/ Check-in [175156d1]
Login

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

Overview
Comment:Minor changes (mainly to assert() macros) to handle malloc failure in vtab operations. (CVS 3851)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:175156d1fcaadab3b955597abb27f6b9043bbb5b
User & Date: danielk1977 2007-04-18 14:24:33
Context
2007-04-18
14:47
Fix an assertion failure caused by (3851). (CVS 3852) check-in: 24683f1d user: danielk1977 tags: trunk
14:24
Minor changes (mainly to assert() macros) to handle malloc failure in vtab operations. (CVS 3851) check-in: 175156d1 user: danielk1977 tags: trunk
13:49
Bump the version number and update documents in preparation for 3.3.16. (CVS 3850) check-in: 852100a3 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/insert.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   ** This file contains C code routines that are called by the parser
    13     13   ** to handle INSERT statements in SQLite.
    14     14   **
    15         -** $Id: insert.c,v 1.184 2007/04/10 18:17:55 drh Exp $
           15  +** $Id: insert.c,v 1.185 2007/04/18 14:24:33 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** Set P3 of the most recently inserted opcode to a column affinity
    21     21   ** string for index pIdx. A column affinity string has one character
    22     22   ** for each column in the table, according to the affinity of the column:
................................................................................
   701    701           sqlite3VdbeAddOp(v, OP_Column, srcTab, keyColumn);
   702    702         }else if( pSelect ){
   703    703           sqlite3VdbeAddOp(v, OP_Dup, nColumn - keyColumn - 1, 1);
   704    704         }else{
   705    705           VdbeOp *pOp;
   706    706           sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr);
   707    707           pOp = sqlite3VdbeGetOp(v, sqlite3VdbeCurrentAddr(v) - 1);
   708         -        if( pOp->opcode==OP_Null ){
          708  +        if( pOp && pOp->opcode==OP_Null ){
   709    709             appendFlag = 1;
   710    710             pOp->opcode = OP_NewRowid;
   711    711             pOp->p1 = base;
   712    712             pOp->p2 = counterMem;
   713    713           }
   714    714         }
   715    715         /* If the PRIMARY KEY expression is NULL, then use OP_NewRowid

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.369 2007/04/16 15:06:25 danielk1977 Exp $
           17  +** $Id: main.c,v 1.370 2007/04/18 14:24:33 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 version of the library
................................................................................
   124    124     {
   125    125       extern void sqlite3SseCleanup(sqlite3*);
   126    126       sqlite3SseCleanup(db);
   127    127     }
   128    128   #endif 
   129    129   
   130    130     sqlite3ResetInternalSchema(db, 0);
          131  +
          132  +  /* If a transaction is open, the ResetInternalSchema() call above
          133  +  ** will not have called the xDisconnect() method on any virtual
          134  +  ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback()
          135  +  ** call will do so. We need to do this before the check for active
          136  +  ** SQL statements below, as the v-table implementation may be storing
          137  +  ** some prepared statements internally.
          138  +  */
          139  +  sqlite3VtabRollback(db);
   131    140   
   132    141     /* If there are any outstanding VMs, return SQLITE_BUSY. */
   133    142     if( db->pVdbe ){
   134    143       sqlite3Error(db, SQLITE_BUSY, 
   135    144           "Unable to close due to unfinalised statements");
   136    145       return SQLITE_BUSY;
   137    146     }
................................................................................
   146    155     ** true. It's hard to see how to cause it without messing with threads.
   147    156     */
   148    157     if( db->magic!=SQLITE_MAGIC_CLOSED && sqlite3SafetyOn(db) ){
   149    158       /* printf("DID NOT CLOSE\n"); fflush(stdout); */
   150    159       return SQLITE_ERROR;
   151    160     }
   152    161   
   153         -  sqlite3VtabRollback(db);
   154         -
   155    162     for(j=0; j<db->nDb; j++){
   156    163       struct Db *pDb = &db->aDb[j];
   157    164       if( pDb->pBt ){
   158    165         sqlite3BtreeClose(pDb->pBt);
   159    166         pDb->pBt = 0;
   160    167         if( j!=1 ){
   161    168           pDb->pSchema = 0;

Changes to src/vdbeaux.c.

   141    141   ** operand.
   142    142   */
   143    143   int sqlite3VdbeAddOp(Vdbe *p, int op, int p1, int p2){
   144    144     int i;
   145    145     VdbeOp *pOp;
   146    146   
   147    147     i = p->nOp;
   148         -  p->nOp++;
   149    148     assert( p->magic==VDBE_MAGIC_INIT );
   150    149     if( p->nOpAlloc<=i ){
   151    150       resizeOpArray(p, i+1);
   152    151       if( sqlite3MallocFailed() ){
   153    152         return 0;
   154    153       }
   155    154     }
          155  +  p->nOp++;
   156    156     pOp = &p->aOp[i];
   157    157     pOp->opcode = op;
   158    158     pOp->p1 = p1;
   159    159     pOp->p2 = p2;
   160    160     pOp->p3 = 0;
   161    161     pOp->p3type = P3_NOTUSED;
   162    162     p->expired = 0;
................................................................................
   553    553   #ifndef NDEBUG
   554    554   /*
   555    555   ** Replace the P3 field of the most recently coded instruction with
   556    556   ** comment text.
   557    557   */
   558    558   void sqlite3VdbeComment(Vdbe *p, const char *zFormat, ...){
   559    559     va_list ap;
   560         -  assert( p->nOp>0 );
   561         -  assert( p->aOp==0 || p->aOp[p->nOp-1].p3==0 
   562         -          || sqlite3MallocFailed() );
          560  +  assert( p->nOp>0 || p->aOp==0 );
          561  +  assert( p->aOp==0 || p->aOp[p->nOp-1].p3==0 || sqlite3MallocFailed() );
   563    562     va_start(ap, zFormat);
   564    563     sqlite3VdbeChangeP3(p, -1, sqlite3VMPrintf(zFormat, ap), P3_DYNAMIC);
   565    564     va_end(ap);
   566    565   }
   567    566   #endif
   568    567   
   569    568   /*
   570    569   ** Return the opcode for a given address.
   571    570   */
   572    571   VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
   573    572     assert( p->magic==VDBE_MAGIC_INIT );
   574         -  assert( addr>=0 && addr<p->nOp );
   575         -  return &p->aOp[addr];
          573  +  assert( (addr>=0 && addr<p->nOp) || sqlite3MallocFailed() );
          574  +  return ((addr>=0 && addr<p->nOp)?(&p->aOp[addr]):0);
   576    575   }
   577    576   
   578    577   #if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) \
   579    578        || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
   580    579   /*
   581    580   ** Compute a string that describes the P3 parameter for an opcode.
   582    581   ** Use zTemp for any required temporary buffer space.

Changes to src/vtab.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 help implement virtual tables.
    13     13   **
    14         -** $Id: vtab.c,v 1.41 2007/04/16 15:49:41 danielk1977 Exp $
           14  +** $Id: vtab.c,v 1.42 2007/04/18 14:24:34 danielk1977 Exp $
    15     15   */
    16     16   #ifndef SQLITE_OMIT_VIRTUALTABLE
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** External API function used to create a new virtual-table module.
    21     21   */
................................................................................
   306    306     int rc;
   307    307     int rc2;
   308    308     sqlite3_vtab *pVtab;
   309    309     const char *const*azArg = (const char *const*)pTab->azModuleArg;
   310    310     int nArg = pTab->nModuleArg;
   311    311     char *zErr = 0;
   312    312     char *zModuleName = sqlite3MPrintf("%s", pTab->zName);
          313  +
          314  +  if( !zModuleName ){
          315  +    return SQLITE_NOMEM;
          316  +  }
   313    317   
   314    318     assert( !db->pVTab );
   315    319     assert( xConstruct );
   316    320   
   317    321     db->pVTab = pTab;
   318    322     rc = sqlite3SafetyOff(db);
   319    323     assert( rc==SQLITE_OK );
................................................................................
   467    471         !sParse.pNewTable->pSelect && 
   468    472         !sParse.pNewTable->isVirtual 
   469    473     ){
   470    474       pTab->aCol = sParse.pNewTable->aCol;
   471    475       pTab->nCol = sParse.pNewTable->nCol;
   472    476       sParse.pNewTable->nCol = 0;
   473    477       sParse.pNewTable->aCol = 0;
          478  +    db->pVTab = 0;
   474    479     } else {
   475    480       sqlite3Error(db, SQLITE_ERROR, zErr);
   476    481       sqliteFree(zErr);
   477    482       rc = SQLITE_ERROR;
   478    483     }
   479    484     sParse.declareVtab = 0;
   480    485   
   481    486     sqlite3_finalize((sqlite3_stmt*)sParse.pVdbe);
   482    487     sqlite3DeleteTable(sParse.pNewTable);
   483    488     sParse.pNewTable = 0;
   484         -  db->pVTab = 0;
   485    489   
   486    490     assert( (rc&0xff)==rc );
   487         -  return rc;
          491  +  return sqlite3ApiExit(db, rc);
   488    492   }
   489    493   
   490    494   /*
   491    495   ** This function is invoked by the vdbe to call the xDestroy method
   492    496   ** of the virtual table named zTab in database iDb. This occurs
   493    497   ** when a DROP TABLE is mentioned.
   494    498   **