FreeBSD 9.0: Valgrind leaks memory

Ina J. inarvaj at
Fri Mar 16 11:23:51 UTC 2012


I tried to find a thread about this, but I didn't and in this
suggested to send message to the mailing list.

I've been developing program for Linux under Ubuntu 10.04. I want to get
the code running under my FreeBSD 9.0-RELEASE server. The code compiles
without problems, but Valgrind doesn't work the same way as on my Ubuntu. I
made an example code, which produces a memory leak with Valgrind. The code
is as follows:

### C O D E ###
#include <iostream>
int main()
    std::cout << "Valgrind leaks memory" << std::endl;
    return 0;

I compile it simply with command:

And then run it in valgrind:
valgrind --show-reachable=yes --tool=memcheck --db-attach=yes
--leak-check=full --track-origins=yes ./a.out

And Valgrind outputs this:

### V AL G R I N D   O U T P U T ###
==39783== Memcheck, a memory error detector
==39783== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==39783== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==39783== Command: ./a.out
Valgrind leaks memory
==39783== HEAP SUMMARY:
==39783==     in use at exit: 4,096 bytes in 1 blocks
==39783==   total heap usage: 1 allocs, 0 frees, 4,096 bytes allocated
==39783== 4,096 bytes in 1 blocks are still reachable in loss record 1 of 1
==39783==    at 0x5BF98: malloc (in
==39783==    by 0x26B503: ??? (in /lib/
==39783==    by 0x26B3C4: ??? (in /lib/
==39783==    by 0x26AF12: ??? (in /lib/
==39783==    by 0x26AAB4: fwrite (in /lib/
==39783==    by 0xA1135: ??? (in /usr/lib/
==39783==    by 0xDC3C7: std::basic_ostream<char, std::char_traits<char> >&
std::__ostream_insert<char, std::char_traits<char>
>(std::basic_ostream<char, std::char_traits<char> >&, char const*, int) (in
==39783==    by 0xDC5DB: std::basic_ostream<char, std::char_traits<char> >&
std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*) (in /usr/lib/
==39783==    by 0x80488C4: main (in /usr/home/ina/test/a.out)
==39783== LEAK SUMMARY:
==39783==    definitely lost: 0 bytes in 0 blocks
==39783==    indirectly lost: 0 bytes in 0 blocks
==39783==      possibly lost: 0 bytes in 0 blocks
==39783==    still reachable: 4,096 bytes in 1 blocks
==39783==         suppressed: 0 bytes in 0 blocks
==39783== For counts of detected and suppressed errors, rerun with: -v
==39783== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

In my Ubuntu, Valgrind detects no memory leaks. Although, those reported
leaks are just reachable bytes, but there shouldn't be any of them.

On my Ubuntu g++ and Valgrind versions are as follows:
g++ (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3

And on FreeBSD:
g++ (GCC) 4.2.1 20070831 patched [FreeBSD]

With my actual code, Valgrind reports a lot more memory leaks and also
those mentioned on the thread I linked, but sample code is enough to
produce errors which shouldn't exist.


More information about the freebsd-stable mailing list