[Python-Dev] FW: static analysis of python source

Josiah Carlson jcarlson at uci.edu
Fri Apr 20 17:59:55 CEST 2007


Kristján Valur Jónsson <kristjan at ccpgames.com> wrote:
> 
> I just ran some static analysis of the python core 2.5 with Visual Studio team system.
> There was the stray error discovered.  I will update the most obvious ones.
[snip]
> 2)  There is a lot of code that goes like this:
> f->buf = PyMem_Realloc(f->buf, newsize);
> if (!f->buf)
>     return PyErr_NoMemory(), 0;
> Now,  this if Realloc fails, this causes a memory leak.  Is there any
>  interest to fix this flawed pattern wholesale?

I believe the idea is that if you run into a MemoryError, in particular
on linux (whose allocator will give you a nonzero pointer well beyond
what was actually available), you can't really trust the state of the
interpreter, so it is expected that Python will be ending shortly. 
Forcing the leak (leaving the code as-is) basically encourages the
interpreter to have more and more errors before the expected, possibly
inevitable (and perhaps desireable) quitting of the Python interpreter.


 - Josiah



More information about the Python-Dev mailing list