Skip to contentSkip to conversation

Grow: fix possible memory leak

PATCH Applied Blazej Kucman 2 participants 2 messages Dec 21, 2022 – Dec 28, 2022 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Grow: fix possible memory leak

In function Grow_addbitmap, struct mdinfo may be allocated but is not freed
in few exit paths. Add free 'mdi' variable in missing exit paths to avoid possible memory leak.

---
 Grow.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Grow.c +4 -1
index e362403a..b73ec2ae 100644
@@ -432,6 +432,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
 			if (((disk.state & (1 << MD_DISK_WRITEMOSTLY)) == 0) &&
 			   (strcmp(s->bitmap_file, "clustered") == 0)) {
 				pr_err("%s disks marked write-mostly are not supported with clustered bitmap\n",devname);
+				free(mdi);
 				return 1;
 			}
 			fd2 = dev_open(dv, O_RDWR);
@@ -453,8 +454,10 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
 				pr_err("failed to load super-block.\n");
 			}
 			close(fd2);
-			if (rv)
+			if (rv) {
+				free(mdi);
 				return 1;
+			}
 		}
 		if (offset_setable) {
 			st->ss->getinfo_super(st, mdi, NULL);
Signature · 1 line
2.35.3
Applied
#1 lore raw
Quoted 9 lines · Blazej Kucman

In function Grow_addbitmap, struct mdinfo may be allocated but is not freed
in few exit paths. Add free 'mdi' variable in missing exit paths to avoid possible memory leak.

---
 Grow.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Applied!

Thanks,
Jes