Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

openssl / valgrind

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 ?

like image 210
Gaetano Mendola Avatar asked Jan 23 '09 13:01

Gaetano Mendola


Video Answer


2 Answers

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

like image 77
HUAGHAGUAH Avatar answered Oct 09 '22 02:10

HUAGHAGUAH


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

~

like image 21
twk Avatar answered Oct 09 '22 02:10

twk