From 4fc543f0c31acb29d9b2f951e79f4c997536b2c5 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Fri, 9 Apr 2021 18:44:23 +0900 Subject: libkmod-config: fix a memory leak when kmod_list_append() fails 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: cherry-pick mainline commit 39dd17162374] Change-Id: Ic1d1e77ecc9b81fdd4f0eb771cce1d7b42d0024e --- 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 971f20b..90e3e94 100644 --- a/libkmod/libkmod-config.c +++ b/libkmod/libkmod-config.c @@ -854,8 +854,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; } -- cgit v1.2.3