Issue #4873: Fix resource leaks in error cases of pwd and grp.
diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c
index 9e01f48..a271c5a 100644
--- a/Modules/pwdmodule.c
+++ b/Modules/pwdmodule.c
@@ -160,6 +160,7 @@
 		if (v == NULL || PyList_Append(d, v) != 0) {
 			Py_XDECREF(v);
 			Py_DECREF(d);
+			endpwent();
 			return NULL;
 		}
 		Py_DECREF(v);