openssl / valgrind

发布于 2024-07-12 12:16:10 字数 1155 浏览 11 评论 0原文

我有一个必须计算文件 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)

有人有相同的经历吗?

I have an application that has to calculate the MD5 of file, I have
used the openssl library, valgrind complains about some blocks still
reachable.

Compile the following code:

#include <openssl/bio.h>

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

the run it using valgrind this is what I'm obtaining:

==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)

anyone had same experience ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

无法回应 2024-07-19 12:16:10

当未使用 -DPURIFY 编译时,OpenSSL 的某些操作会使 Valgrind 感到困惑。 这是您看到的错误吗?

OpenSSL has actions that confuse Valgrind when not compiled with -DPURIFY. Is this the error you are seeing?

顾忌 2024-07-19 12:16:10

我相信这些是 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;
}

~

I believe those are some static structures that openssl allocates. I ran your code, and I ran the following code and valgrind reported that both had the same amount of unfreed memory:

#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;
}

~

め可乐爱微笑 2024-07-19 12:16:10
BIO_new() -> BIO_set() -> CRYPTO_new_ex_data() -> int_new_ex_data() -> def_get_class()

int_new_ex_data() 不会释放 def_get_class malloc 的内存。

请参阅: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

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

int_new_ex_data() do not release the mem that def_get_class malloced.

SEE: 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

动次打次papapa 2024-07-19 12:16:10

OpenSSL 包含大量未初始化的变量、从未释放的变量和内存、从未清除的变量以及无法在范围外访问甚至无法手动释放的变量。
Valgrind 发现了很多这样的东西。

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

OpenSSL contains a lot of uninitialized variables, variables and memory never freed, variables never cleared and not reachable outside scope to even be freed manually.
Valgrind finds a lot of these.

The PURIFY flag is only related to the rand()_function. So to avoid a detection in Purify Openssl actually uses different source code if that flag is set. Nice coding... Maybe better to fix the problem in first place?!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文