Memory leak in TableIO?
Mark Fardal
fardal at corvus.phys.uvic.ca
Tue Jan 14 21:36:44 EST 2003
sjmachin at lexicon.net (John Machin) writes:
> At first glance, there are several instances of
>
> status = PyList_Append( myList, PyFloat_FromDouble(atof(string)) );
>
> This needs to be changed to
>
> tmp_obj = PyFloat_FromDouble(atof(string)) );
> status = PyList_Append( myList, tmp_obj );
> Py_DECREF(tmp_obj);
I wondered about that...but thought perhaps the PyList_Append
decremented the object by itself.
> There may well be other leaks, there may well be other problems, but
> plugging the above leak of one Python float object per table element
> should get you a lot further ...
Yes indeed. Do some of the calls to Py_BuildValue also leak memory?
How about PyArg_ParseTuple? PyArg_Parse? But if so, those are still just
memory leaks. You pointed out a memory gush.
> You will notice that there is no error checking on the result of the
> PyFloat_FromDouble() call, presumably because atof() is expected to
> return a legal double even if the input string is not a valid
> representation of a floating-point number [see example below], and so
> the presumption is that PyFloat_FromDouble() cannot fail. However
> given your opening remark that you use this module "since it's very
> fast", this may not be a concern to you :-)
Well, not at the moment, since I know what is in my data files. :->
But good you pointed it out. Is a PyFloat the same thing as a C double,
by the way? Or is it machine dependent?
thanks much,
Mark
More information about the Python-list
mailing list