public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
From: H.J. Lu <hjl@sourceware.org>
To: binutils-cvs@sourceware.org
Subject: [binutils-gdb] mmap: Fix a memory leak in _bfd_mmap_read_temporary
Date: Thu, 11 Apr 2024 02:52:05 +0000 (GMT)	[thread overview]
Message-ID: <20240411025205.E0AA7384AB40@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=533da9536e6e4d65f0623ede93365f7229779f54

commit 533da9536e6e4d65f0623ede93365f7229779f54
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Apr 9 16:02:48 2024 -0700

    mmap: Fix a memory leak in _bfd_mmap_read_temporary
    
    Return malloced memory in *mmap_base so that _bfd_munmap_readonly_temporary
    will free it.
    
            * libbfd.c (_bfd_mmap_read_temporary): Return malloced memory
            in *mmap_base.

Diff:
---
 bfd/libbfd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/bfd/libbfd.c b/bfd/libbfd.c
index e92ed5e18a2..2f5ddcaf3b8 100644
--- a/bfd/libbfd.c
+++ b/bfd/libbfd.c
@@ -1223,8 +1223,12 @@ _bfd_mmap_read_temporary (void **data_p, size_t *size_p,
       if (data == NULL)
 	return false;
       *data_p = data;
+      /* NB: _bfd_munmap_readonly_temporary will free *MMAP_BASE if
+	 *SIZE_P == 0.  */
+      *mmap_base = data;
     }
-  *mmap_base = NULL;
+  else
+    *mmap_base = NULL;
   *size_p = 0;
   return bfd_read (data, size, abfd) == size;
 }

                 reply	other threads:[~2024-04-11  2:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240411025205.E0AA7384AB40@sourceware.org \
    --to=hjl@sourceware.org \
    --cc=binutils-cvs@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).