Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Still reachable in valgrind

While searching about still reachable in valgrind, some people say its not a problem. we don't nedd to fix it. Some people say it needs to be fixed.I would be better if somebody could exaplain me explicitly what is the logic behind this still reachable. Is it mandatory to fix this?

[EDIT]

I have following valgrind output for my C program.Do i need to fix it?

      LEAK SUMMARY:
      ==27333==    definitely lost: 0 bytes in 0 blocks.
      ==27333==      possibly lost: 0 bytes in 0 blocks.
      ==27333==    still reachable: 96 bytes in 12 blocks.
      ==27333==         suppressed: 0 bytes in 0 blocks.
like image 447
thetna Avatar asked Dec 10 '10 06:12

thetna


People also ask

What does still reachable mean Valgrind?

The "still reachable" category within Valgrind's leak report refers to allocations that fit only the first definition of "memory leak". These blocks were not freed, but they could have been freed (if the programmer had wanted to) because the program still was keeping track of pointers to those memory blocks.

What does it mean if memory is still reachable?

"still reachable" means your program is probably ok -- it didn't free some memory it could have. This is quite common and often reasonable.

How do I show line numbers in Valgrind?

If you compile your program with the -g flag, Valgrind will show you the function names and line numbers where errors occur.


1 Answers

It depends. "Still reachable" means you haven't deallocated a block of memory before exiting, but had a pointer to it.

In a C++ program this means that some object could have not been deleted and therefore its destructor might not have been run and thus say some data might have not been saved onto disk for example and some other action might not have been taken and thus your program might produce unexpected behavior.

However there're no destructors in C programs, so your program just can't depend on that. Also deallocating memory takes some time, so by not freeing memory on exit you can save some time - your program will exit faster (this can be significant for programs with lots of data).

So IMO if your C program has "still reachable" blocks it's not a problem but this indicates that some code in the program doesn't free memory and so you can expect bugs when reusing that code.

like image 54
sharptooth Avatar answered Nov 15 '22 08:11

sharptooth