All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] Grow: fix possible memory leak
@ 2022-12-21 12:52 Blazej Kucman
  2022-12-28 14:59 ` Jes Sorensen
  0 siblings, 1 reply; 2+ messages in thread
From: Blazej Kucman @ 2022-12-21 12:52 UTC (permalink / raw)
  To: linux-raid; +Cc: jes, colyli

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.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
---
 Grow.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/Grow.c b/Grow.c
index e362403a..b73ec2ae 100644
--- a/Grow.c
+++ b/Grow.c
@@ -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);
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH V2] Grow: fix possible memory leak
  2022-12-21 12:52 [PATCH V2] Grow: fix possible memory leak Blazej Kucman
@ 2022-12-28 14:59 ` Jes Sorensen
  0 siblings, 0 replies; 2+ messages in thread
From: Jes Sorensen @ 2022-12-28 14:59 UTC (permalink / raw)
  To: Blazej Kucman, linux-raid; +Cc: colyli

On 12/21/22 07:52, Blazej Kucman wrote:
> 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.
> 
> Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
> ---
>  Grow.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

Applied!

Thanks,
Jes



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-28 14:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-21 12:52 [PATCH V2] Grow: fix possible memory leak Blazej Kucman
2022-12-28 14:59 ` Jes Sorensen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.