/ Check-in [bd02a6fa]
Login

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

Overview
Comment:If compiled with memory-debugging, write garbage to memory when it is freed. Fix for #1594. (CVS 2900)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bd02a6faefa3602d0b93d54bc57809a2222d5903
User & Date: danielk1977 2006-01-10 07:14:23
Context
2006-01-10
12:31
Fix a problem with shared-schemas and temp triggers. (CVS 2901) check-in: 9c18a1ce user: danielk1977 tags: trunk
07:14
If compiled with memory-debugging, write garbage to memory when it is freed. Fix for #1594. (CVS 2900) check-in: bd02a6fa user: danielk1977 tags: trunk
02:30
Enable shared cache on the server demonstration. (CVS 2899) check-in: 8719f880 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/attach.c.

     7      7   **    May you do good and not evil.
     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   ** This file contains code used to implement the ATTACH and DETACH commands.
    13     13   **
    14         -** $Id: attach.c,v 1.43 2006/01/09 23:40:25 drh Exp $
           14  +** $Id: attach.c,v 1.44 2006/01/10 07:14:23 danielk1977 Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   
    18     18   /*
    19     19   ** Resolve an expression that was part of an ATTACH or DETACH statement. This
    20     20   ** is slightly different from resolving a normal SQL expression, because simple
    21     21   ** identifiers are treated as strings, not possible column names or aliases.
................................................................................
   178    178     }
   179    179     if( rc ){
   180    180       int i = db->nDb - 1;
   181    181       assert( i>=2 );
   182    182       if( db->aDb[i].pBt ){
   183    183         sqlite3BtreeClose(db->aDb[i].pBt);
   184    184         db->aDb[i].pBt = 0;
          185  +      db->aDb[i].pSchema = 0;
   185    186       }
   186    187       sqlite3ResetInternalSchema(db, 0);
   187    188       db->nDb = i;
   188    189       sqlite3_snprintf(127, zErr, "unable to open database: %s", zFile);
   189    190       goto attach_error;
   190    191     }
   191    192     
................................................................................
   239    240     if( !db->autoCommit ){
   240    241       strcpy(zErr, "cannot DETACH database within transaction");
   241    242       goto detach_error;
   242    243     }
   243    244   
   244    245     sqlite3BtreeClose(pDb->pBt);
   245    246     pDb->pBt = 0;
          247  +  pDb->pSchema = 0;
   246    248     sqlite3ResetInternalSchema(db, 0);
   247    249     return;
   248    250   
   249    251   detach_error:
   250    252     sqlite3_result_error(context, zErr, -1);
   251    253   }
   252    254   

Changes to src/build.c.

    18     18   **     CREATE INDEX
    19     19   **     DROP INDEX
    20     20   **     creating ID lists
    21     21   **     BEGIN TRANSACTION
    22     22   **     COMMIT
    23     23   **     ROLLBACK
    24     24   **
    25         -** $Id: build.c,v 1.373 2006/01/09 23:40:25 drh Exp $
           25  +** $Id: build.c,v 1.374 2006/01/10 07:14:23 danielk1977 Exp $
    26     26   */
    27     27   #include "sqliteInt.h"
    28     28   #include <ctype.h>
    29     29   
    30     30   /*
    31     31   ** This routine is called when a new SQL statement is beginning to
    32     32   ** be parsed.  Initialize the pParse structure as needed.
................................................................................
   401    401       }
   402    402       if( iDb>0 ) return;
   403    403     }
   404    404     assert( iDb==0 );
   405    405     db->flags &= ~SQLITE_InternChanges;
   406    406   
   407    407     /* If one or more of the auxiliary database files has been closed,
   408         -  ** then remove then from the auxiliary database list.  We take the
          408  +  ** then remove them from the auxiliary database list.  We take the
   409    409     ** opportunity to do this here since we have just deleted all of the
   410    410     ** schema hash tables and therefore do not have to make any changes
   411    411     ** to any of those tables.
   412    412     */
   413    413     for(i=0; i<db->nDb; i++){
   414    414       struct Db *pDb = &db->aDb[i];
   415    415       if( pDb->pBt==0 ){

Changes to src/main.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Main file for the SQLite library.  The routines in this file
    13     13   ** implement the programmer interface to the library.  Routines in
    14     14   ** other files are for internal use by SQLite and should not be
    15     15   ** accessed by users of the library.
    16     16   **
    17         -** $Id: main.c,v 1.320 2006/01/09 16:12:05 danielk1977 Exp $
           17  +** $Id: main.c,v 1.321 2006/01/10 07:14:24 danielk1977 Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "os.h"
    21     21   #include <ctype.h>
    22     22   
    23     23   /*
    24     24   ** The following constant value is used by the SQLITE_BIGENDIAN and
................................................................................
   135    135     sqlite3MallocDisallow();
   136    136   
   137    137     for(j=0; j<db->nDb; j++){
   138    138       struct Db *pDb = &db->aDb[j];
   139    139       if( pDb->pBt ){
   140    140         sqlite3BtreeClose(pDb->pBt);
   141    141         pDb->pBt = 0;
          142  +      if( j!=1 ){
          143  +        pDb->pSchema = 0;
          144  +      }
   142    145       }
   143    146     }
   144    147     sqlite3ResetInternalSchema(db, 0);
   145    148     assert( db->nDb<=2 );
   146    149     assert( db->aDb==db->aDbStatic );
   147    150     for(i=sqliteHashFirst(&db->aFunc); i; i=sqliteHashNext(i)){
   148    151       FuncDef *pFunc, *pNext;
................................................................................
   161    164     sqlite3HashClear(&db->aFunc);
   162    165     sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */
   163    166     if( db->pErr ){
   164    167       sqlite3ValueFree(db->pErr);
   165    168     }
   166    169   
   167    170     db->magic = SQLITE_MAGIC_ERROR;
          171  +
          172  +  /* The temp-database schema is allocated differently from the other schema
          173  +  ** objects (using sqliteMalloc() directly, instead of sqlite3BtreeSchema()).
          174  +  ** So it needs to be freed here. Todo: Why not roll the temp schema into
          175  +  ** the same sqliteMalloc() as the one that allocates the database 
          176  +  ** structure?
          177  +  */
   168    178     sqliteFree(db->aDb[1].pSchema);
          179  +
   169    180     sqliteFree(db);
   170    181     sqlite3MallocAllow();
   171    182     return SQLITE_OK;
   172    183   }
   173    184   
   174    185   /*
   175    186   ** Rollback all database files.

Changes to src/util.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Utility functions used throughout sqlite.
    13     13   **
    14     14   ** This file contains functions for allocating memory, comparing
    15     15   ** strings, and stuff like that.
    16     16   **
    17         -** $Id: util.c,v 1.164 2006/01/09 09:59:49 danielk1977 Exp $
           17  +** $Id: util.c,v 1.165 2006/01/10 07:14:24 danielk1977 Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "os.h"
    21     21   #include <stdarg.h>
    22     22   #include <ctype.h>
    23     23   
    24     24   /*
................................................................................
   445    445       sqlite3_nMalloc++;
   446    446       applyGuards(p);
   447    447       linkAlloc(p);
   448    448       return (void *)(&p[TESTALLOC_NGUARD + 2*sizeof(void *)/sizeof(u32)]);
   449    449     }
   450    450     return 0;
   451    451   }
          452  +
          453  +static int OSSIZEOF(void *p){
          454  +  if( p ){
          455  +    u32 *pOs = (u32 *)getOsPointer(p);
          456  +    return sqlite3OsAllocationSize(pOs) - TESTALLOC_OVERHEAD;
          457  +  }
          458  +  return 0;
          459  +}
   452    460   
   453    461   /*
   454    462   ** This is the test layer's wrapper around sqlite3OsFree(). The argument is a
   455    463   ** pointer to the space allocated for the application to use.
   456    464   */
   457         -void OSFREE(void *pFree){
          465  +static void OSFREE(void *pFree){
   458    466     u32 *p = (u32 *)getOsPointer(pFree);   /* p points to Os level allocation */
   459    467     checkGuards(p);
   460    468     unlinkAlloc(p);
          469  +  memset(pFree, 0x55, OSSIZEOF(pFree));
   461    470     sqlite3OsFree(p);
   462    471     sqlite3_nFree++;
   463    472   }
   464    473   
   465    474   /*
   466    475   ** This is the test layer's wrapper around sqlite3OsRealloc().
   467    476   */
   468         -void * OSREALLOC(void *pRealloc, int n){
          477  +static void * OSREALLOC(void *pRealloc, int n){
   469    478   #ifndef SQLITE_OMIT_MEMORY_MANAGEMENT
   470    479     ThreadData *pTsd = sqlite3ThreadData();
   471    480     pTsd->nMaxAlloc = MAX(pTsd->nMaxAlloc, pTsd->nAlloc);
   472    481   #endif
   473    482     if( !failMalloc() ){
   474    483       u32 *p = (u32 *)getOsPointer(pRealloc);
   475    484       checkGuards(p);
................................................................................
   477    486       applyGuards(p);
   478    487       relinkAlloc(p);
   479    488       return (void *)(&p[TESTALLOC_NGUARD + 2*sizeof(void *)/sizeof(u32)]);
   480    489     }
   481    490     return 0;
   482    491   }
   483    492   
   484         -void OSMALLOC_FAILED(){
          493  +static void OSMALLOC_FAILED(){
   485    494     sqlite3ThreadData()->isFail = 0;
   486    495   }
   487    496   
   488         -int OSSIZEOF(void *p){
   489         -  if( p ){
   490         -    u32 *pOs = (u32 *)getOsPointer(p);
   491         -    return sqlite3OsAllocationSize(pOs) - TESTALLOC_OVERHEAD;
   492         -  }
   493         -  return 0;
   494         -}
   495         -
   496    497   #else
   497    498   /* Define macros to call the sqlite3OsXXX interface directly if 
   498    499   ** the SQLITE_MEMDEBUG macro is not defined.
   499    500   */
   500    501   #define OSMALLOC(x)        sqlite3OsMalloc(x)
   501    502   #define OSREALLOC(x,y)     sqlite3OsRealloc(x,y)
   502    503   #define OSFREE(x)          sqlite3OsFree(x)

Changes to test/quick.test.

     2      2   #    May you do good and not evil.
     3      3   #    May you find forgiveness for yourself and forgive others.
     4      4   #    May you share freely, never taking more than you give.
     5      5   #
     6      6   #***********************************************************************
     7      7   # This file runs all tests.
     8      8   #
     9         -# $Id: quick.test,v 1.40 2006/01/09 16:12:05 danielk1977 Exp $
            9  +# $Id: quick.test,v 1.41 2006/01/10 07:14:24 danielk1977 Exp $
    10     10   
    11     11   proc lshift {lvar} {
    12     12     upvar $lvar l
    13     13     set ret [lindex $l 0]
    14     14     set l [lrange $l 1 end]
    15     15     return $ret
    16     16   }
................................................................................
    46     46     malloc2.test
    47     47     malloc3.test
    48     48     malloc4.test
    49     49     memleak.test
    50     50     misuse.test
    51     51     quick.test
    52     52   
    53         -  attachmalloc.test
    54         -  utf16.test
    55     53     autovacuum_crash.test
    56     54     btree8.test
           55  +  utf16.test
    57     56   }
    58     57   
    59     58   if {[sqlite3 -has-codec]} {
    60     59     # lappend EXCLUDE \
    61     60     #  conflict.test
    62     61   }
    63     62