xref: /OK3568_Linux_fs/buildroot/boot/grub2/0086-loader-xnu-Fix-memory-leak.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1From bcb59ece3263d118510c4440c4da0950f224bb7f Mon Sep 17 00:00:00 2001
2From: Darren Kenny <darren.kenny@oracle.com>
3Date: Thu, 26 Nov 2020 12:53:10 +0000
4Subject: [PATCH] loader/xnu: Fix memory leak
5
6The code here is finished with the memory stored in name, but it only
7frees it if there curvalue is valid, while it could actually free it
8regardless.
9
10The fix is a simple relocation of the grub_free() to before the test
11of curvalue.
12
13Fixes: CID 96646
14
15Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
16Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
17Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
18---
19 grub-core/loader/xnu.c | 2 +-
20 1 file changed, 1 insertion(+), 1 deletion(-)
21
22diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c
23index 44fd5a9..eb14462 100644
24--- a/grub-core/loader/xnu.c
25+++ b/grub-core/loader/xnu.c
26@@ -1391,9 +1391,9 @@ grub_xnu_fill_devicetree (void)
27     name[len] = 0;
28
29     curvalue = grub_xnu_create_value (curkey, name);
30+    grub_free (name);
31     if (!curvalue)
32       return grub_errno;
33-    grub_free (name);
34
35     data = grub_malloc (grub_strlen (var->value) + 1);
36     if (!data)
37--
382.14.2
39
40