hello i got a problem using valgrind
when i use it with valgrind --leak-check=full
and afterwards the name of excution file it tells me in which blocks the memory leak is but when i cant find to which pointer i did use free.
is there some sort of flag that tells the name of the pointer.
if there is anyway to tell me where the leak is on visual studio i would very much like to hear about it too
views:
92answers:
2You didn't say which compiler you are using, I suppose gcc?
Do you use -g
to have debugging symbols included?
It can't tell you the name of the pointer, because the whole idea of a memory leak is that no pointer points at the memory any more (at least, for the kinds of leaks that Valgrind describes as "definitely lost").
What it can tell you is the source file and line number where the memory was allocated - you then will need to look up that line in your source to figure out where the memory is supposed to be deallocated. For example, if the Valgrind loss record looks like:
==17110== 49 bytes in 1 blocks are definitely lost in loss record 17 of 35
==17110== at 0x4023D6E: malloc (vg_replace_malloc.c:207)
==17110== by 0x80C4CF8: do_foo (foo.c:1161)
==17110== by 0x80AE325: xyzzy (bar.c:466)
==17110== by 0x8097C46: io (bar.c:950)
==17110== by 0x8098163: main (quux.c:1291)
Then you need to look at line 1161 in foo.c
, which is within the function do_foo()
. That's where the memory was allocated (with malloc()
), and only you can say where it should have been freed.