1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-09 14:21:03 +03:00

Fix to sqlite3DbMallocRaw() when SQLITE_OMIT_LOOKASIDE is defined so that

once it fails it continues to fail.  Add a comment explaining why this is
important. (CVS 5804)

FossilOrigin-Name: 63dd8be70d333c56171dfd254406abb1af685b0f
This commit is contained in:
drh
2008-10-11 17:35:16 +00:00
parent 8867e38aab
commit ddecae7995
4 changed files with 29 additions and 13 deletions

View File

@@ -12,7 +12,7 @@
**
** Memory allocation functions used throughout sqlite.
**
** $Id: malloc.c,v 1.43 2008/10/11 15:38:30 drh Exp $
** $Id: malloc.c,v 1.44 2008/10/11 17:35:16 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@@ -618,6 +618,20 @@ void *sqlite3DbMallocZero(sqlite3 *db, int n){
/*
** Allocate and zero memory. If the allocation fails, make
** the mallocFailed flag in the connection pointer.
**
** If db!=0 and db->mallocFailed is true (indicating a prior malloc
** failure on the same database connection) then always return 0.
** Hence for a particular database connection, once malloc starts
** failing, it fails consistently until mallocFailed is reset.
** This is an important assumption. There are many places in the
** code that do things like this:
**
** int *a = (int*)sqlite3DbMallocRaw(db, 100);
** int *b = (int*)sqlite3DbMallocRaw(db, 200);
** if( b ) a[10] = 9;
**
** In other words, if a subsequent malloc (ex: "b") worked, it is assumed
** that all prior mallocs (ex: "a") worked too.
*/
void *sqlite3DbMallocRaw(sqlite3 *db, int n){
void *p;
@@ -637,6 +651,10 @@ void *sqlite3DbMallocRaw(sqlite3 *db, int n){
return (void*)pBuf;
}
}
#else
if( db && db->mallocFailed ){
return 0;
}
#endif
p = sqlite3Malloc(n);
if( !p && db ){