[3.12] gh-129346: Handle allocation errors for SQLite aggregate context (GH-129347) (#129373)

(cherry picked from commit 379ab856f5)

Co-authored-by: Erlend E. Aasland <erlend@python.org>
This commit is contained in:
Miss Islington (bot) 2025-01-27 18:33:18 +01:00 committed by GitHub
parent 6073f04b73
commit 23faf5f2dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 0 deletions

View file

@ -0,0 +1,2 @@
In :mod:`sqlite3`, handle out-of-memory when creating user-defined SQL
functions.

View file

@ -927,6 +927,11 @@ step_callback(sqlite3_context *context, int argc, sqlite3_value **params)
assert(ctx != NULL);
aggregate_instance = (PyObject**)sqlite3_aggregate_context(context, sizeof(PyObject*));
if (aggregate_instance == NULL) {
(void)PyErr_NoMemory();
set_sqlite_error(context, "unable to allocate SQLite aggregate context");
goto error;
}
if (*aggregate_instance == NULL) {
*aggregate_instance = PyObject_CallNoArgs(ctx->callable);
if (!*aggregate_instance) {