]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-116738: Add critical section to dbm/gdbm context manager (gh-140391) (gh...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 22 Oct 2025 15:44:09 +0000 (17:44 +0200)
committerGitHub <noreply@github.com>
Wed, 22 Oct 2025 15:44:09 +0000 (15:44 +0000)
(cherry picked from commit d51be28876ac0715b6fc674ef41618d214021348)

Co-authored-by: Alper <alperyoney@fb.com>
Modules/_dbmmodule.c
Modules/_gdbmmodule.c

index 0cd0f043de453d66cd67d1d93f784bcab9600b09..c393cde21f5491239a8a6dc89398e790bd5359d0 100644 (file)
@@ -523,8 +523,12 @@ dbm__enter__(PyObject *self, PyObject *Py_UNUSED(dummy))
 static PyObject *
 dbm__exit__(PyObject *self, PyObject *Py_UNUSED(args))
 {
+    PyObject *result;
     dbmobject *dp = dbmobject_CAST(self);
-    return _dbm_dbm_close_impl(dp);
+    Py_BEGIN_CRITICAL_SECTION(self);
+    result = _dbm_dbm_close_impl(dp);
+    Py_END_CRITICAL_SECTION();
+    return result;
 }
 
 static PyMethodDef dbm_methods[] = {
index ce8696d9225e728136f56a7a4d085ca69960cafc..d9abab197197897bd2da95d397287ed7a0364120 100644 (file)
@@ -695,7 +695,11 @@ gdbm__enter__(PyObject *self, PyObject *args)
 static PyObject *
 gdbm__exit__(PyObject *self, PyObject *args)
 {
-    return _gdbm_gdbm_close_impl((gdbmobject *)self);
+    PyObject *result;
+    Py_BEGIN_CRITICAL_SECTION(self);
+    result = _gdbm_gdbm_close_impl((gdbmobject *)self);
+    Py_END_CRITICAL_SECTION();
+    return result;
 }
 
 static PyMethodDef gdbm_methods[] = {