bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shuyi Cheng <chengshuyi@linux.alibaba.com>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	kafai@fb.com, songliubraving@fb.com, yhs@fb.com,
	john.fastabend@gmail.com, kpsingh@kernel.org
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	Shuyi Cheng <chengshuyi@linux.alibaba.com>,
	Dan Carpenter <dan.carpenter@oracle.com>
Subject: [PATCH bpf-next v4 2/3] libbpf: Fix the possible memory leak on error
Date: Tue, 13 Jul 2021 20:42:38 +0800	[thread overview]
Message-ID: <1626180159-112996-3-git-send-email-chengshuyi@linux.alibaba.com> (raw)
In-Reply-To: <1626180159-112996-1-git-send-email-chengshuyi@linux.alibaba.com>

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@oracle.com>
Signed-off-by: Shuyi Cheng <chengshuyi@linux.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


  parent reply	other threads:[~2021-07-13 12:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-13 12:42 [PATCH bpf-next v4 0/3] Add btf_custom_path in bpf_obj_open_opts Shuyi Cheng
2021-07-13 12:42 ` [PATCH bpf-next v4 1/3] libbpf: Introduce 'btf_custom_path' to 'bpf_obj_open_opts' Shuyi Cheng
2021-07-16  4:51   ` Andrii Nakryiko
2021-07-17  1:15     ` Shuyi Cheng
2021-07-13 12:42 ` Shuyi Cheng [this message]
2021-07-13 12:42 ` [PATCH bpf-next v4 3/3] selftests/bpf: Switches existing selftests to using open_opts for custom BTF Shuyi Cheng
2021-07-16  4:53   ` Andrii Nakryiko
2021-07-16 20:27   ` Andrii Nakryiko
2021-07-17  1:39     ` Shuyi Cheng
2021-07-16  4:49 ` [PATCH bpf-next v4 0/3] Add btf_custom_path in bpf_obj_open_opts Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1626180159-112996-3-git-send-email-chengshuyi@linux.alibaba.com \
    --to=chengshuyi@linux.alibaba.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=dan.carpenter@oracle.com \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).