|
|
Log in / Subscribe / Register

The Valgrind Project releases version 3.4.0

The Valgrind Project releases version 3.4.0

Posted Jan 15, 2009 3:09 UTC (Thu) by pr1268 (guest, #24648)
Parent article: The Valgrind Project releases version 3.4.0

Cool! I like Valgrind—it's certainly useful for hunting down memory leaks. And, since I have a gnarly case of OCD, I'm always checking my own C/C++ programs for leaks. :-\

For some valgrind fun, watch how the below C++ program leaks 19 bytes (likely due to me pulling the plug just after the std::string was allocated in free store):

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

void die()
{
    exit(EXIT_SUCCESS);
}

int main()
{
    string s("I leak");
    cout << s << endl;
    die();
}

Many thanks to the Valgrind developers!


to post comments

Clarification

Posted Jan 15, 2009 15:51 UTC (Thu) by pr1268 (guest, #24648) [Link] (2 responses)

I should clarify that Valgrind says that the above program possibly lost 19 bytes. And, the Valgrind documentation mentions the possibility of false positives related to what this program does.

Still, I find it interesting to analyze the behavior of C++ allocator-based container and "almost container" classes using Valgrind. Not to mention its usefulness in finding uninitialized memory issues as discussed below.

Clarification

Posted Jan 15, 2009 16:59 UTC (Thu) by jengelh (subscriber, #33263) [Link] (1 responses)

>possibly lost 19 bytes.

And let's not forget that glibc and libdl always keep some memory unfreed. Even more so, I get "use of uninitialized value" from libdl :-/

Clarification

Posted Jan 24, 2009 11:22 UTC (Sat) by oak (guest, #2786) [Link]

Valgrind has suppressions for lots of error messages from libdl, but for
suppressions to work it needs debug symbols for libdl, do you have those?
(AFAIK most distros don't strip libdl debug symbols from libc6 package)

The Valgrind Project releases version 3.4.0

Posted Jan 15, 2009 16:58 UTC (Thu) by jengelh (subscriber, #33263) [Link] (1 responses)

>since I have a gnarly case of OCD, I'm always checking my own C/C++ programs for leaks.

That's not OCD but the sign of being a good developer. Having to find bugs and memory leaks is not pleasing, but making the best effort that you find the bugs/leaks before the users do, that's just pro.

The Valgrind Project releases version 3.4.0

Posted Jan 15, 2009 18:04 UTC (Thu) by pr1268 (guest, #24648) [Link]

Aww, thanks! Your comment made my day.

But, I really do have OCD (self-diagnosed). Believe me, I've actually re-written dozens of C/C++/Java programs I authored just to make code style and indentation changes. I once rewrote an entire music directory utility I use personally (about 10 source files) just to get rid of what Valgrind said was a "possible" 12-byte leak (according to a CS professor who examined my code, Valgrind may have given a false positive).


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds