| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Unfortunately due to optimised build of Python3 libraries and executable I got only partial stack from [http://clang.llvm.org/docs/AddressSanitizer.html], however digging into and reducing my code I tracked it down to be issue with `boost/libs/python/src/object/enum.cpp`. It has to bits that leak (and comment mentioning there is one): PyObject *mod = PyObject_GetAttrString( self_, "__module__"); Leaks reference, as it never decreases it. It also stores a new string object under object's `name` that ref count never gets decremented. That commit fixes both issues.
When exception gets set we need to return NULL in Python3 as module pointer.
Code in `Python/importdl.c` explicitly checks for this and suppresses exception (so you lose any knowledge of what went wrong):
PyObject *
_PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
{
[...]
m = p0();
_Py_PackageContext = oldcontext;
if (m == NULL) {
if (!PyErr_Occurred()) {
PyErr_Format(
PyExc_SystemError,
"initialization of %s failed without raising an exception",
name_buf);
}
goto error;
} else if (PyErr_Occurred()) {
PyErr_Clear();
PyErr_Format(
PyExc_SystemError,
"initialization of %s raised unreported exception",
name_buf);
m = NULL;
goto error;
}
In above the first case propagates actually raised exception, but only if we returned NULL.
Otherwise it overrides it with very unhelpful message of "unreported exception".
Fix is to simply return NULL if we got exception raised inside `init_function`.
Handling of that case follows what I could find in `Modules/symtablemodule.c` bundled with Python:
PyMODINIT_FUNC
PyInit__symtable(void)
{
PyObject *m;
[...]
if (PyErr_Occurred()) {
Py_DECREF(m);
m = 0;
}
return m;
}
So it checks if exception was raised, and if so it frees module and returns NULL.
`__cxa_demangle` returns a new pointer that needs to be freed. As much as this is only a minor leak (tenths of bytes per each unique symbol that got resolved) it makes automated memory leak checking tools quite upset. This simply adds a helper that frees memory for names we've kept. Also, removed a lot of trailing whitespace.
| Back | FazBrowse Home | New Git URL |
Two fixes: