public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org
Subject: [PATCH] Fix low-mem memory leak
Date: Tue, 23 Mar 2021 14:19:03 +0100	[thread overview]
Message-ID: <20210323131902.GA17162@delia> (raw)

Hi,

When building dwz with -fsanitize=address, and running dwz in low-mem mode, we
run into a number of memory leaks:
...
$ dwz hello -o hello.z -l0

=================================================================
==22607==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 432 byte(s) in 6 object(s) allocated from:
    #0 0x7f560af846d8 in __interceptor_calloc (/usr/lib64/libasan.so.4+0xdc6d8)
    #1 0x475db1 in htab_try_create hashtab.c:164
    #2 0x406ed6 in read_abbrev dwz.c:1296
    #3 0x42bca9 in read_debug_info dwz.c:6818
    #4 0x4608cb in read_dwarf dwz.c:13706
    #5 0x46ef9a in dwz dwz.c:15383
    #6 0x474a27 in dwz_one_file dwz.c:16279
    #7 0x475951 in main dwz.c:16450
    #8 0x7f560a8f9349 in __libc_start_main (/lib64/libc.so.6+0x24349)

Direct leak of 72 byte(s) in 1 object(s) allocated from:
    #0 0x7f560af846d8 in __interceptor_calloc (/usr/lib64/libasan.so.4+0xdc6d8)
    #1 0x475db1 in htab_try_create hashtab.c:164
    #2 0x42a8fd in read_debug_info dwz.c:6634
    #3 0x4608cb in read_dwarf dwz.c:13706
    #4 0x46ef9a in dwz dwz.c:15383
    #5 0x474a27 in dwz_one_file dwz.c:16279
    #6 0x475951 in main dwz.c:16450
    #7 0x7f560a8f9349 in __libc_start_main (/lib64/libc.so.6+0x24349)

Indirect leak of 4072 byte(s) in 1 object(s) allocated from:
    #0 0x7f560af846d8 in __interceptor_calloc (/usr/lib64/libasan.so.4+0xdc6d8)
    #1 0x475dd7 in htab_try_create hashtab.c:168
    #2 0x42a8fd in read_debug_info dwz.c:6634
    #3 0x4608cb in read_dwarf dwz.c:13706
    #4 0x46ef9a in dwz dwz.c:15383
    #5 0x474a27 in dwz_one_file dwz.c:16279
    #6 0x475951 in main dwz.c:16450
    #7 0x7f560a8f9349 in __libc_start_main (/lib64/libc.so.6+0x24349)

Indirect leak of 2928 byte(s) in 6 object(s) allocated from:
    #0 0x7f560af846d8 in __interceptor_calloc (/usr/lib64/libasan.so.4+0xdc6d8)
    #1 0x475dd7 in htab_try_create hashtab.c:168
    #2 0x406ed6 in read_abbrev dwz.c:1296
    #3 0x42bca9 in read_debug_info dwz.c:6818
    #4 0x4608cb in read_dwarf dwz.c:13706
    #5 0x46ef9a in dwz dwz.c:15383
    #6 0x474a27 in dwz_one_file dwz.c:16279
    #7 0x475951 in main dwz.c:16450
    #8 0x7f560a8f9349 in __libc_start_main (/lib64/libc.so.6+0x24349)

SUMMARY: AddressSanitizer: 7504 byte(s) leaked in 14 allocation(s).
...

The leaks are related to the meta_abbrev_htab, which is allocated in
the initial read_debug_info call for .debug_info, and then allocated once more
in a second call to read_debug_info for .debug_types.

The second allocation overwrites the first one, and consequently the first one
is leaked.

Fix this by only allocating meta_abbrev_htab if not already allocated.

Any comments?

Thanks,
- Tom

Fix low-mem memory leak

2021-03-23  Tom de Vries  <tdevries@suse.de>

	PR dwz/27633
	* dwz.c (read_debug_info): Don't allocate meta_abbrev_htab if already
	allocated.

---
 dwz.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/dwz.c b/dwz.c
index 4fc01a3..4707aa9 100644
--- a/dwz.c
+++ b/dwz.c
@@ -6628,7 +6628,8 @@ read_debug_info (DSO *dso, int kind, unsigned int *die_count)
       if (dup_htab == NULL)
 	dwz_oom ();
     }
-  if (unlikely (op_multifile || rd_multifile || fi_multifile || low_mem))
+  if (unlikely (meta_abbrev_htab == NULL
+		&& (op_multifile || rd_multifile || fi_multifile || low_mem)))
     {
       meta_abbrev_htab
 	= htab_try_create (500, meta_abbrev_hash, meta_abbrev_eq,

                 reply	other threads:[~2021-03-23 13:19 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=20210323131902.GA17162@delia \
    --to=tdevries@suse.de \
    --cc=dwz@sourceware.org \
    --cc=jakub@redhat.com \
    --cc=mark@klomp.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).