Fog Creek Software
Discussion Board




Detecting Memory Leaks in Shared Libraries

Does anyone know of a tool that I can use to find memory leaks in a shared library?

I built a php extension and it is loaded as an .so at runtime and I need to detect if there are any leaks in the code.  I've built php in debug mode and introduced a mem leak on purpose to see if it notices and it doesn't.  Any ideas?

PHP leak
Tuesday, September 09, 2003

Purify is available on most systems, but costs lots of $$$.

Valgrind is free (libre and gratis), and is available for x86 linux.

There are other memory management libraries, such as MemPatrol that can detect leaks; The Microsoft Debug run time has such a facility. You might have to recompile PHP to use any of them, though.

Which platform are you using?

Ori Berger
Tuesday, September 09, 2003

I'm on Linux... I downloaded valgrind but when I compile it, it says:

vg_intercept.c: In function `vgAllRoadsLeadToRome_poll':
vg_intercept.c:284: sizeof applied to an incomplete type
vg_intercept.c: In function `vgAllRoadsLeadToRome_select':
vg_intercept.c:562: sizeof applied to an incomplete type
vg_intercept.c:573: dereferencing pointer to incomplete type
vg_intercept.c:573: dereferencing pointer to incomplete type
vg_intercept.c:593: dereferencing pointer to incomplete type
vg_intercept.c:594: dereferencing pointer to incomplete type

PHP leak
Tuesday, September 09, 2003

Well I think you would get better help on the valgrind mailing list for that.  Build problems are one of those things that tend to get responded to quickly, as long as you provide the distro and compiler version you're using.

Alex
Tuesday, September 09, 2003

I forgot to look in the error_log in apache... All my memory leak info was in there  (it didn't make it super easy to figure out what I had to do to fix them, but a lot of trial and error is leading me in the right direction).

PHP leak
Tuesday, September 09, 2003

Won't solve this particular problem but does provide some information of memory usage plus plenty of other essential stuff as seen from a PHP script - XDebug: http://xdebug.derickrethans.nl/

Anon Coward
Wednesday, September 10, 2003

*  Recent Topics

*  Fog Creek Home