2013-10-20 74 views
0

我運行valgrind來查看我的程序有關內存問題的錯誤。 而Valgrind的輸出是:錯誤的使用Valgrind檢查內存

==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%,大約是這個!

有人知道如何解決這個問題嗎?

回答

1

你打開許多數據庫連接句柄,忘記釋放它們嗎?使用libpq時,即使與服務器的連接不成功,也應該釋放由PQconnectdb返回的指針所使用的內存。要做到這一點,請致電PQfinish,並指向PGconn

+0

沒錯,但我打開一個連接,並在所有需要連接的功能中使用。如何進行? –