File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change 8
8
#include "Python.h"
9
9
#include "posixmodule.h"
10
10
#include "pycore_list.h" // _PyList_AppendTakeRef()
11
+ #include "pycore_object.h" // _PyObject_IsUniquelyReferenced()
11
12
12
13
#include <errno.h> // ERANGE
13
14
#include <grp.h> // getgrgid_r()
@@ -291,13 +292,14 @@ grp_getgrall_impl(PyObject *module)
291
292
setgrent ();
292
293
293
294
struct group * p ;
295
+ // `d` is a local list; append items without a lock using
296
+ // _PyList_AppendTakeRef() within the loop.
297
+ assert (_PyObject_IsUniquelyReferenced (d ));
294
298
while ((p = getgrent ()) != NULL ) {
295
299
// gh-126316: Don't release the mutex around mkgrent() since
296
300
// setgrent()/endgrent() are not reentrant / thread-safe. A deadlock
297
301
// is unlikely since mkgrent() should not be able to call arbitrary
298
302
// Python code.
299
- // `d` is a local list; append to it without a lock using
300
- // _PyList_AppendTakeRef().
301
303
PyObject * v = mkgrent (module , p );
302
304
if (v == NULL
303
305
|| _PyList_AppendTakeRef ((PyListObject * )d , Py_NewRef (v )) != 0 )
You can’t perform that action at this time.
0 commit comments