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 stabs.c. The red text illustrates the steps that generate the bug. As shown in the diagram, in the function parse_stab, a block of memory is allocated for dhandle->current_file by calling the function debug_set_filename. After calling parse_stab, the memory of dhandle->current_file is not freed.The memory of dhandle->current_file will 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.
This isn't a leak, nor is any other case of allocated memory accessible via pointers.
To be clear, by accessible I mean reachable from a pointer in data (possibly via a chain of pointers).
Created attachment 15259 [details] Memory Leak in stabs.c
(In reply to Alan Modra from comment #2) > To be clear, by accessible I mean reachable from a pointer in data (possibly > via a chain of pointers). I'm sorry, it seems that the previous attachment may not have been uploaded successfully. I have now included the detailed steps of how memory can be accessable via pointer. As shown in the image, first, the function debug_set_filename allocates a block of memory for handle->current_file. Second, when calling debug_set_filename, dhandle is passed as the 1st parameter.Therefore, dhandle->current_file is modified. Third,in the function parse_stab, there are several places where it can return FALSE.If the function parse_stab returns FALSE, the branch in the fuction read_section_stabs_debugging_info will be executed, and read_section_stabs_debugging_info will also return FALSE. dhandle->current_file is not freed in this branch.Forth, if read_section_stabs_debugging_info returns FALSE, the fuction read_debugging_info will return NULL, and the memory of dhandle->current_file will leak. Can you please help to check again? Thanks for your effort.