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

(cherry picked from commit f937468e7c)

Co-authored-by: Shamil <ashm.tech@proton.me>
This commit is contained in:
Serhiy Storchaka 2025-10-18 14:00:10 +03:00 committed by GitHub
parent 0760a572f7
commit 0231a391f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 0 deletions

View file

@ -0,0 +1 @@
Fix memory leak in the :meth:`!clear` method of the :mod:`dbm.gnu` database.

View file

@ -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;
}