diff options
author | drh <> | 2022-01-24 12:48:54 +0000 |
---|---|---|
committer | drh <> | 2022-01-24 12:48:54 +0000 |
commit | 3cdb1394b936cbf139d441628de7533efa895cc3 (patch) | |
tree | 12f106e4791fbf055f279d9367dd1f189f2c2132 /src | |
parent | f5bc44407701b4143519ecb32a547ca2f3b169ff (diff) | |
download | sqlite-3cdb1394b936cbf139d441628de7533efa895cc3.tar.gz sqlite-3cdb1394b936cbf139d441628de7533efa895cc3.zip |
Make sure the sqlite3OomFault() routine sets an error in the Parse object
if there is a Parse object active and linked to the database connection.
FossilOrigin-Name: ad7aace761c6b21ba453eaf43c68d985be7cbd5a200fe0d2e27a0c7150f99874
Diffstat (limited to 'src')
-rw-r--r-- | src/build.c | 2 | ||||
-rw-r--r-- | src/malloc.c | 11 | ||||
-rw-r--r-- | src/select.c | 2 | ||||
-rw-r--r-- | src/sqliteInt.h | 2 |
4 files changed, 13 insertions, 4 deletions
diff --git a/src/build.c b/src/build.c index ce1c72080..af6ee4e77 100644 --- a/src/build.c +++ b/src/build.c @@ -4544,10 +4544,10 @@ void sqlite3DropIndex(Parse *pParse, SrcList *pName, int ifExists){ sqlite3 *db = pParse->db; int iDb; - assert( pParse->nErr==0 ); /* Never called with prior errors */ if( db->mallocFailed ){ goto exit_drop_index; } + assert( pParse->nErr==0 ); /* Never called with prior non-OOM errors */ assert( pName->nSrc==1 ); if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){ goto exit_drop_index; diff --git a/src/malloc.c b/src/malloc.c index 932cecc21..21e524589 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -759,8 +759,15 @@ void sqlite3SetString(char **pz, sqlite3 *db, const char *zNew){ ** has happened. This routine will set db->mallocFailed, and also ** temporarily disable the lookaside memory allocator and interrupt ** any running VDBEs. +** +** Always return a NULL pointer so that this routine can be invoked using +** +** return sqlite3OomFault(db); +** +** and thereby avoid unnecessary stack frame allocations for the overwhelmingly +** common case where no OOM occurs. */ -void sqlite3OomFault(sqlite3 *db){ +void *sqlite3OomFault(sqlite3 *db){ if( db->mallocFailed==0 && db->bBenignMalloc==0 ){ db->mallocFailed = 1; if( db->nVdbeExec>0 ){ @@ -768,9 +775,11 @@ void sqlite3OomFault(sqlite3 *db){ } DisableLookaside; if( db->pParse ){ + sqlite3ErrorMsg(db->pParse, "out of memory"); db->pParse->rc = SQLITE_NOMEM_BKPT; } } + return 0; } /* diff --git a/src/select.c b/src/select.c index a0fc3d90f..da3c78009 100644 --- a/src/select.c +++ b/src/select.c @@ -1404,7 +1404,7 @@ KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){ p->nRef = 1; memset(&p[1], 0, nExtra); }else{ - sqlite3OomFault(db); + return (KeyInfo*)sqlite3OomFault(db); } return p; } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index a2724f582..7fd0d81d0 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4975,7 +4975,7 @@ int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, FuncDestructor *pDestructor ); void sqlite3NoopDestructor(void*); -void sqlite3OomFault(sqlite3*); +void *sqlite3OomFault(sqlite3*); void sqlite3OomClear(sqlite3*); int sqlite3ApiExit(sqlite3 *db, int); int sqlite3OpenTempDatabase(Parse *); |