From: Viktor Malik <vmalik@redhat.com>
To: Alan Maguire <alan.maguire@oracle.com>, acme@kernel.org
Cc: dwarves@vger.kernel.org
Subject: Re: [PATCH dwarves] dwarf_loader: Fix memleak in dwarf_cus__create_cu
Date: Mon, 2 Sep 2024 15:23:33 +0200 [thread overview]
Message-ID: <e17da8c8-e15e-4749-bc7e-625ec1c00376@redhat.com> (raw)
In-Reply-To: <3e5c79bf-6c6f-435d-9dd2-5a3fa5fb7334@oracle.com>
On 9/2/24 15:16, Alan Maguire wrote:
> On 02/09/2024 12:11, Viktor Malik wrote:
>> 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);
>>
>
> Good catch! Looks like there's another few instances of cu leaks like
> this later on in __cus__load_debug_types():
>
>
> if (*cup == NULL) {
> struct cu *cu;
>
> cu = cu__new("", pointer_size, build_id,
> build_id_len, filename,
> conf->use_obstack);
> if (cu == NULL ||
> cu__set_common(cu, conf, mod, elf) != 0) {
> need cu__delete() here ->
> return DWARF_CB_ABORT;
> }
>
> if (dwarf_cu__init(dcup, cu) != 0)
> need cu__delete() here ->
> return DWARF_CB_ABORT;
>
>
> Could you respin to fix them too? Thanks!
>
Sure, I'll check those and send v2 tomorrow.
Viktor
prev parent reply other threads:[~2024-09-02 13:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-02 11:11 [PATCH dwarves] dwarf_loader: Fix memleak in dwarf_cus__create_cu Viktor Malik
2024-09-02 13:16 ` Alan Maguire
2024-09-02 13:23 ` Viktor Malik [this message]
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=e17da8c8-e15e-4749-bc7e-625ec1c00376@redhat.com \
--to=vmalik@redhat.com \
--cc=acme@kernel.org \
--cc=alan.maguire@oracle.com \
--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