1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-10 01:02:56 +03:00

Changes to memory allocator usage tracking to delay the onset of integer

overflow.

FossilOrigin-Name: 4e33a0eaf83922926f8d5ee988a20439a09bc795
This commit is contained in:
drh
2011-04-15 16:39:52 +00:00
parent 3e9548b30d
commit 8e1bb041a8
3 changed files with 13 additions and 12 deletions

View File

@@ -266,7 +266,7 @@ static int mallocWithAlarm(int n, void **pp){
sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
if( mem0.alarmCallback!=0 ){
int nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
if( nUsed+nFull >= mem0.alarmThreshold ){
if( nUsed >= mem0.alarmThreshold - nFull ){
mem0.nearlyFull = 1;
sqlite3MallocAlarm(nFull);
}else{
@@ -507,7 +507,7 @@ void sqlite3DbFree(sqlite3 *db, void *p){
** Change the size of an existing memory allocation
*/
void *sqlite3Realloc(void *pOld, int nBytes){
int nOld, nNew;
int nOld, nNew, nDiff;;
void *pNew;
if( pOld==0 ){
return sqlite3Malloc(nBytes); /* IMP: R-28354-25769 */
@@ -530,8 +530,9 @@ void *sqlite3Realloc(void *pOld, int nBytes){
}else if( sqlite3GlobalConfig.bMemstat ){
sqlite3_mutex_enter(mem0.mutex);
sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes);
if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nNew-nOld >=
mem0.alarmThreshold ){
nDiff = nNew - nOld;
if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
mem0.alarmThreshold-nDiff ){
sqlite3MallocAlarm(nNew-nOld);
}
assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
@@ -543,7 +544,7 @@ void *sqlite3Realloc(void *pOld, int nBytes){
}
if( pNew ){
nNew = sqlite3MallocSize(pNew);
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nDiff);
}
sqlite3_mutex_leave(mem0.mutex);
}else{