471,354 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

Valgrind and pexpect

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 ./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== 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
0 1240

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Michael Surette | last post: by
2 posts views Thread by Adrian Casey | last post: by
reply views Thread by dwelch91 | last post: by
5 posts views Thread by half.italian | last post: by
1 post views Thread by Kevin Erickson | last post: by
8 posts views Thread by asgarde | last post: by
5 posts views Thread by crybaby | last post: by
2 posts views Thread by yellowblueyellow | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.