2

I'm using valgrind to check about the memory usage of my C application. After the first tests valgrind reports:

"still reachable: 2,248 bytes in 1 blocks".

I checked the code but I was not able to find the problem at mere sight. So I started to comment sections of the code to try to find the problem.

I was shocked when in my code I only have left

int main(void)
{

}; 

and STILL get the message, with the only difference in the amount of bytes.

I'm really puzzled with this...

Here is the complete messagge:

Running with options : valgrind --leak-check=full --show-reachable=yes

==2557== HEAP SUMMARY:
==2557==     in use at exit: 2,248 bytes in 1 blocks
==2557==   total heap usage: 362 allocs, 361 frees, 14,579 bytes allocated
==2557== 
==2557== 2,248 bytes in 1 blocks are still reachable in loss record 1 of 1
==2557==    at 0x4006171: calloc (vg_replace_malloc.c:593)
==2557==    by 0x4D72250B: monstartup (in /usr/lib/libc-2.15.so)
==2557==    by 0x8048650: __gmon_start__ (in /home/elias/Documents/SL_HTTP/Endosos/bin/Debug/Endosos)
==2557==    by 0x4005421: ??? (in /usr/local/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2557== 
==2557== LEAK SUMMARY:
==2557==    definitely lost: 0 bytes in 0 blocks
==2557==    indirectly lost: 0 bytes in 0 blocks
==2557==      possibly lost: 0 bytes in 0 blocks
==2557==    still reachable: 2,248 bytes in 1 blocks
==2557==         suppressed: 0 bytes in 0 blocks
==2557== 
==2557== For counts of detected and suppressed errors, rerun with: -v
==2557== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Profiling timer expired

I'm compiling with gcc 4.7.2 in Fedrora 17

Any advice will be appreciated. Thanks.

user1274605
  • 405
  • 2
  • 6
  • 17
  • I think still reachable is not an error or anything to worry about. Not complety sure of what it means though :/ – Adrián Jan 28 '13 at 15:29
  • Check this http://stackoverflow.com/questions/3840582/still-reachable-leak-detected-by-valgrind?rq=1. It's a nice answer. – Adrián Jan 28 '13 at 15:32

2 Answers2

1

This is perfectly fine and safe to ignore. In this case this is memory that seems to have been allocated by profiling (you're probably compiling code with profiling enabled or linking to some library that does).

Your environment will do a bunch of things to set up before calling main and those things can allocate memory. Since they know that this memory will be used until the program exits they don't bother to free it on exit because that just takes time for no benefit. Most of that memory will be reported as "still reachable" by valgrind and can be safely ignored.

Art
  • 19,807
  • 1
  • 34
  • 60
0

Thanks to all.

You were right.

I'm using Code:Blocks 12.11 and by default it had enable -pg in the compiler settings.

user1274605
  • 405
  • 2
  • 6
  • 17