在valgrind中检查内存泄漏

时间:2013-02-11 10:22:28

标签: memory valgrind memory-leaks

我的老师说我的程序中有内存泄漏,所以我用valgrind来检查它。我收到了以下错误:

==24060== Invalid read of size 8
==24060==    at 0x4EB4B4C: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5E253: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060==  Address 0x51dc040 is 0 bytes inside a block of size 5 alloc'd
==24060==    at 0x4C2AD7B: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==24060==    by 0x4E63D43: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5E23D: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Invalid read of size 8
==24060==    at 0x4EB4B54: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5E253: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060==  Address 0x51dc048 is 3 bytes after a block of size 5 alloc'd
==24060==    at 0x4C2AD7B: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==24060==    by 0x4E63D43: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5E23D: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Invalid read of size 8
==24060==    at 0x4EB4931: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5E266: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060==  Address 0x51dc040 is 0 bytes inside a block of size 5 alloc'd
==24060==    at 0x4C2AD7B: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==24060==    by 0x4E63D43: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5E23D: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Conditional jump or move depends on uninitialised value(s)
==24060==    at 0x4EB493F: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5DF87: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Conditional jump or move depends on uninitialised value(s)
==24060==    at 0x4E5DF8D: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Conditional jump or move depends on uninitialised value(s)
==24060==    at 0x4E5DFAF: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Use of uninitialised value of size 8
==24060==    at 0x4E5E033: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Use of uninitialised value of size 8
==24060==    at 0x4E5E041: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Conditional jump or move depends on uninitialised value(s)
==24060==    at 0x4E5E047: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Conditional jump or move depends on uninitialised value(s)
==24060==    at 0x4EB2E42: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5E06C: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Use of uninitialised value of size 8
==24060==    at 0x4EB4214: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5E06C: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Use of uninitialised value of size 8
==24060==    at 0x4EB4218: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5E06C: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Invalid read of size 8
==24060==    at 0x4EB2E1E: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CECD: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060==  Address 0x51dc158 is 8 bytes inside a block of size 12 alloc'd
==24060==    at 0x4C2AD7B: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==24060==    by 0x4EB4591: strdup (in /lib64/libc-2.16.so)
==24060==    by 0x4E5E129: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Invalid read of size 8
==24060==    at 0x4EB4931: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4EB4585: strdup (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CEE4: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060==  Address 0x51dc158 is 8 bytes inside a block of size 12 alloc'd
==24060==    at 0x4C2AD7B: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==24060==    by 0x4EB4591: strdup (in /lib64/libc-2.16.so)
==24060==    by 0x4E5E129: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Invalid read of size 8
==24060==    at 0x4EB2E23: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5DEFA: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060==  Address 0x51dc158 is 8 bytes inside a block of size 12 alloc'd
==24060==    at 0x4C2AD7B: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==24060==    by 0x4EB4591: strdup (in /lib64/libc-2.16.so)
==24060==    by 0x4E5E129: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D328: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CE85: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Invalid read of size 8
==24060==    at 0x4EB4931: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5C9D2: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D0B2: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060==  Address 0x51dd568 is 8 bytes inside a block of size 12 alloc'd
==24060==    at 0x4C2AD7B: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==24060==    by 0x4EB4591: strdup (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CEE4: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Invalid read of size 8
==24060==    at 0x4EB2E1E: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CA0F: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D0B2: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060==  Address 0x51dd518 is 8 bytes inside a block of size 12 alloc'd
==24060==    at 0x4C2AD7B: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==24060==    by 0x4EB4591: strdup (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CEE4: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Invalid read of size 8
==24060==    at 0x4EB2E23: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CA0F: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D0B2: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060==  Address 0x51dd568 is 8 bytes inside a block of size 12 alloc'd
==24060==    at 0x4C2AD7B: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==24060==    by 0x4EB4591: strdup (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CEE4: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Invalid read of size 8
==24060==    at 0x4EB2E1E: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CA83: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D0B2: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060==  Address 0x51dd568 is 8 bytes inside a block of size 12 alloc'd
==24060==    at 0x4C2AD7B: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==24060==    by 0x4EB4591: strdup (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CEE4: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 
==24060== Invalid read of size 8
==24060==    at 0x4EB2E1E: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CA9D: ??? (in /lib64/libc-2.16.so)
==24060==    by 0x4E5D0B2: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060==  Address 0x51dd568 is 8 bytes inside a block of size 12 alloc'd
==24060==    at 0x4C2AD7B: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==24060==    by 0x4EB4591: strdup (in /lib64/libc-2.16.so)
==24060==    by 0x4E5CEE4: setlocale (in /lib64/libc-2.16.so)
==24060==    by 0x401751: ??? (in /usr/bin/test)
==24060==    by 0x4E52804: (below main) (in /lib64/libc-2.16.so)
==24060== 

任何人都可以帮我理解这个错误是什么意思吗?

1 个答案:

答案 0 :(得分:1)

为什么valgrind输出不显示行号?我不知道在哪里寻找这个错误。 我使用flag -g编译了我的程序,并使用valgrind,语法如下: valgrind --tool = memcheck --track-originins = yes -q test