Vitor Villar
Vitor Villar

Reputation: 1925

Checking memory with Valgrind

i run valgrind to see what errors my program have about problems of memory. And the output of valgrind is:

==31041== 17,736 bytes in 1 blocks are still reachable in loss record 423 of 423
==31041==    at 0x4C2CD7B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==31041==    by 0x5B0F21F: CRYPTO_malloc (in /lib/x86_64-linux-gnu/libcrypto.so.1.0.0)
==31041==    by 0x5874B12: ??? (in /lib/x86_64-linux-gnu/libssl.so.1.0.0)
==31041==    by 0x5874C68: ??? (in /lib/x86_64-linux-gnu/libssl.so.1.0.0)
==31041==    by 0x586DE5B: ??? (in /lib/x86_64-linux-gnu/libssl.so.1.0.0)
==31041==    by 0x4E4FFEA: ??? (in /usr/lib/libpq.so.5.4)
==31041==    by 0x4E40AB5: PQconnectPoll (in /usr/lib/libpq.so.5.4)
==31041==    by 0x4E41F4D: ??? (in /usr/lib/libpq.so.5.4)
==31041==    by 0x4E428FE: PQconnectdb (in /usr/lib/libpq.so.5.4)
==31041==    by 0x401D18: open_connection (database.c:23)
==31041==    by 0x402A78: init (kernel.c:28)
==31041==    by 0x402E9C: main (main.c:22)

90% of the errors, is about this!

Someone know how to solve this?

Upvotes: 0

Views: 262

Answers (1)

Delan Azabani
Delan Azabani

Reputation: 81502

Are you opening many database connection handles and forgetting to free them? When using libpq, you should always free the memory used by the pointer returned by PQconnectdb, even if a connection to a server did not succeed. To do this, call PQfinish with your pointer to PGconn.

Upvotes: 1

Related Questions