diff -r 6ced540a92bc Modules/posixmodule.c --- a/Modules/posixmodule.c Wed Dec 21 14:08:55 2016 +0200 +++ b/Modules/posixmodule.c Wed Dec 21 17:06:24 2016 +0200 @@ -998,11 +998,13 @@ path_converter(PyObject *o, void *p) goto exit; } + Py_XDECREF(to_cleanup); + to_cleanup = bytes; + length = PyBytes_GET_SIZE(bytes); narrow = PyBytes_AS_STRING(bytes); if ((size_t)length != strlen(narrow)) { FORMAT_EXCEPTION(PyExc_ValueError, "embedded null character in %s"); - Py_DECREF(bytes); goto exit; } @@ -1039,10 +1041,10 @@ path_converter(PyObject *o, void *p) path->object = o; path->fd = -1; if (bytes == o) { - Py_DECREF(bytes); ret = 1; } else { + to_cleanup = NULL; path->cleanup = bytes; ret = Py_CLEANUP_SUPPORTED; }