tags:

views:

92

answers:

2

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

+1  A: 

You didn't say which compiler you are using, I suppose gcc? Do you use -g to have debugging symbols included?

Jens Gustedt
yea i use gcc and no i didnt use -g
Nadav Stern
In that case use -g and check, as debug symbols may not be available
Praveen S
+1  A: 

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.

caf
can u tell me what is the command to see where was the memory leak created please
Nadav Stern
@Nadav: The above example is just from the regular Valgrind output. That's all you need.
caf