/ Check-in [8a9f3e66]
Login

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

Overview
Comment:Add asserts to make sure that database connection locks are held when accessing the lookaside memory allocation buffers. No defects were found. (CVS 6374)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8a9f3e66069146ad1b1bc2686567882dc87603a9
User & Date: drh 2009-03-23 17:49:15
Context
2009-03-23
21:37
Clarify the meaning of a comment. No changes to code. (CVS 6375) check-in: 7c2df04b user: drh tags: trunk
17:49
Add asserts to make sure that database connection locks are held when accessing the lookaside memory allocation buffers. No defects were found. (CVS 6374) check-in: 8a9f3e66 user: drh tags: trunk
17:11
Fix an obscure race condition that can occur when multiple threads, shared cache and DDL statements are combined. Enhance notify2.test to test this scenario. (CVS 6373) check-in: 92ec5975 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/malloc.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   **
    13     13   ** Memory allocation functions used throughout sqlite.
    14     14   **
    15         -** $Id: malloc.c,v 1.59 2009/03/23 04:33:33 danielk1977 Exp $
           15  +** $Id: malloc.c,v 1.60 2009/03/23 17:49:15 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <stdarg.h>
    19     19   
    20     20   /*
    21     21   ** This routine runs when the memory allocator sees that the
    22     22   ** total memory allocation is about to exceed the soft heap
................................................................................
   422    422   ** Return the size of a memory allocation previously obtained from
   423    423   ** sqlite3Malloc() or sqlite3_malloc().
   424    424   */
   425    425   int sqlite3MallocSize(void *p){
   426    426     return sqlite3GlobalConfig.m.xSize(p);
   427    427   }
   428    428   int sqlite3DbMallocSize(sqlite3 *db, void *p){
          429  +  assert( db==0 || sqlite3_mutex_held(db->mutex) );
   429    430     if( p==0 ){
   430    431       return 0;
   431    432     }else if( isLookaside(db, p) ){
   432    433       return db->lookaside.sz;
   433    434     }else{
   434    435       return sqlite3GlobalConfig.m.xSize(p);
   435    436     }
................................................................................
   451    452   }
   452    453   
   453    454   /*
   454    455   ** Free memory that might be associated with a particular database
   455    456   ** connection.
   456    457   */
   457    458   void sqlite3DbFree(sqlite3 *db, void *p){
          459  +  assert( db==0 || sqlite3_mutex_held(db->mutex) );
   458    460     if( isLookaside(db, p) ){
   459    461       LookasideSlot *pBuf = (LookasideSlot*)p;
   460    462       pBuf->pNext = db->lookaside.pFree;
   461    463       db->lookaside.pFree = pBuf;
   462    464       db->lookaside.nOut--;
   463    465     }else{
   464    466       sqlite3_free(p);
................................................................................
   562    564   ** that all prior mallocs (ex: "a") worked too.
   563    565   */
   564    566   void *sqlite3DbMallocRaw(sqlite3 *db, int n){
   565    567     void *p;
   566    568   #ifndef SQLITE_OMIT_LOOKASIDE
   567    569     if( db ){
   568    570       LookasideSlot *pBuf;
          571  +    assert( sqlite3_mutex_held(db->mutex) );
   569    572       if( db->mallocFailed ){
   570    573         return 0;
   571    574       }
   572    575       if( db->lookaside.bEnabled && n<=db->lookaside.sz
   573    576            && (pBuf = db->lookaside.pFree)!=0 ){
   574    577         db->lookaside.pFree = pBuf->pNext;
   575    578         db->lookaside.nOut++;
................................................................................
   593    596   
   594    597   /*
   595    598   ** Resize the block of memory pointed to by p to n bytes. If the
   596    599   ** resize fails, set the mallocFailed flag in the connection object.
   597    600   */
   598    601   void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){
   599    602     void *pNew = 0;
          603  +  assert( sqlite3_mutex_held(db->mutex) );
   600    604     if( db->mallocFailed==0 ){
   601    605       if( p==0 ){
   602    606         return sqlite3DbMallocRaw(db, n);
   603    607       }
   604    608       if( isLookaside(db, p) ){
   605    609         if( n<=db->lookaside.sz ){
   606    610           return p;