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

This commit is contained in:
Shamil 2025-10-18 12:27:58 +03:00 committed by GitHub
parent 1bfe86caaa
commit f937468e7c
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

@ -673,8 +673,10 @@ _gdbm_gdbm_clear_impl(gdbmobject *self, PyTypeObject *cls)
} }
if (gdbm_delete(self->di_dbm, key) < 0) { if (gdbm_delete(self->di_dbm, key) < 0) {
PyErr_SetString(state->gdbm_error, "cannot delete item from database"); PyErr_SetString(state->gdbm_error, "cannot delete item from database");
free(key.dptr);
return NULL; return NULL;
} }
free(key.dptr);
} }
Py_RETURN_NONE; Py_RETURN_NONE;
} }