From: Alan Maguire <alan.maguire@oracle.com>
To: Viktor Malik <vmalik@redhat.com>, acme@kernel.org
Cc: dwarves@vger.kernel.org
Subject: Re: [PATCH v2] dwarf_loader: Fix memleaks in creating cus
Date: Tue, 3 Sep 2024 11:07:05 +0100 [thread overview]
Message-ID: <b9a5e324-8a22-4232-91e2-9b0b101b160d@oracle.com> (raw)
In-Reply-To: <20240903062352.763644-1-vmalik@redhat.com>
On 03/09/2024 07:23, 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. The same situation occurs in __cus_load_debug_types.
>
> Fix the leaks.
>
> Signed-off-by: Viktor Malik <vmalik@redhat.com>
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
Tested-by: Alan Maguire <alan.maguire@oracle.com>
Thanks!
> ---
> dwarf_loader.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/dwarf_loader.c b/dwarf_loader.c
> index 04f5637..065ed4d 100644
> --- a/dwarf_loader.c
> +++ b/dwarf_loader.c
> @@ -3247,11 +3247,14 @@ static int __cus__load_debug_types(struct cus *cus, struct conf_load *conf, Dwfl
> build_id_len, filename, conf->use_obstack);
> if (cu == NULL ||
> cu__set_common(cu, conf, mod, elf) != 0) {
> + cu__delete(cu);
> return DWARF_CB_ABORT;
> }
>
> - if (dwarf_cu__init(dcup, cu) != 0)
> + if (dwarf_cu__init(dcup, cu) != 0) {
> + cu__delete(cu);
> return DWARF_CB_ABORT;
> + }
> dcup->cu = cu;
> /* Funny hack. */
> dcup->type_unit = dcup;
> @@ -3378,8 +3381,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);
>
prev parent reply other threads:[~2024-09-03 10:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-03 6:23 [PATCH v2] dwarf_loader: Fix memleaks in creating cus Viktor Malik
2024-09-03 10:07 ` Alan Maguire [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=b9a5e324-8a22-4232-91e2-9b0b101b160d@oracle.com \
--to=alan.maguire@oracle.com \
--cc=acme@kernel.org \
--cc=dwarves@vger.kernel.org \
--cc=vmalik@redhat.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