mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Weigang He <geoffreyhe2@gmail.com>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] objtool: Fix memory leak in elf_alloc_reloc() on realloc failure
Date: Mon, 19 Jan 2026 13:38:09 +0100	[thread overview]
Message-ID: <20260119123809.GS830755@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260118065643.924837-1-geoffreyhe2@gmail.com>

On Sun, Jan 18, 2026 at 06:56:43AM +0000, Weigang He wrote:
> When realloc() fails in elf_alloc_reloc(), the original buffer pointer
> is overwritten with NULL before the failure is detected. This causes
> the original buffer to become unreachable, resulting in a memory leak.
> 
> Fix this by using a temporary variable to hold the realloc() result.
> If realloc() fails, free the original buffer and set d_buf to NULL to
> maintain the expected error state before returning -1.
> 
> This bug is found by my static analysis tool and my code review.

Yeah, except that the moment this error is actually hit, the tool will
exit, freeing all memory.

      parent reply	other threads:[~2026-01-19 12:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-18  6:56 Weigang He
2026-01-19 12:08 ` Markus Elfring
2026-01-19 12:38 ` Peter Zijlstra [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=20260119123809.GS830755@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=geoffreyhe2@gmail.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@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

Powered by JetHome