diff mbox series

[4/5,v2] find_disk_attached_hba: fix memleak

Message ID c9b240d7-cf0d-8a98-d1b5-9f4ae203526c@huawei.com (mailing list archive)
State Superseded, archived
Headers show
Series mdadm: fix memory leak and double free | expand

Commit Message

Wu Guanghao Aug. 2, 2022, 2:16 a.m. UTC
If disk_path = diskfd_to_devpath(), we need free(disk_path) before
return, otherwise there will be a memory leak

Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Reviewed-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
---
 super-intel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--
2.27.0

Comments

Coly Li Sept. 3, 2022, 8:37 a.m. UTC | #1
> 2022年8月2日 10:16,Wu Guanghao <wuguanghao3@huawei.com> 写道:
> 
> If disk_path = diskfd_to_devpath(), we need free(disk_path) before
> return, otherwise there will be a memory leak
> 
> Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
> Reviewed-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>

Acked-by: Coly Li <colyli@suse.de>

Thanks.

Coly Li

> ---
> super-intel.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/super-intel.c b/super-intel.c
> index ddbdd3e1..2a4019e7 100644
> --- a/super-intel.c
> +++ b/super-intel.c
> @@ -713,12 +713,12 @@ static struct sys_dev* find_disk_attached_hba(int fd, const char *devname)
> 
>        for (elem = list; elem; elem = elem->next)
>                if (path_attached_to_hba(disk_path, elem->path))
> -                       return elem;
> +                       break;
> 
>        if (disk_path != devname)
>                free(disk_path);
> 
> -       return NULL;
> +       return elem;
> }
> 
> static int find_intel_hba_capability(int fd, struct intel_super *super,
> --
> 2.27.0
diff mbox series

Patch

diff --git a/super-intel.c b/super-intel.c
index ddbdd3e1..2a4019e7 100644
--- a/super-intel.c
+++ b/super-intel.c
@@ -713,12 +713,12 @@  static struct sys_dev* find_disk_attached_hba(int fd, const char *devname)

        for (elem = list; elem; elem = elem->next)
                if (path_attached_to_hba(disk_path, elem->path))
-                       return elem;
+                       break;

        if (disk_path != devname)
                free(disk_path);

-       return NULL;
+       return elem;
 }

 static int find_intel_hba_capability(int fd, struct intel_super *super,