1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-09 04:58:16 +03:00

python: Fix memory leak checks

xmlInitParser doesn't allocate memory anymore, so the checks can be
simplified.
This commit is contained in:
Nick Wellnhofer 2022-11-25 18:09:15 +01:00
parent 1966382b34
commit 82bd2c3736

View File

@ -145,23 +145,13 @@ libxml_xmlDebugMemory(PyObject * self ATTRIBUTE_UNUSED, PyObject * args)
if ((freeFunc == xmlMemFree) && (mallocFunc == xmlMemMalloc) &&
(reallocFunc == xmlMemRealloc) &&
(strdupFunc == xmlMemoryStrdup)) {
libxmlMemoryAllocatedBase = xmlMemUsed();
} else {
/*
* cleanup first, because some memory has been
* allocated with the non-debug malloc in xmlInitParser
* when the python module was imported
*/
xmlCleanupParser();
ret = (long) xmlMemSetup(xmlMemFree, xmlMemMalloc,
xmlMemRealloc, xmlMemoryStrdup);
if (ret < 0)
goto error;
libxmlMemoryAllocatedBase = xmlMemUsed();
/* reinitialize */
xmlInitParser();
libxml_xmlErrorInitialize();
}
libxmlMemoryAllocatedBase = xmlMemUsed();
ret = 0;
} else if (libxmlMemoryDebugActivated == 0) {
libxmlMemoryAllocatedBase = xmlMemUsed();
@ -188,13 +178,7 @@ libxml_xmlPythonCleanupParser(PyObject *self ATTRIBUTE_UNUSED,
PyObject *args ATTRIBUTE_UNUSED) {
int ix;
long freed = -1;
if (libxmlMemoryDebug) {
freed = xmlMemUsed();
}
xmlCleanupParser();
/*
* Need to confirm whether we really want to do this (required for
* memcheck) in all cases...
@ -212,12 +196,7 @@ libxml_xmlPythonCleanupParser(PyObject *self ATTRIBUTE_UNUSED,
libxml_xpathCallbacks = NULL;
}
if (libxmlMemoryDebug) {
freed -= xmlMemUsed();
libxmlMemoryAllocatedBase -= freed;
if (libxmlMemoryAllocatedBase < 0)
libxmlMemoryAllocatedBase = 0;
}
xmlCleanupParser();
Py_INCREF(Py_None);
return(Py_None);