https://github.com/python/cpython/commit/0231a391f913e7cd19b0ee82802c99104472411e
commit: 0231a391f913e7cd19b0ee82802c99104472411e
branch: 3.13
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2025-10-18T11:00:10Z
summary:

[3.13] gh-140272: Fix memory leak in _gdbm.gdbm.clear() (GH-140274) (GH-140289)

(cherry picked from commit f937468e7c88c768a28ff4e653da051ffa30d86c)

Co-authored-by: Shamil <[email protected]>

files:
A Misc/NEWS.d/next/Library/2025-10-17-23-58-11.gh-issue-140272.lhY8uS.rst
M Modules/_gdbmmodule.c

diff --git 
a/Misc/NEWS.d/next/Library/2025-10-17-23-58-11.gh-issue-140272.lhY8uS.rst 
b/Misc/NEWS.d/next/Library/2025-10-17-23-58-11.gh-issue-140272.lhY8uS.rst
new file mode 100644
index 00000000000000..666a45055f5a58
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-10-17-23-58-11.gh-issue-140272.lhY8uS.rst
@@ -0,0 +1 @@
+Fix memory leak in the :meth:`!clear` method of the :mod:`dbm.gnu` database.
diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c
index ea4fe247987e9d..3fe08004790912 100644
--- a/Modules/_gdbmmodule.c
+++ b/Modules/_gdbmmodule.c
@@ -612,8 +612,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;
 }

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to