[capi-sig] Fix random crashes - embedding py/w PyObject pointers to app data.

Campbell Barton ideasman42 at gmail.com
Wed Oct 22 05:34:17 CEST 2008


Hi, just spent a couple of hours looking into a bug that others might also have.
If your app embeds python, and allows scripts to throw exceptions
while the application keeps running you may also have this problem.

sys.last_traceback will store the last exception along with the
namespace dictionary of the script that just ran (with all its
functions etc, variables etc).

In our case this caused crashes because you could load in new data,
making many of the PyObjects referenced from sys.last_traceback, point
to invalid data. Once sys.last_traceback was set again it would free
the existing data sometimes touching pointers with invalid addresses
causing a segfault.

Simple solution is to run this after PyErr_Print();

 PySys_SetObject( "last_traceback", Py_None);

This can also free memory, if large datasets are references from the
traceback. maybe some of your would fine this useful.

-- 
- Campbell


More information about the capi-sig mailing list