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:23:11 2016 +0200 @@ -846,7 +846,7 @@ static int path_converter(PyObject *o, void *p) { path_t *path = (path_t *)p; - PyObject *bytes, *to_cleanup = NULL; + PyObject *bytes = NULL, *to_cleanup = NULL; Py_ssize_t length; int is_index, is_buffer, is_bytes, is_unicode; /* Default to failure, forcing explicit signaling of succcess. */ @@ -1002,7 +1002,6 @@ path_converter(PyObject *o, void *p) 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,14 +1038,15 @@ path_converter(PyObject *o, void *p) path->object = o; path->fd = -1; if (bytes == o) { - Py_DECREF(bytes); ret = 1; } else { path->cleanup = bytes; + bytes = NULL; ret = Py_CLEANUP_SUPPORTED; } exit: + Py_XDECREF(bytes); Py_XDECREF(to_cleanup); return ret; }