bugmake - Bugs: bug #62615, Fix the leaks of file->cmds and...

 
 

bug #62615: Fix the leaks of file->cmds and file->cmds->commands

Submitter:  Dmitry Goncharov <dgoncharov>
Submitted:  Sat 11 Jun 2022 01:52:52 PM UTC
   
 
Severity:  3 - Normal Item Group:  Bug
Status:  None Privacy:  Public
Assigned to:  None Open/Closed:  Open
Component Version:  4.4 Operating System:  Any
Fixed Release:  None Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 16 Jun 2022 01:55:00 AM UTC, comment #1: 

Paul, can you please ignore this patch?
This bug report is correct, there is a memory leak.
But the patch is not correct. The patch fails to take into account a case when multiple targets are defined on the same rule. Correctly taking care of freeing commands in cases like


bye.o hello.o: hello.h; $(info 1 $@ from $^)
hello.o: hello.c; $(info 2 $@ from $^)


requires additional bookkeeping, like reference counters or similar. This patch does not do any of that.

Dmitry Goncharov <dgoncharov>
Sat 11 Jun 2022 01:52:52 PM UTC, original submission:  

Makefile like the following causes make to leak
file->cmds along with file->cmds->commands allocated for the 1st hello.o rule.


all: hello.o
hello.o: hello.h; $(info 1 $@ from $^)
hello.o: hello.c; $(info 2 $@ from $^)


To see the leak build with -fsanitize=leak


$ make
makefile2:5: warning: overriding recipe for target 'hello.o'
makefile2:4: warning: ignoring old recipe for target 'hello.o'
2 hello.o from hello.c hello.h
make: Nothing to be done for 'all'.

=================================================================
==13813==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7fb54a09bc9c in __interceptor_malloc /var/tmp/portage/sys-devel/gcc-10.2.0-r5/work/gcc-10.2.0/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x558a7a3aae35 in xmalloc ../src/misc.c:190
    #2 0x558a7a3c1923 in record_files ../src/read.c:2011
    #3 0x558a7a3b6f0d in eval ../src/read.c:1009
    #4 0x558a7a3b2a3c in eval_makefile ../src/read.c:438
    #5 0x558a7a3b0a38 in read_all_makefiles ../src/read.c:223
    #6 0x558a7a397ff7 in main ../src/main.c:1971
    #7 0x7fb54953bc4e in __libc_start_main (/lib64/libc.so.6+0x23c4e)

Indirect leak of 23 byte(s) in 1 object(s) allocated from:
    #0 0x7fb54a09bc9c in __interceptor_malloc /var/tmp/portage/sys-devel/gcc-10.2.0-r5/work/gcc-10.2.0/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x7fb54a04660d in __interceptor_strndup /var/tmp/portage/sys-devel/gcc-10.2.0-r5/work/gcc-10.2.0/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:395
    #2 0x558a7a3aaf88 in xstrndup ../src/misc.c:252
    #3 0x558a7a3c1b07 in record_files ../src/read.c:2015
    #4 0x558a7a3b6f0d in eval ../src/read.c:1009
    #5 0x558a7a3b2a3c in eval_makefile ../src/read.c:438
    #6 0x558a7a3b0a38 in read_all_makefiles ../src/read.c:223
    #7 0x558a7a397ff7 in main ../src/main.c:1971
    #8 0x7fb54953bc4e in __libc_start_main (/lib64/libc.so.6+0x23c4e)

SUMMARY: AddressSanitizer: 79 byte(s) leaked in 2 allocation(s).


Dmitry Goncharov <dgoncharov>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #53294:  sv62615_fix.diff added by dgoncharov (1KiB - text/x-patch)
file #53295:  sv62615_test.diff added by dgoncharov (1KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dgoncharov (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-06-11 dgoncharov Attached File- Added sv62615_fix.diff, #53294
        Attached File- Added sv62615_test.diff, #53295

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code