diff mbox series

Grow: fix possible memory leak.

Message ID 20221220110751.27354-1-blazej.kucman@intel.com (mailing list archive)
State Accepted, archived
Headers show
Series Grow: fix possible memory leak. | expand

Commit Message

Blazej Kucman Dec. 20, 2022, 11:07 a.m. UTC
Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
---
 Grow.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Paul Menzel Dec. 20, 2022, 11:14 a.m. UTC | #1
Dear Blazej,


Thank you for the patch.

Am 20.12.22 um 12:07 schrieb Blazej Kucman:

It’d be great, if you removed the dot/period at the end of the commit 
message.

Also, please elaborate on the memory leak in the commit message. Where 
was `mdi` allocated?

> 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);


Kind regards,

Paul
diff mbox series

Patch

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);