Sandeep Pathak
Sandeep Pathak

Reputation: 10747

Valgrind complains while working with threads

I have created 20 threads to read/write a shared file.I have synchronized threads. Now My program works fine but when I run it with valgrind it gives me Errors like this:

LEAK SUMMARY:

   **definitely lost: 0 bytes in 0 blocks.
\
     **possibly lost: 624 bytes in 5 blocks.**

   **still reachable: 1,424 bytes in 5 blocks.****


    suppressed: 0 bytes in 0 blocks.

Reachable blocks (those to which a pointer was found) are not shown.

Also When I press Ctrl + c , it gives the same errors.

I have not even malloced anything but still valgrind complains.

Any suggestion would be appreciated .

Upvotes: 1

Views: 671

Answers (2)

DavidMFrey
DavidMFrey

Reputation: 1668

You can run valgrind --leak-check=full ./prog_name to make sure these reachable blocks are not something you can destroy in your program. Many times initializing a library such as libcurl without closing or destroying it will cause leaks. If it's not something you have control over, you can write a suppression file. http://valgrind.org/docs/manual/mc-manual.html section 4.4 has some info and a link to some examples

Upvotes: 2

James
James

Reputation: 25533

Sill reachable blocks are probably caused by your standard library not freeing memory used in pools for standard containers (see this faq): which would be a performance optimisation for program exit, since the memory is immediately going to be returned to the operating system anyway.

"Possibly lost" blocks are probably caused by the same thing.

The Valgrind Manual page for memcheck has a good explanation about the different sorts of leaks detected.

Upvotes: 1

Related Questions