From ea78cfa099c330dce18d50c0a9df3b4477904ecb Mon Sep 17 00:00:00 2001 From: Shamil Abdulaev Date: Fri, 17 Oct 2025 23:58:40 +0300 Subject: [PATCH 1/4] gh-140272: Fix memory leak in _gdbm.gdbm.clear() --- .../2025-10-17-23-58-11.gh-issue-140272.lhY8uS.rst | 2 ++ Modules/_gdbmmodule.c | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-10-17-23-58-11.gh-issue-140272.lhY8uS.rst 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 index 00000000000000..4f4af5b8b52bac --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-10-17-23-58-11.gh-issue-140272.lhY8uS.rst @@ -0,0 +1,2 @@ +Fix memory leak in :meth:`_gdbm.gdbm.clear` by properly freeing memory +allocated by ``gdbm_firstkey()``. diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c index 87b84976f49d61..a6e0662ae743e9 100644 --- a/Modules/_gdbmmodule.c +++ b/Modules/_gdbmmodule.c @@ -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; } From 65f45d6c24d1eec8385198e64c0f08e94678ac81 Mon Sep 17 00:00:00 2001 From: Shamil Abdulaev Date: Sat, 18 Oct 2025 00:20:42 +0300 Subject: [PATCH 2/4] fix --- .../2025-10-17-23-58-11.gh-issue-140272.lhY8uS.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 index 4f4af5b8b52bac..a33a396a2282c6 100644 --- 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 @@ -1,2 +1 @@ -Fix memory leak in :meth:`_gdbm.gdbm.clear` by properly freeing memory -allocated by ``gdbm_firstkey()``. +Fix memory leak in ``_gdbm.gdbm.clear`` by properly freeing memory allocated by ``gdbm_firstkey()``. From 13f9a8211bb91150d567b179718395135fbf1547 Mon Sep 17 00:00:00 2001 From: Shamil Date: Sat, 18 Oct 2025 11:56:04 +0300 Subject: [PATCH 3/4] Update Misc/NEWS.d/next/Core_and_Builtins/2025-10-17-23-58-11.gh-issue-140272.lhY8uS.rst Co-authored-by: Serhiy Storchaka --- .../2025-10-17-23-58-11.gh-issue-140272.lhY8uS.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index a33a396a2282c6..a8fb670fcf5dbd 100644 --- 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 @@ -1 +1 @@ -Fix memory leak in ``_gdbm.gdbm.clear`` by properly freeing memory allocated by ``gdbm_firstkey()``. +Fix memory leak in the :meth:`clear` method of the :mod:`dbm.gnu` database. From c5575c05a92d463f048ca64f052a7a80026bc611 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 18 Oct 2025 12:00:12 +0300 Subject: [PATCH 4/4] Update 2025-10-17-23-58-11.gh-issue-140272.lhY8uS.rst --- .../2025-10-17-23-58-11.gh-issue-140272.lhY8uS.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index a8fb670fcf5dbd..666a45055f5a58 100644 --- 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 @@ -1 +1 @@ -Fix memory leak in the :meth:`clear` method of the :mod:`dbm.gnu` database. +Fix memory leak in the :meth:`!clear` method of the :mod:`dbm.gnu` database.