diff mbox series

libkmod-config: fix a memory leak when kmod_list_append() fails

Message ID 20210409094423.966-1-sw0312.kim@samsung.com (mailing list archive)
State New, archived
Headers show
Series libkmod-config: fix a memory leak when kmod_list_append() fails | expand

Commit Message

Seung-Woo Kim April 9, 2021, 9:44 a.m. UTC
From kmod_config_new(), when kmod_list_append() fails,
fix not list-appended kmod_config_path leak.

Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
---
 libkmod/libkmod-config.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Lucas De Marchi April 9, 2021, 3:13 p.m. UTC | #1
On Fri, Apr 9, 2021 at 2:41 AM Seung-Woo Kim <sw0312.kim@samsung.com> wrote:
>
> From kmod_config_new(), when kmod_list_append() fails,
> fix not list-appended kmod_config_path leak.
>
> Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>

Applied, thanks
Lucas De Marchi

> ---
>  libkmod/libkmod-config.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c
> index 4fdd40f86dea..e83621b34157 100644
> --- a/libkmod/libkmod-config.c
> +++ b/libkmod/libkmod-config.c
> @@ -909,8 +909,10 @@ int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **p_config,
>                 memcpy(cf->path, path, pathlen);
>
>                 tmp = kmod_list_append(path_list, cf);
> -               if (tmp == NULL)
> +               if (tmp == NULL) {
> +                       free(cf);
>                         goto oom;
> +               }
>                 path_list = tmp;
>         }
>
> --
> 2.19.2
>
diff mbox series

Patch

diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c
index 4fdd40f86dea..e83621b34157 100644
--- a/libkmod/libkmod-config.c
+++ b/libkmod/libkmod-config.c
@@ -909,8 +909,10 @@  int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **p_config,
 		memcpy(cf->path, path, pathlen);
 
 		tmp = kmod_list_append(path_list, cf);
-		if (tmp == NULL)
+		if (tmp == NULL) {
+			free(cf);
 			goto oom;
+		}
 		path_list = tmp;
 	}