]> git.ipfire.org Git - pakfire.git/commitdiff
_pakfire: Consume any exceptions in log callback
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 Jul 2023 12:57:49 +0000 (12:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 Jul 2023 12:59:11 +0000 (12:59 +0000)
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 <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c

index 27fe098ed7eb96241c221f0d41d5535639c817cc..94ef7ebdac174937c0554e21039f9ae5bf1d422b 100644 (file)
@@ -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);