From: Viktor Malik <vmalik@redhat.com>
To: acme@kernel.org
Cc: dwarves@vger.kernel.org, Viktor Malik <vmalik@redhat.com>
Subject: [PATCH dwarves] dwarf_loader: Fix memleak in dwarf_cus__create_cu
Date: Mon, 2 Sep 2024 13:11:57 +0200 [thread overview]
Message-ID: <20240902111157.748247-1-vmalik@redhat.com> (raw)
Coverity reports a possible memleak in `dwarf_cus__create_cu` due to
`cu` not being freed for the case when it was allocated but
`cu__set_common` failed. Fix the leak.
Signed-off-by: Viktor Malik <vmalik@redhat.com>
---
dwarf_loader.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/dwarf_loader.c b/dwarf_loader.c
index 04f5637..ad36e3c 100644
--- a/dwarf_loader.c
+++ b/dwarf_loader.c
@@ -3378,8 +3378,10 @@ static struct dwarf_cu *dwarf_cus__create_cu(struct dwarf_cus *dcus, Dwarf_Die *
*/
const char *name = attr_string(cu_die, DW_AT_name, dcus->conf);
struct cu *cu = cu__new(name ?: "", pointer_size, dcus->build_id, dcus->build_id_len, dcus->filename, dcus->conf->use_obstack);
- if (cu == NULL || cu__set_common(cu, dcus->conf, dcus->mod, dcus->elf) != 0)
+ if (cu == NULL || cu__set_common(cu, dcus->conf, dcus->mod, dcus->elf) != 0) {
+ cu__delete(cu);
return NULL;
+ }
struct dwarf_cu *dcu = dwarf_cu__new(cu);
--
2.46.0
next reply other threads:[~2024-09-02 11:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-02 11:11 Viktor Malik [this message]
2024-09-02 13:16 ` [PATCH dwarves] dwarf_loader: Fix memleak in dwarf_cus__create_cu Alan Maguire
2024-09-02 13:23 ` Viktor Malik
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=20240902111157.748247-1-vmalik@redhat.com \
--to=vmalik@redhat.com \
--cc=acme@kernel.org \
--cc=dwarves@vger.kernel.org \
/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