diff options
author | danielk1977 <danielk1977@noemail.net> | 2008-06-19 18:17:49 +0000 |
---|---|---|
committer | danielk1977 <danielk1977@noemail.net> | 2008-06-19 18:17:49 +0000 |
commit | d09414cdd60e8c30eb15e4758b8289efbe4cdedd (patch) | |
tree | d86848b8fa02eb4ee3265d6a5d384179585de5f0 /src/malloc.c | |
parent | 55b0cf00ad16da59d56358e0073627ae03a3ffa5 (diff) | |
download | sqlite-d09414cdd60e8c30eb15e4758b8289efbe4cdedd.tar.gz sqlite-d09414cdd60e8c30eb15e4758b8289efbe4cdedd.zip |
Move the malloc() failure simulation out of malloc.c and into a separate sqlite3_mem_methods interface. Still some related changes to come. (CVS 5250)
FossilOrigin-Name: d22cd2a59f472f4eaf80aa9f55fbff2514ca428d
Diffstat (limited to 'src/malloc.c')
-rw-r--r-- | src/malloc.c | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/src/malloc.c b/src/malloc.c index 3441123c6..c107c36ab 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -12,7 +12,7 @@ ** ** Memory allocation functions used throughout sqlite. ** -** $Id: malloc.c,v 1.21 2008/06/19 00:16:08 drh Exp $ +** $Id: malloc.c,v 1.22 2008/06/19 18:17:50 danielk1977 Exp $ */ #include "sqliteInt.h" #include <stdarg.h> @@ -213,14 +213,10 @@ static int mallocWithAlarm(int n, void **pp){ sqlite3MallocAlarm(nFull); } } - if( sqlite3FaultStep(SQLITE_FAULTINJECTOR_MALLOC) ){ - p = 0; - }else{ + p = sqlite3Config.m.xMalloc(nFull); + if( p==0 && mem0.alarmCallback ){ + sqlite3MallocAlarm(nFull); p = sqlite3Config.m.xMalloc(nFull); - if( p==0 ){ - sqlite3MallocAlarm(nFull); - p = malloc(nFull); - } } if( p ) sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nFull); *pp = p; @@ -279,9 +275,6 @@ static int scratchAllocOut = 0; void *sqlite3ScratchMalloc(int n){ void *p; assert( n>0 ); - if( sqlite3FaultStep(SQLITE_FAULTINJECTOR_MALLOC) ){ - return 0; - } #if SQLITE_THREADSAFE==0 && !defined(NDEBUG) /* Verify that no more than one scratch allocation per thread @@ -377,9 +370,6 @@ void *sqlite3PageMalloc(int n){ assert( n>0 ); assert( (n & (n-1))==0 ); assert( n>=512 && n<=32768 ); - if( sqlite3FaultStep(SQLITE_FAULTINJECTOR_MALLOC) ){ - return 0; - } if( sqlite3Config.szPage<n ){ goto page_overflow; @@ -487,14 +477,10 @@ void *sqlite3Realloc(void *pOld, int nBytes){ mem0.alarmThreshold ){ sqlite3MallocAlarm(nNew-nOld); } - if( sqlite3FaultStep(SQLITE_FAULTINJECTOR_MALLOC) ){ - pNew = 0; - }else{ + pNew = sqlite3Config.m.xRealloc(pOld, nNew); + if( pNew==0 && mem0.alarmCallback ){ + sqlite3MallocAlarm(nBytes); pNew = sqlite3Config.m.xRealloc(pOld, nNew); - if( pNew==0 ){ - sqlite3MallocAlarm(nBytes); - pNew = sqlite3Config.m.xRealloc(pOld, nNew); - } } if( pNew ){ sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld); |