By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,314 Members | 1,772 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,314 IT Pros & Developers. It's quick & easy.

Valgrind and pexpect

P: n/a
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:


#include <stdlib.h>
#include <stdio.h>

int main()
int *i = (int *) malloc(sizeof(int));
*i = 7;
printf("*i=%d\n", *i);

return 0;
import pexpect
import sys

child = pexpect.spawn('./leak')
print 'Done'

Valgrind command:

valgrind --leak-check=full --trace-children=yes --tool=memcheck
--suppressions=valgrind-python.supp python ./

==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== 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== 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:
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,
Salvatore Iovene
Key Fingerprint: 5647 944D D5AD 2E87 00B4 7D54 2864 359D FF20 16D8
Dec 20 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.