Mercurial > hgrepos > Python > libs > ConfigMix
diff configmix/_py_helper.h @ 562:f75c5b13a1d7
FIX: Memory-leak
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 06 Jan 2022 20:13:10 +0100 |
| parents | 81238ea2dbe3 |
| children | 2c211934d4b0 |
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;
