views:

409

answers:

3

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 ?

+1  A: 

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

HUAGHAGUAH
As an example of what happens when you don't use -DPURIFY, see http://www.metasploit.com/users/hdm/tools/debian-openssl/ (I'm not saying that running valgrind without -DPURIFY directly caused the bug, but it did cause people to take actions that ended up causing the bug). :-P
Chris Jester-Young
A: 

No, the error I'm seeing is the one I have reported on my host, also I have not compiled OpenSSL but I'm using the one available on my distribution: UbuntuGutsy.

Gaetano Mendola
A: 

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

~

twk