S
Salvatore Iovene
Hi,
I'm using the pexpect module to spawn some processes in a testing
environment. pexpect uses, internally, os.execv. What I need to do is
valgrind python and get memory leaks from the spawned children
(assuming that python doesn't leak ).
Here's a simple testcase:
===================
leak.c:
===================
#include <stdlib.h>
#include <stdio.h>
int main()
{
int *i = (int *) malloc(sizeof(int));
*i = 7;
printf("*i=%d\n", *i);
return 0;
}
===================
leak.py:
===================
import pexpect
import sys
child = pexpect.spawn('./leak')
child.expect('\*i=');
print 'Done'
===================
Valgrind command:
===================
valgrind --leak-check=full --trace-children=yes --tool=memcheck
--suppressions=valgrind-python.supp python ./leak.py
==30239== Memcheck, a memory error detector.
==30239== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==30239== Using LibVEX rev 1658, a library for dynamic binary translation.
==30239== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==30239== Using valgrind-3.2.1-Debian, a dynamic binary
instrumentation framework.
==30239== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==30239== For more details, rerun with: -v
==30239==
Done
==30239==
==30239== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 1092 from 8)
==30239== malloc/free: in use at exit: 702,546 bytes in 140 blocks.
==30239== malloc/free: 2,314 allocs, 2,174 frees, 1,929,320 bytes allocated.
==30239== For counts of detected errors, rerun with: -v
==30239== searching for pointers to 140 not-freed blocks.
==30239== checked 1,069,436 bytes.
==30239==
==30239== LEAK SUMMARY:
==30239== definitely lost: 0 bytes in 0 blocks.
==30239== possibly lost: 0 bytes in 0 blocks.
==30239== still reachable: 699,710 bytes in 138 blocks.
==30239== suppressed: 2,836 bytes in 2 blocks.
==30239== Reachable blocks (those to which a pointer was found) are not shown.
==30239== To see them, rerun with: --show-reachable=yes
As you can see, the 4 bytes leaked by leak.c are not reported. The
suppression file I've used is taken from:
http://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp
and I have uncommented the parts related to PyObject_Free and
PyObject_Realloc, as explained there.
So, does anyone know what the correct way to do this is?
Thanks in advance,
Salvarore.
I'm using the pexpect module to spawn some processes in a testing
environment. pexpect uses, internally, os.execv. What I need to do is
valgrind python and get memory leaks from the spawned children
(assuming that python doesn't leak ).
Here's a simple testcase:
===================
leak.c:
===================
#include <stdlib.h>
#include <stdio.h>
int main()
{
int *i = (int *) malloc(sizeof(int));
*i = 7;
printf("*i=%d\n", *i);
return 0;
}
===================
leak.py:
===================
import pexpect
import sys
child = pexpect.spawn('./leak')
child.expect('\*i=');
print 'Done'
===================
Valgrind command:
===================
valgrind --leak-check=full --trace-children=yes --tool=memcheck
--suppressions=valgrind-python.supp python ./leak.py
==30239== Memcheck, a memory error detector.
==30239== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==30239== Using LibVEX rev 1658, a library for dynamic binary translation.
==30239== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==30239== Using valgrind-3.2.1-Debian, a dynamic binary
instrumentation framework.
==30239== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==30239== For more details, rerun with: -v
==30239==
Done
==30239==
==30239== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 1092 from 8)
==30239== malloc/free: in use at exit: 702,546 bytes in 140 blocks.
==30239== malloc/free: 2,314 allocs, 2,174 frees, 1,929,320 bytes allocated.
==30239== For counts of detected errors, rerun with: -v
==30239== searching for pointers to 140 not-freed blocks.
==30239== checked 1,069,436 bytes.
==30239==
==30239== LEAK SUMMARY:
==30239== definitely lost: 0 bytes in 0 blocks.
==30239== possibly lost: 0 bytes in 0 blocks.
==30239== still reachable: 699,710 bytes in 138 blocks.
==30239== suppressed: 2,836 bytes in 2 blocks.
==30239== Reachable blocks (those to which a pointer was found) are not shown.
==30239== To see them, rerun with: --show-reachable=yes
As you can see, the 4 bytes leaked by leak.c are not reported. The
suppression file I've used is taken from:
http://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp
and I have uncommented the parts related to PyObject_Free and
PyObject_Realloc, as explained there.
So, does anyone know what the correct way to do this is?
Thanks in advance,
Salvarore.