Bug 26388 - objdump debug dump memory leaks
Summary: objdump debug dump memory leaks
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.35
: P2 normal
Target Milestone: 2.36
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-14 08:54 UTC by 15664243668
Modified: 2020-08-14 12:09 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed: 2020-08-14 00:00:00


Attachments
PoC (13.60 KB, application/octet-stream)
2020-08-14 08:54 UTC, 15664243668
Details

Note You need to log in before you can comment on or make changes to this bug.
Description 15664243668 2020-08-14 08:54:52 UTC
Created attachment 12771 [details]
PoC

I have found a memory leak in xmalloc and xrealloc of Binutils-2.35. This bug is triggered as
$./objdump –dwarf-check -C -g -f -dwarf -x PoC
I compile the binutils-2.35 to the 64-bit LSB version with AddressSanitizer in Ubuntu 16.04 and print the debug information.
...

=================================================================
==4710==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 8192 byte(s) in 1 object(s) allocated from:
    #0 0x7f665e4de602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0xb36457 in xrealloc ../../libiberty/xmalloc.c:177

Direct leak of 96 byte(s) in 1 object(s) allocated from:
    #0 0x7f665e4de602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0xb362dc in xmalloc ../../libiberty/xmalloc.c:147

SUMMARY: AddressSanitizer: 8288 byte(s) leaked in 2 allocation(s).
Comment 1 cvs-commit@gcc.gnu.org 2020-08-14 12:06:04 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

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

commit 82fcdb39388c6690699d41b7022b054c2de2554c
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Aug 14 20:19:39 2020 +0930

    PR26388, objdump debug dump memory leaks
    
    num_debug_info_entries is used not just as a count but also as a flag
    (DEBUG_INFO_UNAVAILABLE) after some errors.  That means
    num_debug_info_entries can't be used when cleaning up malloc'd info.
    
            PR 26388
            * dwarf.c (free_debug_memory): Free alloc_num_debug_info_entries
            of debug_information.  Correct test of max_loc_offsets and
            max_range_lists.
            * rddbg.c (read_debugging_info): Free dhandle on error.
Comment 2 Alan Modra 2020-08-14 12:09:39 UTC
Fixed.