/ Check-in [67207a15]
Login

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

Overview
Comment:Fix a problem where a buffer allocated from a lookaside pool was being released using the system free().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 67207a15bd7302ffeb2f342532b57b4852838d83
User & Date: dan 2009-08-19 09:09:38
Context
2009-08-19
14:34
Clean up sqlite_stat2 related code. Add test cases. check-in: aa728e06 user: dan tags: trunk
09:09
Fix a problem where a buffer allocated from a lookaside pool was being released using the system free(). check-in: 67207a15 user: dan tags: trunk
08:18
Add the SQLITE_ENABLE_STAT2 macro. If this is not defined at build-time, the stat2 table is not created, populated, or used. check-in: 362665e8 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/analyze.c.

   545    545   
   546    546       if( rc==SQLITE_OK ){
   547    547         while( sqlite3_step(pStmt)==SQLITE_ROW ){
   548    548           char *zIndex = (char *)sqlite3_column_text(pStmt, 0);
   549    549           Index *pIdx = sqlite3FindIndex(db, zIndex, sInfo.zDatabase);
   550    550           if( pIdx ){
   551    551             int iSample = sqlite3_column_int(pStmt, 1);
          552  +          sqlite3 *dbMem = pIdx->pTable->dbMem;
          553  +	  assert( dbMem==db || dbMem==0 );
   552    554             if( iSample<SQLITE_INDEX_SAMPLES && iSample>=0 ){
   553    555               int eType = sqlite3_column_type(pStmt, 2);
   554    556   
   555    557               if( pIdx->aSample==0 ){
   556         -              static const int nByte = sizeof(IndexSample)*SQLITE_INDEX_SAMPLES;
   557         -              pIdx->aSample = (IndexSample *)sqlite3DbMallocZero(db, nByte);
          558  +              static const int sz = sizeof(IndexSample)*SQLITE_INDEX_SAMPLES;
          559  +              pIdx->aSample = (IndexSample *)sqlite3DbMallocZero(dbMem, sz);
   558    560                 if( pIdx->aSample==0 ){
          561  +		db->mallocFailed = 1;
   559    562                   break;
   560    563                 }
   561    564               }
   562    565   
   563    566               if( pIdx->aSample ){
   564    567                 IndexSample *pSample = &pIdx->aSample[iSample];
   565    568                 if( pSample->eType==SQLITE_TEXT || pSample->eType==SQLITE_BLOB ){
   566         -                sqlite3DbFree(db, pSample->u.z);
          569  +                sqlite3DbFree(dbMem, pSample->u.z);
   567    570                 }
   568    571                 pSample->eType = eType;
   569    572                 if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
   570    573                   pSample->u.r = sqlite3_column_double(pStmt, 2);
   571    574                 }else if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
   572    575                   const char *z = (const char *)(
   573    576                       (eType==SQLITE_BLOB) ?
................................................................................
   575    578                       sqlite3_column_text(pStmt, 2)
   576    579                   );
   577    580                   int n = sqlite3_column_bytes(pStmt, 2);
   578    581                   if( n>24 ){
   579    582                     n = 24;
   580    583                   }
   581    584                   pSample->nByte = n;
   582         -                pSample->u.z = sqlite3DbMallocRaw(db, n);
          585  +                pSample->u.z = sqlite3DbMallocRaw(dbMem, n);
   583    586                   if( pSample->u.z ){
   584    587                     memcpy(pSample->u.z, z, n);
   585    588                   }else{
          589  +		  db->mallocFailed = 1;
   586    590                     break;
   587    591                   }
   588    592                 }
   589    593               }
   590    594             }
   591    595           }
   592    596         }

Changes to src/sqliteInt.h.

  1574   1574     /* If the EP_Reduced flag is set in the Expr.flags mask, then no
  1575   1575     ** space is allocated for the fields below this point. An attempt to
  1576   1576     ** access them will result in a segfault or malfunction.
  1577   1577     *********************************************************************/
  1578   1578   
  1579   1579     int iTable;            /* TK_COLUMN: cursor number of table holding column
  1580   1580                            ** TK_REGISTER: register number */
  1581         -  i16 iColumn;           /* TK_COLUMN: column index.  -1 for rowid */
         1581  +  i16 iColumn;           /* TK_COLUMN: column index.  -1 for rowid
         1582  +                         ** TK_REGISTER: original value of Expr.op */
  1582   1583     i16 iAgg;              /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
  1583   1584     i16 iRightJoinTable;   /* If EP_FromJoin, the right table of the join */
  1584   1585     u16 flags2;            /* Second set of flags.  EP2_... */
  1585   1586     AggInfo *pAggInfo;     /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
  1586   1587     Table *pTab;           /* Table for TK_COLUMN expressions. */
  1587   1588   #if SQLITE_MAX_EXPR_DEPTH>0
  1588   1589     int nHeight;           /* Height of the tree headed by this node */