[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1626180159-112996-3-git-send-email-chengshuyi@linux.alibaba.com>
Date: Tue, 13 Jul 2021 20:42:38 +0800
From: Shuyi Cheng <chengshuyi@...ux.alibaba.com>
To: ast@...nel.org, daniel@...earbox.net, andrii@...nel.org,
kafai@...com, songliubraving@...com, yhs@...com,
john.fastabend@...il.com, kpsingh@...nel.org
Cc: netdev@...r.kernel.org, bpf@...r.kernel.org,
linux-kernel@...r.kernel.org, kernel-janitors@...r.kernel.org,
Shuyi Cheng <chengshuyi@...ux.alibaba.com>,
Dan Carpenter <dan.carpenter@...cle.com>
Subject: [PATCH bpf-next v4 2/3] libbpf: Fix the possible memory leak on error
If the strdup() fails then we need to call bpf_object__close(obj) to
avoid a resource leak.
Fixes: 166750b ("libbpf: Support libbpf-provided extern variables")
Cc: Dan Carpenter <dan.carpenter@...cle.com>
Signed-off-by: Shuyi Cheng <chengshuyi@...ux.alibaba.com>
---
tools/lib/bpf/libbpf.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 6e11a7b..9d80794 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -7611,8 +7611,10 @@ int bpf_program__load(struct bpf_program *prog, char *license, __u32 kern_ver)
kconfig = OPTS_GET(opts, kconfig, NULL);
if (kconfig) {
obj->kconfig = strdup(kconfig);
- if (!obj->kconfig)
- return ERR_PTR(-ENOMEM);
+ if (!obj->kconfig) {
+ err = -ENOMEM;
+ goto out;
+ }
}
err = bpf_object__elf_init(obj);
--
1.8.3.1
Powered by blists - more mailing lists