aboutsummaryrefslogtreecommitdiff
path: root/src/malloc.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2009-08-18 14:48:53 +0000
committerdrh <drh@noemail.net>2009-08-18 14:48:53 +0000
commit7c6791c8b1b78fe03665867484bddf6fac9663b2 (patch)
tree4b93e5619578ae1e2f79c8394b799a772e13c117 /src/malloc.c
parent15385ad437d60bf7025e79859d0b32ce264369f8 (diff)
downloadsqlite-7c6791c8b1b78fe03665867484bddf6fac9663b2.tar.gz
sqlite-7c6791c8b1b78fe03665867484bddf6fac9663b2.zip
Fix obscure issues with the memsys5 memory allocator. Arrange that the
xRealloc() interface to memory allocators is only called with a value that has been through xRoundup(). FossilOrigin-Name: 577bd6f15556b7f6d86ee5167353fdd535577bf6
Diffstat (limited to 'src/malloc.c')
-rw-r--r--src/malloc.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/malloc.c b/src/malloc.c
index 7afe528d7..6678d5659 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -481,30 +481,28 @@ void *sqlite3Realloc(void *pOld, int nBytes){
return 0;
}
nOld = sqlite3MallocSize(pOld);
- if( sqlite3GlobalConfig.bMemstat ){
+ nNew = sqlite3GlobalConfig.m.xRoundup(nBytes);
+ if( nOld==nNew ){
+ pNew = pOld;
+ }else if( sqlite3GlobalConfig.bMemstat ){
sqlite3_mutex_enter(mem0.mutex);
sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes);
- nNew = sqlite3GlobalConfig.m.xRoundup(nBytes);
- if( nOld==nNew ){
- pNew = pOld;
- }else{
- if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nNew-nOld >=
- mem0.alarmThreshold ){
- sqlite3MallocAlarm(nNew-nOld);
- }
+ if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nNew-nOld >=
+ mem0.alarmThreshold ){
+ sqlite3MallocAlarm(nNew-nOld);
+ }
+ pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
+ if( pNew==0 && mem0.alarmCallback ){
+ sqlite3MallocAlarm(nBytes);
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
- if( pNew==0 && mem0.alarmCallback ){
- sqlite3MallocAlarm(nBytes);
- pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
- }
- if( pNew ){
- nNew = sqlite3MallocSize(pNew);
- sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
- }
+ }
+ if( pNew ){
+ nNew = sqlite3MallocSize(pNew);
+ sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
}
sqlite3_mutex_leave(mem0.mutex);
}else{
- pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nBytes);
+ pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
}
return pNew;
}