Valgrind and pexpect

Discussion in 'Python' started by Salvatore Iovene, Dec 20, 2007.

  1. 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.


    --
    Salvatore Iovene
    http://www.iovene.com/
    Key Fingerprint: 5647 944D D5AD 2E87 00B4 7D54 2864 359D FF20 16D8
     
    Salvatore Iovene, Dec 20, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Esa A E Peuha

    Valgrind and Python

    Esa A E Peuha, Nov 10, 2007, in forum: Python
    Replies:
    3
    Views:
    999
    Terry Reedy
    Nov 10, 2007
  2. Jean-Paul Calderone

    Re: Valgrind and Python

    Jean-Paul Calderone, Nov 10, 2007, in forum: Python
    Replies:
    1
    Views:
    345
    Esa A E Peuha
    Nov 11, 2007
  3. David RF

    Confused with valgrind and memmove

    David RF, Sep 11, 2009, in forum: C Programming
    Replies:
    4
    Views:
    1,139
  4. Saqib Ali
    Replies:
    1
    Views:
    367
    Roy Smith
    Dec 26, 2011
  5. Heiko Leberer

    valgrind and embedded ruby

    Heiko Leberer, Nov 21, 2005, in forum: Ruby
    Replies:
    0
    Views:
    106
    Heiko Leberer
    Nov 21, 2005
Loading...

Share This Page