Bug 29255 - A Potential Memory Leak Bug
Summary: A Potential Memory Leak Bug
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.34
: P2 normal
Target Milestone: 2.39
Assignee: Alan Modra
Depends on:
Reported: 2022-06-16 12:17 UTC by yuxuan He
Modified: 2022-06-19 06:38 UTC (History)
0 users

See Also:
Last reconfirmed: 2022-06-17 00:00:00

diagram of memory leak bug (129.44 KB, image/png)
2022-06-16 12:17 UTC, yuxuan He

Note You need to log in before you can comment on or make changes to this bug.
Description yuxuan He 2022-06-16 12:17:56 UTC
Created attachment 14146 [details]
diagram of memory leak bug

Hi, I found a potential memory leak bug in the project source code of binutils, and I have shown the execution sequence of the program that may have generated the bug on a diagram,which is added to the attachment
The red text illustrates the steps that created the bug
the red arrows represent the call relationships
the green text illustrates the file and function where the code snippet is located below the green text.

In short, the key to the bug is the fourth and fifth steps in the diagram. The return value of the function called in the fourth step points to dynamically allocated memory, which should normally be further returned to the function caller, however, when the return value of the mkdir function is not equal to 0, the handling of the case simply returns the null pointer, and the dynamically allocated memory is then leaked, as shown in the diagram demonstrates. A free operation should be performed on tmpname when mkdir fails, to avoid memory leaks.

I look forward to your reply and thank you very much for your patience!
Comment 1 Sourceware Commits 2022-06-17 11:59:32 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:


commit d6e1d48c83b165c129cb0aa78905f7ca80a1f682
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Jun 17 09:13:38 2022 +0930

    PR29255, memory leak in make_tempdir
            PR 29255
            * bucomm.c (make_tempdir, make_tempname): Free template on all
            failure paths.
Comment 2 Alan Modra 2022-06-17 12:19:19 UTC
Fixed for 2.39
Comment 3 yuxuan He 2022-06-17 12:27:41 UTC
(In reply to Alan Modra from comment #2)
> Fixed for 2.39

thank you!
Comment 4 Alan Modra 2022-06-19 06:38:38 UTC