|
From: <su...@un...> - 2004-05-25 20:07:06
|
hi,
i am a new valgrind user. i am facing the following proble.
i have a test program here
#include <stdio.h>
void Leak(char *inStr)
{
char *str = (char *) malloc(strlen(inStr));
memcpy(str, inStr, strlen(inStr));
}
char *AvoidLeak(char *inStr)
{
char *str = (char *) malloc(strlen(inStr));
memcpy(str, inStr, strlen(inStr));
return str;
}
int main()
{
char *str;
Leak("This leaks 19 bytes");
str = AvoidLeak("This is not a 26 byte leak");
free(str);
str = AvoidLeak("12 byte leak");
exit(0);
}
i run
1) gcc -o test -g test.c
followed by
2) valgrind --leak-check=yes --show-reachable=yes --num-callers=20
--error-limit=no ./test
**********************************
I should get the output as
**********************************
==27145== valgrind-1.0.0, a memory error detector for x86 GNU/Linux.
==27145== Copyright (C) 2000-2002, and GNU GPL'd, by Julian Seward.
==27145== Estimated CPU clock rate is 993 MHz
==27145== For more details, rerun with: -v
==27145==
==27145==
==27145== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==27145== malloc/free: in use at exit: 31 bytes in 2 blocks.
==27145== malloc/free: 3 allocs, 1 frees, 57 bytes allocated.
==27145== For counts of detected errors, rerun with: -v
==27145== searching for pointers to 2 not-freed blocks.
==27145== checked 3661276 bytes.
==27145==
==27145== definitely lost: 19 bytes in 1 blocks.
==27145== possibly lost: 0 bytes in 0 blocks.
==27145== still reachable: 12 bytes in 1 blocks.
==27145==
==27145== 12 bytes in 1 blocks are still reachable in loss record 1 of 2
==27145== at 0x40046824: malloc (vg_clientfuncs.c:100)
==27145== by 0x8048594: AvoidLeak (test.c:11)
==27145== by 0x804860E: main (test.c:23)
==27145== by 0x4026A657: __libc_start_main (../sysdeps/generic/libc-start.c:129)
==27145==
==27145== 19 bytes in 1 blocks are definitely lost in loss record 2 of 2
==27145== at 0x40046824: malloc (vg_clientfuncs.c:100)
==27145== by 0x804854C: Leak (test.c:5)
==27145== by 0x80485DB: main (test.c:20)
==27145== by 0x4026A657: __libc_start_main (../sysdeps/generic/libc-start.c:129)
==27145==
==27145== LEAK SUMMARY:
==27145== definitely lost: 19 bytes in 1 blocks.
==27145== possibly lost: 0 bytes in 0 blocks.
==27145== still reachable: 12 bytes in 1 blocks.
==27145==
**************************************************
but i am getting output as
**************************************************
[root@localhost test valgrind programs]# valgrind --leak-check=yes
--show-reachable=yes --num-callers=20 -v --single-step=yes --error-limit=no
--num-callers=20 ./a.out
/usr/local/bin/valgrind: line 120: [: too many arguments
==21461== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
==21461== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward.
==21461== Using valgrind-2.0.0, a program supervision framework for x86-linux.
==21461== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward.
==21461== Command line:
==21461== ./a.out
==21461== Startup, with flags:
==21461== --suppressions=/usr/local/lib/valgrind/default.supp
==21461== --leak-check=yes
==21461== --show-reachable=yes
==21461== --num-callers=20
==21461== -v
==21461== --single-step=yes
==21461== --error-limit=no
==21461== --num-callers=20
==21461== Reading syms from /lib/ld-2.3.2.so
==21461== Reading syms from /usr/local/lib/valgrind/vgskin_memcheck.so
==21461== Reading syms from /usr/local/lib/valgrind/valgrind.so
==21461== Reading syms from /lib/libc-2.3.2.so
==21461== Reading suppressions file: /usr/local/lib/valgrind/default.supp
==21461== Estimated CPU clock rate is 1999 MHz
==21461==
==21461==
==21461== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==21461== malloc/free: in use at exit: 31 bytes in 2 blocks.
==21461== malloc/free: 3 allocs, 1 frees, 57 bytes allocated.
==21461==
==21461== searching for pointers to 2 not-freed blocks.
==21461== checked 3542472 bytes.
==21461==
==21461== 12 bytes in 1 blocks are still reachable in loss record 1 of 2
==21461== at 0x400296B2: malloc (vg_replace_malloc.c:153)
==21461== by 0x8048453: ???
==21461== by 0x80484CC: ???
==21461== by 0x402438C6: __libc_start_main (in /lib/libc-2.3.2.so)
==21461== by 0x8048368: ???
==21461==
==21461==
==21461== 19 bytes in 1 blocks are definitely lost in loss record 2 of 2
==21461== at 0x400296B2: malloc (vg_replace_malloc.c:153)
==21461== by 0x8048411: ???
==21461== by 0x804849B: ???
==21461== by 0x402438C6: __libc_start_main (in /lib/libc-2.3.2.so)
==21461== by 0x8048368: ???
==21461==
==21461== LEAK SUMMARY:
==21461== definitely lost: 19 bytes in 1 blocks.
==21461== possibly lost: 0 bytes in 0 blocks.
==21461== still reachable: 12 bytes in 1 blocks.
==21461== suppressed: 0 bytes in 0 blocks.
==21461==
--21461-- TT/TC: 0 tc sectors discarded.
--21461-- 1163 chainings, 0 unchainings.
--21461-- translate: new 2506 (7663 -> 169097; ratio 220:10)
--21461-- discard 0 (0 -> 0; ratio 0:10).
--21461-- dispatch: 0 jumps (bb entries), of which 2871 (287100%) were unchained.
--21461-- 2/2520 major/minor sched events. 2513 tt_fast misses.
--21461-- reg-alloc: 1 t-req-spill, 25423+8 orig+spill uis, 8081 total-reg-r.
--21461-- sanity: 3 cheap, 1 expensive checks.
--21461-- ccalls: 2233 C calls, 66% saves+restores avoided (8748 bytes)
--21461-- 2868 args, avg 0.92 setup instrs each (416 bytes)
--21461-- 0% clear the stack (6699 bytes)
--21461-- 821 retvals, 4% of reg-reg movs avoided (54 bytes)
[root@localhost test valgrind programs]#
can anyone tell me why i am getting ???? instead of getting the function name
and line number here
Thank yuo
|