Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Once the newly created pwent items are successfully added to the list…
… they are

strongly referenced by that, so we can dec-ref them safely.
  • Loading branch information
duaneg committed May 21, 2025
commit 7ca685875c45c680c1bff3d07541ca0e12b4d508
16 changes: 5 additions & 11 deletions Modules/pwdmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,31 +308,25 @@ pwd_getpwall_impl(PyObject *module)
PyMutex_Lock(&getpwall_mutex);
#endif
int failure = 0;
PyObject *orphan = NULL;
PyObject *v = NULL;
setpwent();
while ((p = getpwent()) != NULL) {
/* NOTE: Ref counts are not decremented here, as we cannot allow
* re-entrancy while holding the mutex. */
PyObject *v = mkpwent(module, p);
v = mkpwent(module, p);
if (v == NULL || PyList_Append(d, v) != 0) {
orphan = v;
/* NOTE: cannot dec-ref here, while holding the mutex. */
failure = 1;
goto done;
}
Py_DECREF(v);
}

done:
endpwent();
#ifdef Py_GIL_DISABLED
PyMutex_Unlock(&getpwall_mutex);
#endif
/* Deferred decref on entries created above and added to the list. */
Py_ssize_t n = PyList_Size(d);
while (--n >= 0) {
Py_DECREF(PyList_GetItem(d, n));
}
if (failure) {
Py_XDECREF(orphan);
Py_XDECREF(v);
Py_CLEAR(d);
}
return d;
Expand Down
Loading