Bug 31159 - Memory Leak in bucomm.c
Summary: Memory Leak in bucomm.c
Status: RESOLVED NOTABUG
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.32
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-12-13 07:02 UTC by 时宇羽然
Modified: 2023-12-13 21:18 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Memory Leak in bucomm.c (286.02 KB, image/png)
2023-12-13 07:02 UTC, 时宇羽然
Details

Note You need to log in before you can comment on or make changes to this bug.
Description 时宇羽然 2023-12-13 07:02:39 UTC
Created attachment 15256 [details]
Memory Leak in bucomm.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 bucomm.c. The red text illustrates the steps that generate the bug.

As shown in the diagram, The variable filename receives the return value from the function bfd_get_archive_filename, which allocates a block of memory for it. However, this allocated memory is not freed, resulting in 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 Alan Modra 2023-12-13 21:18:24 UTC
bfd_get_archive_filename doesn't leak memory and its return value should not be freed.  It is perfectly fine for the static buffer managed by bfd_get_archive_filename to point to some allocated memory at the end of main().  Any such memory will be freed on process exit.