changeset 562:f75c5b13a1d7

FIX: Memory-leak
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 06 Jan 2022 20:13:10 +0100
parents c51f484387ee
children 2c211934d4b0
files configmix/_py_helper.h configmix/_speedups.c
diffstat 2 files changed, 48 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/configmix/_py_helper.h	Thu Jan 06 20:03:01 2022 +0100
+++ b/configmix/_py_helper.h	Thu Jan 06 20:13:10 2022 +0100
@@ -102,12 +102,26 @@
 
 /*
  * Transfer from a borrowed reference to an owned one and clear the source.
- * Also safely clear the destination before.
+ * Also clear the destination before.
  */
 static inline
 void
 py_transfer_borrowed(PyObject **dest, PyObject **src)
 {
+    Py_DECREF(*dest);
+    *dest = Py_NewRef(*src);
+    *src = NULL;
+}
+
+
+/*
+ * Transfer from a borrowed reference to an owned one and clear the source.
+ * Also safely clear the destination before.
+ */
+static inline
+void
+py_x_transfer_borrowed(PyObject **dest, PyObject **src)
+{
     Py_XDECREF(*dest);
     *dest = Py_NewRef(*src);
     *src = NULL;
@@ -116,11 +130,25 @@
 
 /*
  * Transfer from a borrowed reference to an owned one and clear the source.
+ * Also clear the destination before. The source object may be NULL.
+ */
+static inline
+void
+py_transfer_x_borrowed(PyObject **dest, PyObject **src)
+{
+    Py_DECREF(*dest);
+    *dest = Py_XNewRef(*src);
+    *src = NULL;
+}
+
+
+/*
+ * Transfer from a borrowed reference to an owned one and clear the source.
  * Also safely clear the destination before. The source object may be NULL.
  */
 static inline
 void
-py_transfer_x_borrowed(PyObject **dest, PyObject **src)
+py_x_transfer_x_borrowed(PyObject **dest, PyObject **src)
 {
     Py_XDECREF(*dest);
     *dest = Py_XNewRef(*src);
@@ -131,11 +159,26 @@
 /*
  * Transfer ownership from a owned reference to an owned one and clear the
  * source.
+ * Also clear the destination before.
+ */
+static inline
+void
+py_transfer_owned(PyObject **dest, PyObject **src)
+{
+    Py_DECREF(*dest);
+    *dest = *src;
+    *src = NULL;
+}
+
+
+/*
+ * Transfer ownership from a owned reference to an owned one and clear the
+ * source.
  * Also safely clear the destination before.
  */
 static inline
 void
-py_transfer_owned(PyObject **dest, PyObject **src)
+py_x_transfer_owned(PyObject **dest, PyObject **src)
 {
     Py_XDECREF(*dest);
     *dest = *src;
--- a/configmix/_speedups.c	Thu Jan 06 20:03:01 2022 +0100
+++ b/configmix/_speedups.c	Thu Jan 06 20:13:10 2022 +0100
@@ -818,6 +818,7 @@
             py_clear_ref(&tmp);
             goto error;
         }
+        py_clear_ref(&varname);
         /* Unpack the result tuple */
         /* borrowed -- cannot fail -- need ownership */
         varname = Py_NewRef(PyTuple_GetItem(tmp, 0));
@@ -1041,6 +1042,7 @@
             py_clear_ref(&tmp);
             goto error;
         }
+        py_clear_ref(&varname);
         /* Unpack the result tuple */
         /* borrowed -- cannot fail -- need ownership */
         varname = Py_NewRef(PyTuple_GetItem(tmp, 0));