From: Michael Tremer Date: Tue, 25 Jul 2023 12:57:49 +0000 (+0000) Subject: _pakfire: Consume any exceptions in log callback X-Git-Tag: 0.9.29~83 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=43849e2fd6bb6cfe9b5a32c37c278bbdc6f6147e;p=pakfire.git _pakfire: Consume any exceptions in log callback We cannot do anything with them here, so we need to de-fuse the exception so that we won't run into errors when the originally called Python function returns. Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index 27fe098ed..94ef7ebda 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -62,6 +62,9 @@ static void Pakfire_log_callback(void* data, int priority, const char* file, int const char* fn, const char* format, va_list args) { PyObject* callback = (PyObject*)data; PyObject* exception = NULL; + PyObject* type = NULL; + PyObject* value = NULL; + PyObject* traceback = NULL; // Do nothing if callback isn't set if (!callback) @@ -114,9 +117,17 @@ ERROR: occurred and if so, print it to the console. */ exception = PyErr_Occurred(); - if (exception) + if (exception) { PyErr_Print(); + // Fetch the exception and destroy it + PyErr_Fetch(&type, &value, &traceback); + + Py_XDECREF(type); + Py_XDECREF(value); + Py_XDECREF(traceback); + } + if (buffer) free(buffer); Py_XDECREF(tuple);