]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-140272: Fix memory leak in _gdbm.gdbm.clear() (GH-140274)
authorShamil <ashm.tech@proton.me>
Sat, 18 Oct 2025 09:27:58 +0000 (12:27 +0300)
committerGitHub <noreply@github.com>
Sat, 18 Oct 2025 09:27:58 +0000 (09:27 +0000)
Misc/NEWS.d/next/Core_and_Builtins/2025-10-17-23-58-11.gh-issue-140272.lhY8uS.rst [new file with mode: 0644]
Modules/_gdbmmodule.c

diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-10-17-23-58-11.gh-issue-140272.lhY8uS.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-10-17-23-58-11.gh-issue-140272.lhY8uS.rst
new file mode 100644 (file)
index 0000000..666a450
--- /dev/null
@@ -0,0 +1 @@
+Fix memory leak in the :meth:`!clear` method of the :mod:`dbm.gnu` database.
index 87b84976f49d61a10e8110837513fb94db54b606..a6e0662ae743e9af18a55fa798fe634d0118bdfe 100644 (file)
@@ -673,8 +673,10 @@ _gdbm_gdbm_clear_impl(gdbmobject *self, PyTypeObject *cls)
         }
         if (gdbm_delete(self->di_dbm, key) < 0) {
             PyErr_SetString(state->gdbm_error, "cannot delete item from database");
+            free(key.dptr);
             return NULL;
         }
+        free(key.dptr);
     }
     Py_RETURN_NONE;
 }