openssl / valgrind

时间:2009-01-23 13:07:58

标签: openssl valgrind

我有一个应用程序必须计算文件的MD5,我有 使用openssl库,valgrind仍抱怨一些块 可到达的。

编译以下代码:

#include <openssl/bio.h>

int main(int, char**)
{
   BIO * mem = BIO_new(BIO_s_mem());
   BIO_vfree(mem);
   return 0;
}

使用valgrind运行它是我得到的:

==23597== 220 bytes in 6 blocks are still reachable in loss record 1 of 1
==23597==    at 0x4022D78: malloc (vg_replace_malloc.c:207)
==23597==    by 0x432FD0D: (within /usr/lib/i686/cmov/libcrypto.so.0.9.8)
==23597==    by 0x433036E: CRYPTO_malloc (in /usr/lib/i686/cmov/libcrypto.so.0.9.8)
==23597==    by 0x43989C9: lh_new (in /usr/lib/i686/cmov/libcrypto.so.0.9.8)
==23597==    by 0x4332025: (within /usr/lib/i686/cmov/libcrypto.so.0.9.8)
==23597==    by 0x433249B: (within /usr/lib/i686/cmov/libcrypto.so.0.9.8)
==23597==    by 0x4332B5D: CRYPTO_new_ex_data (in /usr/lib/i686/cmov/libcrypto.so.0.9.8)
==23597==    by 0x438E053: BIO_set (in /usr/lib/i686/cmov/libcrypto.so.0.9.8)
==23597==    by 0x438E0E9: BIO_new (in /usr/lib/i686/cmov/libcrypto.so.0.9.8)
==23597==    by 0x80485E1: main (in /home/kalman/cxx_test/md5test/a.out)
谁有同样的经历?

4 个答案:

答案 0 :(得分:4)

当未使用-DPURIFY编译时,OpenSSL的操作会使Valgrind感到困惑。 Is this the error you are seeing?

答案 1 :(得分:4)

我相信那些是openssl分配的静态结构。我运行了你的代码,我运行了以下代码,valgrind报告说它们都有相同数量的不同内存:

#include <openssl/bio.h>

int main(int, char**)
{
   BIO * mem = BIO_new(BIO_s_mem());
   BIO * mem2 = BIO_new(BIO_s_mem());
   BIO * mem3 = BIO_new(BIO_s_mem());
   BIO * mem4 = BIO_new(BIO_s_mem());
   BIO_vfree(mem);
   BIO_vfree(mem2);
   BIO_vfree(mem3);
   BIO_vfree(mem4);
   return 0;
}

答案 2 :(得分:4)

BIO_new() -> BIO_set() -> CRYPTO_new_ex_data() -> int_new_ex_data() -> def_get_class()

int_new_ex_data()不会释放def_get_class malloced的模因。

参见:http://openssl.6102.n7.nabble.com/memory-leak-in-engine-cleanup-td30935.html http://rt.openssl.org/Ticket/Display.html?id=2673&user=guest&pass=guest

答案 3 :(得分:2)

OpenSSL包含许多未初始化的变量,变量和内存从未被释放,变量从未被清除,并且在范围之外无法访问甚至可以手动释放。 Valgrind发现了很多这些。

PURIFY标志仅与rand()_函数有关。因此,为了避免在Purify中检测Openssl实际上使用了不同的源代码,如果设置了该标志。不错的编码...也许最好先解决问题?!