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!
The master branch has been updated by Alan Modra <email@example.com>:
Author: Alan Modra <firstname.lastname@example.org>
Date: Fri Jun 17 09:13:38 2022 +0930
PR29255, memory leak in make_tempdir
* bucomm.c (make_tempdir, make_tempname): Free template on all
Fixed for 2.39
(In reply to Alan Modra from comment #2)
> Fixed for 2.39