tfzxyinhao / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Heap Checker misses a memory leak #369

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. git clone git://github.com/nh13/TMAP.git

2. Checkout revision "d6995c5bed47b71c6f5c8d74355b81ae89d90af7"

3. Apply this patch:
diff --git a/Makefile.am b/Makefile.am
index 66b74a8..e3af6c4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -57,7 +57,7 @@ tmap_SOURCES = \
               src/map/tmap_map_driver.h src/map/tmap_map_driver.c \
               src/tmap_main.h src/tmap_main.c

-tmap_LDADD = 
+tmap_LDADD = -lprofiler

 #noinst_LIBRARIES = libtmap.a
 #libtmap_a_SOURCES = ${GLOBAL_SOURCES} 
diff --git a/configure.ac b/configure.ac
index 0f90914..1b40571 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,7 +24,7 @@ AC_GNU_SOURCE
 #AC_PROG_RANLIB

 # set CFLAGS and CXXFLAGS
-default_CFLAGS="-Wall -g -O3 -pthread -msse2";# "-Wall -g -O3 -pthread -msse2";
+default_CFLAGS="-Wall -g -O3 -pthread -msse2 -ltcmalloc";# "-Wall -g -O3 
-pthread -msse2";
 extended_CFLAGS="";# "-m64 -D_FILE_OFFSET_BITS=64";

 AC_MSG_CHECKING(whether this is a git repository)
diff --git a/src/tmap_main.c b/src/tmap_main.c
index cc48b41..f7f8ba6 100644
--- a/src/tmap_main.c
+++ b/src/tmap_main.c
@@ -82,6 +82,7 @@ int main(int argc, char *argv[])
       tmap_progress_set_command(argv[1]); // set output progress
       tmap_progress_set_start_time(clock()); // set start time

+      /*
       if (0 == strcmp("index", argv[1])) ret = tmap_index(argc-1, argv+1);
       else if (0 == strcmp("server", argv[1])) ret = tmap_server_main(argc-1, argv+1);
       else if (0 == strcmp("map1", argv[1])) ret = tmap_map1_main(argc-1, argv+1);
@@ -108,7 +109,15 @@ int main(int argc, char *argv[])
       else {
           tmap_error1(PACKAGE, "Unknown command", Exit, CommandLineArgument);
       }
+      */

+      int *x = malloc(sizeof(int)*10);
+      int i;
+      for(i=0;i<100;i++) {
+          fprintf(stderr, "x[%d]=%d\n", i, x[i]);
+      }
+      
       tmap_file_fclose(tmap_file_stderr);
   }

4. Configure and make with "./configure --enable-debug-functions && make"

5. run "HEAPCHECK=normal ./tmap dummy".

What is the expected output? What do you see instead?

I expect to see a memory leak detect as the the variable "x" in 
"src/tmap_main.c" is not free, and is accessed beyond its bound.  I see no 
output after the exit of the program.

What version of the product are you using? On what operating system?

From "/usr/local/include/google/tcmalloc.h" "google-perftools 1.7".  "uname -a" 
gives "Linux rnd3 2.6.32-33-generic #72-Ubuntu SMP Fri Jul 29 21:07:13 UTC 2011 
x86_64 GNU/Linux".

Please provide any additional information below.

Original issue reported on code.google.com by nilsho...@gmail.com on 13 Oct 2011 at 3:59

GoogleCodeExporter commented 9 years ago
If stderr is closed within the program, I get this behavior. 

Original comment by nilsho...@gmail.com on 13 Oct 2011 at 4:01

GoogleCodeExporter commented 9 years ago
I believe this is expected behavior.  As the heapchecker says in its output, it 
tries to find all leaks, but is not guaranteed to do so.  The closer a leak is 
to program-exit, the greater the chance it won't be discovered (as I understand 
it).

Original comment by csilv...@gmail.com on 13 Oct 2011 at 8:43