aboutsummaryrefslogtreecommitdiff
path: root/src/malloc.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2008-10-11 17:35:16 +0000
committerdrh <drh@noemail.net>2008-10-11 17:35:16 +0000
commitddecae799582987b8303d0062324eb169b40275e (patch)
treead7c3d1c6778fe8a1fe7b9dfc913b9589fa833ea /src/malloc.c
parent8867e38aab61b567d6ce671b2d2e04b5f03c27d2 (diff)
downloadsqlite-ddecae799582987b8303d0062324eb169b40275e.tar.gz
sqlite-ddecae799582987b8303d0062324eb169b40275e.zip
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
Diffstat (limited to 'src/malloc.c')
-rw-r--r--src/malloc.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/malloc.c b/src/malloc.c
index 2d09af68a..949760553 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -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 ){