Skip to content

Commit 8db076c

Browse files
committed
Issue #10363: Deallocate global locks in Py_Finalize().
1 parent e0aa803 commit 8db076c

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

Misc/NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ What's New in Python 3.2.3?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #10363: Deallocate global locks in Py_Finalize().
14+
1315
- Issue #13018: Fix reference leaks in error paths in dictobject.c.
1416
Patch by Suman Saha.
1517

Python/import.c

+15-10
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,6 @@ _PyImportHooks_Init(void)
252252
Py_DECREF(path_hooks);
253253
}
254254

255-
void
256-
_PyImport_Fini(void)
257-
{
258-
Py_XDECREF(extensions);
259-
extensions = NULL;
260-
PyMem_DEL(_PyImport_Filetab);
261-
_PyImport_Filetab = NULL;
262-
}
263-
264-
265255
/* Locking primitives to prevent parallel imports of the same module
266256
in different threads to return with a partially loaded module.
267257
These calls are serialized by the global interpreter lock. */
@@ -374,6 +364,21 @@ imp_release_lock(PyObject *self, PyObject *noargs)
374364
return Py_None;
375365
}
376366

367+
void
368+
_PyImport_Fini(void)
369+
{
370+
Py_XDECREF(extensions);
371+
extensions = NULL;
372+
PyMem_DEL(_PyImport_Filetab);
373+
_PyImport_Filetab = NULL;
374+
#ifdef WITH_THREAD
375+
if (import_lock != NULL) {
376+
PyThread_free_lock(import_lock);
377+
import_lock = NULL;
378+
}
379+
#endif
380+
}
381+
377382
static void
378383
imp_modules_reloading_clear(void)
379384
{

Python/pystate.c

+6
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ PyInterpreterState_Delete(PyInterpreterState *interp)
150150
*p = interp->next;
151151
HEAD_UNLOCK();
152152
free(interp);
153+
#ifdef WITH_THREAD
154+
if (interp_head == NULL && head_mutex != NULL) {
155+
PyThread_free_lock(head_mutex);
156+
head_mutex = NULL;
157+
}
158+
#endif
153159
}
154160

155161

0 commit comments

Comments
 (0)