diff --git a/Misc/NEWS b/Misc/NEWS index 5b0f81841e7..79d7f0e0b4f 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -108,6 +108,11 @@ Library makeunicodedata.py and regenerated the Unicode database (This fixes u'\u1d79'.lower() == '\x00'). +Extension Modules +----------------- + +- Issue #4873: Fix resource leaks in error cases of pwd and grp. + Build ----- diff --git a/Modules/grpmodule.c b/Modules/grpmodule.c index e5b9f4708c6..ffb451e1744 100644 --- a/Modules/grpmodule.c +++ b/Modules/grpmodule.c @@ -76,7 +76,6 @@ mkgrent(struct group *p) if (PyErr_Occurred()) { Py_DECREF(v); - Py_DECREF(w); return NULL; } @@ -139,6 +138,7 @@ grp_getgrall(PyObject *self, PyObject *ignore) if (v == NULL || PyList_Append(d, v) != 0) { Py_XDECREF(v); Py_DECREF(d); + endgrent(); return NULL; } Py_DECREF(v); diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c index 9e01f487576..a271c5a82eb 100644 --- a/Modules/pwdmodule.c +++ b/Modules/pwdmodule.c @@ -160,6 +160,7 @@ pwd_getpwall(PyObject *self) if (v == NULL || PyList_Append(d, v) != 0) { Py_XDECREF(v); Py_DECREF(d); + endpwent(); return NULL; } Py_DECREF(v);