What is the best way for finding memory leaks in Apache httpd and httpd modules?
Are there any howtos?
I'v tried valgrind a little, but few obstacles appeared:
OS: Linux
P.S.:
Valgrind command: $ valgrind --leak-check=full --leak-resolution=med --log-file=/tmp/valgrind.log ./bin/httpd -X
Valgrind output example: http://paste-it.net/public/x5b6e8b/
I don't know of a magic bullet, but you can have a look at valgrind/valgrind.h , it has some useful macros to make things Valgrind aware and alter their behavior if running under Valgrind.
For instance
#ifndef HAVE_VALGRIND_VALGRIND_H
#define RUNNING_ON_VALGRIND 0
#else
#include <valgrind/valgrind.h>
#endif
if (RUNNING_ON_VALGRIND) {
printf("Hello, this is Valgrind instance %d\n", RUNNING_ON_VALGRIND);
/* set debug output annoyingly high */
/* exit after one request */
}
You can also encase that whole mess with NDEBUG
to keep it out of production builds.
That should save you from having to fiddle with the server each time you debug, it will 'just do it' if Valgrind is detected. RUNNING_ON_VALGRIND will expand to the valgrind instance, or remain 0 if not applicable.
For the rest (and I'm imagining you are getting a ton of noise, most likely starting with invalid read of size xx
), you can systematically apply suppressions. If you post some of the output, it might be easier to make suggestions for the suppressions you can stick in a file.
Incidentally, the Valgrind user's mailing list is extremely helpful and very tolerant. You can also post your most annoying and irrelevant noise there, you'll get replies with how to suppress it rather quickly.
If all you want is a summary of leaks and the entry points that led to them, it should not be too difficult to shut almost everything else up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With