From: Paul Brossier Date: Sat, 29 Jun 2019 10:42:36 +0000 (+0200) Subject: [py] fix reference counting of exception types (thanks @wackou) X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=673d7e3259ce178b3b2e3228221887af026a6e78;p=aubio.git [py] fix reference counting of exception types (thanks @wackou) Commit 8bfef30 exposed a reference counting error, causing the interpreter to crash before exiting. The solution is to incref the exception type before calling PyErr_Restore. --- diff --git a/python/ext/py-filter.c b/python/ext/py-filter.c index 19dcc600..220eb139 100644 --- a/python/ext/py-filter.c +++ b/python/ext/py-filter.c @@ -163,7 +163,10 @@ Py_filter_set_c_weighting (Py_filter * self, PyObject *args) // change the RuntimeError into ValueError PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); - PyErr_Restore(PyExc_ValueError, value, traceback); + Py_XDECREF(type); + type = PyExc_ValueError; + Py_XINCREF(type); + PyErr_Restore(type, value, traceback); } return NULL; } @@ -188,7 +191,10 @@ Py_filter_set_a_weighting (Py_filter * self, PyObject *args) // change the RuntimeError into ValueError PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); - PyErr_Restore(PyExc_ValueError, value, traceback); + Py_XDECREF(type); + type = PyExc_ValueError; + Py_XINCREF(type); + PyErr_Restore(type, value, traceback); } return NULL; } @@ -213,7 +219,10 @@ Py_filter_set_biquad(Py_filter * self, PyObject *args) // change the RuntimeError into ValueError PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); - PyErr_Restore(PyExc_ValueError, value, traceback); + Py_XDECREF(type); + type = PyExc_ValueError; + Py_XINCREF(type); + PyErr_Restore(type, value, traceback); } return NULL; }