File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change 1+ Fix libc thread safety issues with :mod: `pwd ` by locking access to
2+ ``getpwall ``.
Original file line number Diff line number Diff line change @@ -301,18 +301,28 @@ pwd_getpwall_impl(PyObject *module)
301301 struct passwd * p ;
302302 if ((d = PyList_New (0 )) == NULL )
303303 return NULL ;
304+
305+ #ifdef Py_GIL_DISABLED
306+ static PyMutex getpwall_mutex = {0 };
307+ PyMutex_Lock (& getpwall_mutex );
308+ #endif
304309 setpwent ();
310+
305311 while ((p = getpwent ()) != NULL ) {
306312 PyObject * v = mkpwent (module , p );
307313 if (v == NULL || PyList_Append (d , v ) != 0 ) {
308314 Py_XDECREF (v );
309- Py_DECREF (d );
310- endpwent ();
311- return NULL ;
315+ Py_CLEAR (d );
316+ goto done ;
312317 }
313318 Py_DECREF (v );
314319 }
320+
321+ done :
315322 endpwent ();
323+ #ifdef Py_GIL_DISABLED
324+ PyMutex_Unlock (& getpwall_mutex );
325+ #endif
316326 return d ;
317327}
318328#endif
You can’t perform that action at this time.
0 commit comments