Bug 31162 - Memory Leak in ldwrite.c
Summary: Memory Leak in ldwrite.c
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.32
: P2 normal
Target Milestone: 2.42
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-12-13 11:31 UTC by 时宇羽然
Modified: 2023-12-18 12:22 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed: 2023-12-15 00:00:00


Attachments
Memory Leak in ldwrite.c (366.99 KB, image/png)
2023-12-13 11:31 UTC, 时宇羽然
Details

Note You need to log in before you can comment on or make changes to this bug.
Description 时宇羽然 2023-12-13 11:31:07 UTC
Created attachment 15257 [details]
Memory Leak in ldwrite.c

Hi, I found a memory leak bug in the source code of binutils, and I have shown 
the execution sequence below. This bug exists in the file ldwrite.c. The red text illustrates the steps that generate the bug.

As shown in the diagram, in the function build_link_order, the variables link_order->u.data.contents and link_order->u.reloc.p are allocated memory. However, they are not freed, which will lead to a memory leak.

Although reported bug trace is for version 2.32 but i've check this bug still existing in latest version.

Can you help to check if this bug is true? Thanks for your effort.
Comment 1 Sourceware Commits 2023-12-18 12:16:12 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

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

commit 4cc1f41cfa45b0d36427e79409f447e83f4e66d4
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Dec 15 20:19:46 2023 +1030

    PR31162, Memory Leak in ldwrite.c
    
    This isn't a particularly worrying memory leak, but fix it anyway.
    
            PR 31162
            * ldwrite.c (build_link_order): Use bfd_alloc rather than xmalloc.
            Add %E to error messages.
Comment 2 Alan Modra 2023-12-18 12:22:33 UTC
Fixed for 2.42