shithub: aubio

Download patch

ref: 673d7e3259ce178b3b2e3228221887af026a6e78
parent: 841ceede7d6094d043eb988ce8948bc2ef6d9475
author: Paul Brossier <piem@piem.org>
date: Sat Jun 29 08:42:36 EDT 2019

[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.

--- a/python/ext/py-filter.c
+++ b/python/ext/py-filter.c
@@ -163,7 +163,10 @@
       // 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 @@
       // 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 @@
       // 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;
   }