From 673d7e3259ce178b3b2e3228221887af026a6e78 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 29 Jun 2019 12:42:36 +0200 Subject: [PATCH 1/1] [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. --- python/ext/py-filter.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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; } -- 2.11.0