bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [bug #50790] Some kind of memory corruption in error messages with g


From: Martin Dorey
Subject: RE: [bug #50790] Some kind of memory corruption in error messages with gcc-6.3.0 -flto=4
Date: Tue, 18 Apr 2017 18:44:02 +0000

==22022==  Address 0x4caf710 is 0 bytes inside a block of size 200 free'd
==22022==    at 0x4A0804B: free (vg_replace_malloc.c:534)
==22022==    by 0x41EC52: read_all_makefiles (read.c:210)

That was helpful, thanks.  Reproduced with:

address@hidden:~/tmp/make-50790$ cat first.make
default:; false
address@hidden:~/tmp/make-50790$ cat Makefile
real: default
address@hidden:~/tmp/make-50790$ MAKEFILES=first.make valgrind make
==23084== Memcheck, a memory error detector
==23084== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==23084== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==23084== Command: make
==23084== 
false
==23084== Invalid read of size 1
==23084==    at 0x4C2C1A2: strlen (vg_replace_strmem.c:412)
==23084==    by 0x4138B3: child_error (job.c:500)
==23084==    by 0x415B43: reap_children (job.c:869)
==23084==    by 0x415F83: new_job (job.c:1857)
==23084==    by 0x4212FF: remake_file (remake.c:1234)
==23084==    by 0x4212FF: update_file_1 (remake.c:835)
==23084==    by 0x4212FF: update_file (remake.c:336)
==23084==    by 0x4213F2: check_dep (remake.c:1024)
==23084==    by 0x4203FA: update_file_1 (remake.c:572)
==23084==    by 0x4203FA: update_file (remake.c:336)
==23084==    by 0x42191F: update_goal_chain (remake.c:151)
==23084==    by 0x407C96: main (main.c:2555)
==23084==  Address 0x5842100 is 0 bytes inside a block of size 200 free'd
==23084==    at 0x4C29E90: free (vg_replace_malloc.c:473)
==23084==    by 0x41EC2E: read_all_makefiles (read.c:210)
==23084==    by 0x407884: main (main.c:1967)
==23084== 
==23084== Invalid read of size 1
==23084==    at 0x4C2C1B4: strlen (vg_replace_strmem.c:412)
==23084==    by 0x4138B3: child_error (job.c:500)
==23084==    by 0x415B43: reap_children (job.c:869)
==23084==    by 0x415F83: new_job (job.c:1857)
==23084==    by 0x4212FF: remake_file (remake.c:1234)
==23084==    by 0x4212FF: update_file_1 (remake.c:835)
==23084==    by 0x4212FF: update_file (remake.c:336)
==23084==    by 0x4213F2: check_dep (remake.c:1024)
==23084==    by 0x4203FA: update_file_1 (remake.c:572)
==23084==    by 0x4203FA: update_file (remake.c:336)
==23084==    by 0x42191F: update_goal_chain (remake.c:151)
==23084==    by 0x407C96: main (main.c:2555)
==23084==  Address 0x5842101 is 1 bytes inside a block of size 200 free'd
==23084==    at 0x4C29E90: free (vg_replace_malloc.c:473)
==23084==    by 0x41EC2E: read_all_makefiles (read.c:210)
==23084==    by 0x407884: main (main.c:1967)
==23084== 
==23084== Invalid read of size 1
==23084==    at 0x528BDCC: vfprintf (vfprintf.c:1642)
==23084==    by 0x52AD3FA: vsprintf (iovsprintf.c:42)
==23084==    by 0x5291EB6: sprintf (sprintf.c:32)
==23084==    by 0x4138E6: child_error (job.c:501)
==23084==    by 0x415B43: reap_children (job.c:869)
==23084==    by 0x415F83: new_job (job.c:1857)
==23084==    by 0x4212FF: remake_file (remake.c:1234)
==23084==    by 0x4212FF: update_file_1 (remake.c:835)
==23084==    by 0x4212FF: update_file (remake.c:336)
==23084==    by 0x4213F2: check_dep (remake.c:1024)
==23084==    by 0x4203FA: update_file_1 (remake.c:572)
==23084==    by 0x4203FA: update_file (remake.c:336)
==23084==    by 0x42191F: update_goal_chain (remake.c:151)
==23084==    by 0x407C96: main (main.c:2555)
==23084==  Address 0x5842100 is 0 bytes inside a block of size 200 free'd
==23084==    at 0x4C29E90: free (vg_replace_malloc.c:473)
==23084==    by 0x41EC2E: read_all_makefiles (read.c:210)
==23084==    by 0x407884: main (main.c:1967)
==23084== 
==23084== Invalid read of size 1
==23084==    at 0x52B7240: _IO_default_xsputn (genops.c:475)
==23084==    by 0x528BD86: vfprintf (vfprintf.c:1642)
==23084==    by 0x52AD3FA: vsprintf (iovsprintf.c:42)
==23084==    by 0x5291EB6: sprintf (sprintf.c:32)
==23084==    by 0x4138E6: child_error (job.c:501)
==23084==    by 0x415B43: reap_children (job.c:869)
==23084==    by 0x415F83: new_job (job.c:1857)
==23084==    by 0x4212FF: remake_file (remake.c:1234)
==23084==    by 0x4212FF: update_file_1 (remake.c:835)
==23084==    by 0x4212FF: update_file (remake.c:336)
==23084==    by 0x4213F2: check_dep (remake.c:1024)
==23084==    by 0x4203FA: update_file_1 (remake.c:572)
==23084==    by 0x4203FA: update_file (remake.c:336)
==23084==    by 0x42191F: update_goal_chain (remake.c:151)
==23084==    by 0x407C96: main (main.c:2555)
==23084==  Address 0x5842100 is 0 bytes inside a block of size 200 free'd
==23084==    at 0x4C29E90: free (vg_replace_malloc.c:473)
==23084==    by 0x41EC2E: read_all_makefiles (read.c:210)
==23084==    by 0x407884: main (main.c:1967)
==23084== 
==23084== Invalid read of size 1
==23084==    at 0x52B724E: _IO_default_xsputn (genops.c:474)
==23084==    by 0x528BD86: vfprintf (vfprintf.c:1642)
==23084==    by 0x52AD3FA: vsprintf (iovsprintf.c:42)
==23084==    by 0x5291EB6: sprintf (sprintf.c:32)
==23084==    by 0x4138E6: child_error (job.c:501)
==23084==    by 0x415B43: reap_children (job.c:869)
==23084==    by 0x415F83: new_job (job.c:1857)
==23084==    by 0x4212FF: remake_file (remake.c:1234)
==23084==    by 0x4212FF: update_file_1 (remake.c:835)
==23084==    by 0x4212FF: update_file (remake.c:336)
==23084==    by 0x4213F2: check_dep (remake.c:1024)
==23084==    by 0x4203FA: update_file_1 (remake.c:572)
==23084==    by 0x4203FA: update_file (remake.c:336)
==23084==    by 0x42191F: update_goal_chain (remake.c:151)
==23084==    by 0x407C96: main (main.c:2555)
==23084==  Address 0x5842102 is 2 bytes inside a block of size 200 free'd
==23084==    at 0x4C29E90: free (vg_replace_malloc.c:473)
==23084==    by 0x41EC2E: read_all_makefiles (read.c:210)
==23084==    by 0x407884: main (main.c:1967)
==23084== 
make: *** [first.make:1: default] Error 1
==23084== 
==23084== HEAP SUMMARY:
==23084==     in use at exit: 156,321 bytes in 1,750 blocks
==23084==   total heap usage: 2,759 allocs, 1,009 frees, 390,456 bytes allocated
==23084== 
==23084== LEAK SUMMARY:
==23084==    definitely lost: 0 bytes in 0 blocks
==23084==    indirectly lost: 0 bytes in 0 blocks
==23084==      possibly lost: 0 bytes in 0 blocks
==23084==    still reachable: 156,321 bytes in 1,750 blocks
==23084==         suppressed: 0 bytes in 0 blocks
==23084== Rerun with --leak-check=full to see details of leaked memory
==23084== 
==23084== For counts of detected and suppressed errors, rerun with: -v
==23084== ERROR SUMMARY: 32 errors from 5 contexts (suppressed: 0 from 0)
address@hidden:~/tmp/make-50790$ 

With a putative "fix", to leak that one-off allocation:

diff --git a/read.c b/read.c
index 047807a..edba6f8 100644
--- a/read.c
+++ b/read.c
@@ -207,7 +207,8 @@ read_all_makefiles (const char **makefiles)
         eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE);
       }
 
-    free (value);
+    /* We may have retained a pointer to the memory, per bug #50790. */
+    /* free (value); */
   }
 
   /* Read makefiles specified with -f switches.  */

... the problem goes:

address@hidden:~/tmp/make-50790$ MAKEFILES=first.make valgrind 
~/download/make-git/make
==25294== Memcheck, a memory error detector
==25294== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==25294== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==25294== Command: /home/martind/download/make-git/make
==25294== 
false
make: *** [first.make:1: default] Error 1
==25294== 
==25294== HEAP SUMMARY:
==25294==     in use at exit: 156,553 bytes in 1,751 blocks
==25294==   total heap usage: 2,759 allocs, 1,008 frees, 390,488 bytes allocated
==25294== 
==25294== LEAK SUMMARY:
==25294==    definitely lost: 0 bytes in 0 blocks
==25294==    indirectly lost: 0 bytes in 0 blocks
==25294==      possibly lost: 0 bytes in 0 blocks
==25294==    still reachable: 156,553 bytes in 1,751 blocks
==25294==         suppressed: 0 bytes in 0 blocks
==25294== Rerun with --leak-check=full to see details of leaked memory
==25294== 
==25294== For counts of detected and suppressed errors, rerun with: -v
==25294== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
address@hidden:~/tmp/make-50790$

I don't see the valgrind symptom in (Debian's) 3.81 but I do in (Debian's) 4.0. 
 I didn't see an obvious introducer in the source.  The line I nobbled was from 
the first revision in source control.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]