diff mbox series

[ndctl,2/8] lib/libndctl: fix memory leakage problem in add_bus

Message ID 8caac123-9d45-c848-d45a-3cb8be5a2708@huawei.com (mailing list archive)
State New, archived
Headers show
Series fix serverl issues reported by Coverity | expand

Commit Message

Zhiqiang Liu Nov. 6, 2020, 9:25 a.m. UTC
In add_bus(), bus->bus_path is set by calling parent_dev_path(),
which will finally adopt realpath(, NULL) to allocate new path.
However, bus->bus_path will not be freed in err_read tag, then,
memory leakage occurs.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
---
 ndctl/lib/libndctl.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Jeff Moyer Nov. 20, 2020, 4:31 p.m. UTC | #1
Zhiqiang Liu <liuzhiqiang26@huawei.com> writes:

> In add_bus(), bus->bus_path is set by calling parent_dev_path(),
> which will finally adopt realpath(, NULL) to allocate new path.
> However, bus->bus_path will not be freed in err_read tag, then,
> memory leakage occurs.
>
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> ---
>  ndctl/lib/libndctl.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
> index ad521d3..3926382 100644
> --- a/ndctl/lib/libndctl.c
> +++ b/ndctl/lib/libndctl.c
> @@ -975,6 +975,7 @@ static void *add_bus(void *parent, int id, const char *ctl_base)
>  	free(bus->wait_probe_path);
>  	free(bus->scrub_path);
>  	free(bus->provider);
> +	free(bus->bus_path);
>  	free(bus->bus_buf);
>  	free(bus);
>   err_bus:

Acked-by: Jeff Moyer <jmoyer@redhat.com>
diff mbox series

Patch

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index ad521d3..3926382 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -975,6 +975,7 @@  static void *add_bus(void *parent, int id, const char *ctl_base)
 	free(bus->wait_probe_path);
 	free(bus->scrub_path);
 	free(bus->provider);
+	free(bus->bus_path);
 	free(bus->bus_buf);
 	free(bus);
  err_bus: