Fix multiple mem leaks, refactor and improve memory management #10

Manually merged
jabber.developer merged 4 commits from ref/scrolling into master 2025-07-02 18:48:51 +00:00
8 changed files with 41 additions and 24 deletions
Showing only changes of commit 6871a4d46f - Show all commits

View File

@@ -900,6 +900,8 @@ _python_type_error(ProfPlugin* plugin, char* hook, char* type)
g_string_free(err_msg, TRUE);
}
// Converts a Python string or None result to a C string and decreases the Python object's reference count.
// If the result is NULL, or not a string/unicode/bytes/None, logs an error and returns NULL.
static char*
_handle_string_or_none_result(ProfPlugin* plugin, PyObject* result, char* hook)
{
@@ -910,18 +912,16 @@ _handle_string_or_none_result(ProfPlugin* plugin, PyObject* result, char* hook)
}
#ifdef PY_IS_PYTHON3
if (result != Py_None && !PyUnicode_Check(result) && !PyBytes_Check(result)) {
allow_python_threads();
_python_type_error(plugin, hook, "string, unicode or None");
return NULL;
}
#else
if (result != Py_None && !PyUnicode_Check(result) && !PyString_Check(result)) {
#endif
Py_XDECREF(result);
allow_python_threads();
_python_type_error(plugin, hook, "string, unicode or None");
return NULL;
}
#endif
char* result_str = python_str_or_unicode_to_string(result);
Py_XDECREF(result);
allow_python_threads();
return result_str;
}