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

(cherry picked from commit f937468e7c)

Co-authored-by: Shamil <ashm.tech@proton.me>
This commit is contained in:
Miss Islington (bot) 2025-10-18 12:17:42 +02:00 committed by GitHub
parent f59236b746
commit 128f48fd2d
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

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