aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/malloc.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/malloc.c b/src/malloc.c
index 0fdc8d73f..b942f47b2 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -217,7 +217,7 @@ static void sqlite3MallocAlarm(int nByte){
** Do a memory allocation with statistics and alarms. Assume the
** lock is already held.
*/
-static void mallocWithAlarm(int n, void **pp){
+static void *mallocWithAlarm(int n){
void *p;
int nFull;
assert( sqlite3_mutex_held(mem0.mutex) );
@@ -230,6 +230,12 @@ static void mallocWithAlarm(int n, void **pp){
** following xRoundup() call. */
nFull = sqlite3GlobalConfig.m.xRoundup(n);
+#ifdef SQLITE_MAX_MEMORY
+ if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nFull>SQLITE_MAX_MEMORY ){
+ return 0;
+ }
+#endif
+
sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n);
if( mem0.alarmThreshold>0 ){
sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
@@ -252,7 +258,7 @@ static void mallocWithAlarm(int n, void **pp){
sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nFull);
sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1);
}
- *pp = p;
+ return p;
}
/*
@@ -270,7 +276,7 @@ void *sqlite3Malloc(u64 n){
p = 0;
}else if( sqlite3GlobalConfig.bMemstat ){
sqlite3_mutex_enter(mem0.mutex);
- mallocWithAlarm((int)n, &p);
+ p = mallocWithAlarm((int)n);
sqlite3_mutex_leave(mem0.mutex);
}else{
p = sqlite3GlobalConfig.m.xMalloc((int)n);