gh-129346: Handle allocation errors for SQLite aggregate context (#129347)

This commit is contained in:
Erlend E. Aasland 2025-01-27 18:16:19 +01:00 committed by GitHub
parent a6a8c6f86e
commit 379ab856f5
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

@ -958,6 +958,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) {