<br><br><div class="gmail_quote">2008/11/28 Hrvoje Niksic <span dir="ltr">&lt;<a href="mailto:hrvoje.niksic@avl.com">hrvoje.niksic@avl.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
A friend pointed out that running python under valgrind (simply &quot;valgrind python&quot;) produces a lot of &quot;invalid read&quot; errors. &nbsp;Reading up on Misc/README.valgrind only seems to describe why &quot;uninitialized reads&quot; should occur, not invalid ones. &nbsp;For example:<br>

<br>
$ valgrind python<br>
[... lots of output ...]<br>
==31428== Invalid read of size 4<br>
==31428== &nbsp; &nbsp;at 0x808EBDF: PyObject_Free (in /usr/bin/python2.5)<br>
==31428== &nbsp; &nbsp;by 0x810DD0A: (within /usr/bin/python2.5)<br>
==31428== &nbsp; &nbsp;by 0x810DD34: PyNode_Free (in /usr/bin/python2.5)<br>
==31428== &nbsp; &nbsp;by 0x80EDAD9: PyRun_InteractiveOneFlags (in /usr/bin/python2.5)<br>
==31428== &nbsp; &nbsp;by 0x80EDDB7: PyRun_InteractiveLoopFlags (in /usr/bin/python2.5)<br>
==31428== &nbsp; &nbsp;by 0x80EE515: PyRun_AnyFileExFlags (in /usr/bin/python2.5)<br>
==31428== &nbsp; &nbsp;by 0x80595E6: Py_Main (in /usr/bin/python2.5)<br>
==31428== &nbsp; &nbsp;by 0x8058961: main (in /usr/bin/python2.5)<br>
==31428== &nbsp;Address 0x43bf010 is 3,112 bytes inside a block of size 6,016 free&#39;d<br>
==31428== &nbsp; &nbsp;at 0x4024B4A: free (vg_replace_malloc.c:323)<br>
==31428== &nbsp; &nbsp;by 0x8059C07: (within /usr/bin/python2.5)<br>
==31428== &nbsp; &nbsp;by 0x80EDAA5: PyRun_InteractiveOneFlags (in /usr/bin/python2.5)<br>
...<br>
<br>
valgrind claims that Python reads 4 bytes inside a block on which free() has already been called. &nbsp;Is valgrind wrong, or is Python really doing that? &nbsp;Googling revealed previous reports of this, normally answered by a reference to README.valgrind. &nbsp;But README.valgrind justifies reading from ununitialized memory, which doesn&#39;t help me understand how reading from the middle of a block of freed memory (more precisely, memory on which the libc free() has already been called) would be okay.<br>

<br>
I suppose valgrind could be confused by PyFree&#39;s pool address validation that intentionally reads the memory just before the allocated block, and incorrectly attributes it to a previously allocated (and hence freed) block, but I can&#39;t prove that. &nbsp;Has anyone investigated this kind of valgrind report?</blockquote>
<div><br>I can&#39;t answer your question directly, but I can tell you that whenever I have to debug memory problems with python extensions is usually use my own python compiled with --with-pydebug --without-pymalloc.&nbsp; It really helps with valgrind.<br>
</div></div><br>-- <br>Gustavo J. A. M. Carneiro<br>INESC Porto, Telecommunications and Multimedia Unit<br>&quot;The universe is always one step beyond logic.&quot; -- Frank Herbert<br>