/ Check-in [4e33a0ea]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Changes to memory allocator usage tracking to delay the onset of integer overflow.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4e33a0eaf83922926f8d5ee988a20439a09bc795
User & Date: drh 2011-04-15 16:39:52
References
2011-05-05
17:00
Fix a bug in memory usage tracking that was introduced by check-in [4e33a0eaf83922]. check-in: 8ba456ae user: drh tags: trunk
Context
2011-04-15
19:30
Remove stray semi-colon that MSVC complained about. check-in: 7a085271 user: shaneh tags: trunk
16:39
Changes to memory allocator usage tracking to delay the onset of integer overflow. check-in: 4e33a0ea user: drh tags: trunk
14:46
Do not do full table scans of unordered indices. check-in: a8761a91 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/malloc.c.

   262    262     int nFull;
   263    263     void *p;
   264    264     assert( sqlite3_mutex_held(mem0.mutex) );
   265    265     nFull = sqlite3GlobalConfig.m.xRoundup(n);
   266    266     sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
   267    267     if( mem0.alarmCallback!=0 ){
   268    268       int nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
   269         -    if( nUsed+nFull >= mem0.alarmThreshold ){
          269  +    if( nUsed >= mem0.alarmThreshold - nFull ){
   270    270         mem0.nearlyFull = 1;
   271    271         sqlite3MallocAlarm(nFull);
   272    272       }else{
   273    273         mem0.nearlyFull = 0;
   274    274       }
   275    275     }
   276    276     p = sqlite3GlobalConfig.m.xMalloc(nFull);
................................................................................
   503    503     sqlite3_free(p);
   504    504   }
   505    505   
   506    506   /*
   507    507   ** Change the size of an existing memory allocation
   508    508   */
   509    509   void *sqlite3Realloc(void *pOld, int nBytes){
   510         -  int nOld, nNew;
          510  +  int nOld, nNew, nDiff;;
   511    511     void *pNew;
   512    512     if( pOld==0 ){
   513    513       return sqlite3Malloc(nBytes); /* IMP: R-28354-25769 */
   514    514     }
   515    515     if( nBytes<=0 ){
   516    516       sqlite3_free(pOld); /* IMP: R-31593-10574 */
   517    517       return 0;
................................................................................
   526    526     ** xRoundup. */
   527    527     nNew = sqlite3GlobalConfig.m.xRoundup(nBytes);
   528    528     if( nOld==nNew ){
   529    529       pNew = pOld;
   530    530     }else if( sqlite3GlobalConfig.bMemstat ){
   531    531       sqlite3_mutex_enter(mem0.mutex);
   532    532       sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, nBytes);
   533         -    if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nNew-nOld >= 
   534         -          mem0.alarmThreshold ){
          533  +    nDiff = nNew - nOld;
          534  +    if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= 
          535  +          mem0.alarmThreshold-nDiff ){
   535    536         sqlite3MallocAlarm(nNew-nOld);
   536    537       }
   537    538       assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
   538    539       assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
   539    540       pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
   540    541       if( pNew==0 && mem0.alarmCallback ){
   541    542         sqlite3MallocAlarm(nBytes);
   542    543         pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
   543    544       }
   544    545       if( pNew ){
   545    546         nNew = sqlite3MallocSize(pNew);
   546         -      sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
          547  +      sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nDiff);
   547    548       }
   548    549       sqlite3_mutex_leave(mem0.mutex);
   549    550     }else{
   550    551       pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
   551    552     }
   552    553     assert( EIGHT_BYTE_ALIGNMENT(pNew) ); /* IMP: R-04675-44850 */
   553    554     return pNew;