diff --git a/src/_path_wrapper.cpp b/src/_path_wrapper.cpp index 2fd90adb97f5..ab8c46c107e3 100644 --- a/src/_path_wrapper.cpp +++ b/src/_path_wrapper.cpp @@ -727,6 +727,7 @@ static PyObject *Py_convert_to_string(PyObject *self, PyObject *args, PyObject * return NULL; } codes[i] = PyBytes_AsString(item); + Py_DECREF(item); if (codes[i] == NULL) { return NULL; } diff --git a/src/py_adaptors.h b/src/py_adaptors.h index d5714db2d8bf..bb11276ebee1 100644 --- a/src/py_adaptors.h +++ b/src/py_adaptors.h @@ -240,6 +240,7 @@ class PathGenerator throw py::exception(); } if (!convert_path(item, &path)) { + Py_DECREF(item); throw py::exception(); } Py_DECREF(item);