/ Check-in [a6fe3d6b]
Login

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

Overview
Comment:Improved overrun detection in mem2.c (SQLITE_MEMDEBUG). Previously was only checking up to 3 extra bytes allocated due to rounding. (CVS 6261)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:a6fe3d6b02734b23fe067a373c0232024a782a6c
User & Date: shane 2009-02-05 03:00:06
Context
2009-02-05
03:16
Fixed error detection in winTrucate() in os_win.c. Windows version only. Ticket #3640. (CVS 6262) check-in: 82e03f1b user: shane tags: trunk
03:00
Improved overrun detection in mem2.c (SQLITE_MEMDEBUG). Previously was only checking up to 3 extra bytes allocated due to rounding. (CVS 6261) check-in: a6fe3d6b user: shane tags: trunk
2009-02-04
22:46
Add "backup" and "restore" methods to the TCL interfaces and test cases to exercise those methods. (CVS 6260) check-in: e420a3ce user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/mem2.c.

    15     15   ** to obtain the memory it needs while adding lots of additional debugging
    16     16   ** information to each allocation in order to help detect and fix memory
    17     17   ** leaks and memory usage errors.
    18     18   **
    19     19   ** This file contains implementations of the low-level memory allocation
    20     20   ** routines specified in the sqlite3_mem_methods object.
    21     21   **
    22         -** $Id: mem2.c,v 1.42 2008/12/10 19:26:24 drh Exp $
           22  +** $Id: mem2.c,v 1.43 2009/02/05 03:00:06 shane Exp $
    23     23   */
    24     24   #include "sqliteInt.h"
    25     25   
    26     26   /*
    27     27   ** This version of the memory allocator is used only if the
    28     28   ** SQLITE_MEMDEBUG macro is defined
    29     29   */
................................................................................
   159    159     p = (struct MemBlockHdr*)pAllocation;
   160    160     p--;
   161    161     assert( p->iForeGuard==(int)FOREGUARD );
   162    162     nReserve = (p->iSize+7)&~7;
   163    163     pInt = (int*)pAllocation;
   164    164     pU8 = (u8*)pAllocation;
   165    165     assert( pInt[nReserve/sizeof(int)]==(int)REARGUARD );
   166         -  assert( (nReserve-0)<=p->iSize || pU8[nReserve-1]==0x65 );
   167         -  assert( (nReserve-1)<=p->iSize || pU8[nReserve-2]==0x65 );
   168         -  assert( (nReserve-2)<=p->iSize || pU8[nReserve-3]==0x65 );
          166  +  /* This checks any of the "extra" bytes allocated due
          167  +  ** to rounding up to an 8 byte boundary to ensure 
          168  +  ** they haven't been overwritten.
          169  +  */
          170  +  while( nReserve-- > p->iSize ) assert( pU8[nReserve]==0x65 );
   169    171     return p;
   170    172   }
   171    173   
   172    174   /*
   173    175   ** Return the number of bytes currently allocated at address p.
   174    176   */
   175    177   static int sqlite3MemSize(void *p){
................................................................................
   182    184   }
   183    185   
   184    186   /*
   185    187   ** Initialize the memory allocation subsystem.
   186    188   */
   187    189   static int sqlite3MemInit(void *NotUsed){
   188    190     UNUSED_PARAMETER(NotUsed);
          191  +  assert( (sizeof(struct MemBlockHdr)&7) == 0 );
   189    192     if( !sqlite3GlobalConfig.bMemstat ){
   190    193       /* If memory status is enabled, then the malloc.c wrapper will already
   191    194       ** hold the STATIC_MEM mutex when the routines here are invoked. */
   192    195       mem.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
   193    196     }
   194    197     return SQLITE_OK;
   195    198   }