loader/xnu: Fix memory leak

The code here is finished with the memory stored in name, but it only
frees it if there curvalue is valid, while it could actually free it
regardless.

The fix is a simple relocation of the grub_free() to before the test
of curvalue.

Fixes: CID 96646

Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Darren Kenny 2020-11-26 12:53:10 +00:00 committed by Daniel Kiper
parent 5d5391b0a0
commit bcb59ece32

View File

@ -1391,9 +1391,9 @@ grub_xnu_fill_devicetree (void)
name[len] = 0; name[len] = 0;
curvalue = grub_xnu_create_value (curkey, name); curvalue = grub_xnu_create_value (curkey, name);
grub_free (name);
if (!curvalue) if (!curvalue)
return grub_errno; return grub_errno;
grub_free (name);
data = grub_malloc (grub_strlen (var->value) + 1); data = grub_malloc (grub_strlen (var->value) + 1);
if (!data) if (!data)