# HG changeset patch # User Franz Glasner # Date 1641496390 -3600 # Node ID f75c5b13a1d707e8b63a15a0b8228ecbdc7b7fb5 # Parent c51f484387ee77118d6bb0857276743bb54a99f2 FIX: Memory-leak diff -r c51f484387ee -r f75c5b13a1d7 configmix/_py_helper.h --- 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; diff -r c51f484387ee -r f75c5b13a1d7 configmix/_speedups.c --- 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));