[SciPy-dev] Valgrind primer

Travis Oliphant oliphant at ee.byu.edu
Fri Nov 4 19:27:52 EST 2005


I've been playing with valgrind to detect memory leaks and other memory 
errors in scipy.  It's a pretty nice tool.   It often comes with most 
Linux distributions (on my system urpmi valgrind installed it for me).

To use it to debug extension modules, you should have a Python compiled 
with debugging symbols (-g) option.  This will add debugging symbols to 
extension modules as well.    There is a file Misc/valgrind-python.supp 
in the standard Python distribution that is needed to suppress some 
useless Python memory warnings. 

Then you can generate some useful output to the file testmem.pid<num> 
using something like

valgrind --tool=memcheck --leak-check=yes --error-limit=no -v 
--log-file=testmem --suppressions=valgrind-python.supp 
--show-reachable=yes --num-callers=7 python leaktest.py

where leaktest.py is a file that exercises your code: i.e

import scipy
scipy.test(1,10)


Currently, my version of valgrind is issuing an illegal instruction in 
eigenvalue computation when I run scipy.test(10,10) under valgrind.  
That's probably O.K. because it would take a long time to finish anyway.

Everything runs a lot slower under valgrind, but you get some useful 
information when it's done.

Feel free to post questionable items from your valgrind-generated log 
files to this list (be sure they involve the PyArray_<something> or 
PyUFunc_<something> C-API though.  You may get errors from the Python 
C-API too, but we can't fix those if needed here.).





More information about the SciPy-Dev mailing list