0

我运行 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%的错误,都是关于这个的!

有人知道如何解决这个问题吗?

4

1 回答 1

1

您是否打开了许多数据库连接句柄而忘记释放它们?使用 libpq 时,您应该始终释放 由 返回的指针使用的内存PQconnectdb,即使与服务器的连接不成功。为此,请PQfinish使用指向 的指针进行调用PGconn

于 2013-10-20T23:57:57.690 回答