Message ID | b54a5d8f-f6f4-af57-b54a-74e56f43dbb1@huawei.com (mailing list archive) |
---|---|
State | Superseded, archived |
Delegated to: | Jes Sorensen |
Headers | show |
Series | mdadm: fix memory leak and double free | expand |
On Thu, 9 Jun 2022 11:08:39 +0800 Wu Guanghao <wuguanghao3@huawei.com> wrote: > If disk_path = diskfd_to_devpath(), we need free(disk_path) before > return, otherwise there will be a memory leak > > Reported-by: Coverity > Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com> > --- > super-intel.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/super-intel.c b/super-intel.c > index ee9e112e..e94f3f65 100644 > --- a/super-intel.c > +++ b/super-intel.c > @@ -701,12 +701,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 Reviewed-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
diff --git a/super-intel.c b/super-intel.c index ee9e112e..e94f3f65 100644 --- a/super-intel.c +++ b/super-intel.c @@ -701,12 +701,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,
If disk_path = diskfd_to_devpath(), we need free(disk_path) before return, otherwise there will be a memory leak Reported-by: Coverity Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com> --- super-intel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.27.0