]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-140272: Fix memory leak in _gdbm.gdbm.clear() (GH-140274) (GH-140285)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 18 Oct 2025 10:17:42 +0000 (12:17 +0200)
committerGitHub <noreply@github.com>
Sat, 18 Oct 2025 10:17:42 +0000 (13:17 +0300)
(cherry picked from commit f937468e7c88c768a28ff4e653da051ffa30d86c)

Co-authored-by: Shamil <ashm.tech@proton.me>
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 9c402e20e513b939d00edc1782130da85dfd3157..ce8696d9225e728136f56a7a4d085ca69960cafc 100644 (file)
@@ -678,8 +678,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;
 }