dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0402-disk-ldm-Fix-memory-leak-on-uninserted-lv-references.patch

80913e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
80913e
From: Darren Kenny <darren.kenny@oracle.com>
80913e
Date: Tue, 8 Dec 2020 10:00:51 +0000
80913e
Subject: [PATCH] disk/ldm: Fix memory leak on uninserted lv references
80913e
80913e
The problem here is that the memory allocated to the variable lv is not
80913e
yet inserted into the list that is being processed at the label fail2.
80913e
80913e
As we can already see at line 342, which correctly frees lv before going
80913e
to fail2, we should also be doing that at these earlier jumps to fail2.
80913e
80913e
Fixes: CID 73824
80913e
80913e
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
80913e
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
80913e
---
80913e
 grub-core/disk/ldm.c | 10 ++++++++--
80913e
 1 file changed, 8 insertions(+), 2 deletions(-)
80913e
80913e
diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c
80913e
index 54713f45a12..e82e9899f96 100644
80913e
--- a/grub-core/disk/ldm.c
80913e
+++ b/grub-core/disk/ldm.c
80913e
@@ -321,7 +321,10 @@ make_vg (grub_disk_t disk,
80913e
 	  lv->visible = 1;
80913e
 	  lv->segments = grub_zalloc (sizeof (*lv->segments));
80913e
 	  if (!lv->segments)
80913e
-	    goto fail2;
80913e
+	    {
80913e
+	      grub_free (lv);
80913e
+	      goto fail2;
80913e
+	    }
80913e
 	  lv->segments->start_extent = 0;
80913e
 	  lv->segments->type = GRUB_DISKFILTER_MIRROR;
80913e
 	  lv->segments->node_count = 0;
80913e
@@ -329,7 +332,10 @@ make_vg (grub_disk_t disk,
80913e
 	  lv->segments->nodes = grub_calloc (lv->segments->node_alloc,
80913e
 					     sizeof (*lv->segments->nodes));
80913e
 	  if (!lv->segments->nodes)
80913e
-	    goto fail2;
80913e
+	    {
80913e
+	      grub_free (lv);
80913e
+	      goto fail2;
80913e
+	    }
80913e
 	  ptr = vblk[i].dynamic;
80913e
 	  if (ptr + *ptr + 1 >= vblk[i].dynamic
80913e
 	      + sizeof (vblk[i].dynamic))