/ Check-in [6736f454]
Login

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

Overview
Comment:Fix memory leaks in WHERE clause processing and in TRIGGER parsing. (CVS 3775)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6736f4547c0cc2123d1a19ed2d6915712718d22e
User & Date: drh 2007-03-31 01:34:45
Context
2007-03-31
02:36
Fix a large memory leak in the btree layer that occurs following an I/O error when in shared cache mode. (CVS 3776) check-in: dce4cb84 user: drh tags: trunk
01:34
Fix memory leaks in WHERE clause processing and in TRIGGER parsing. (CVS 3775) check-in: 6736f454 user: drh tags: trunk
2007-03-30
20:46
Remove vestiges of SQLITE_PROTOCOL from the test scripts. (CVS 3774) check-in: e5e8d563 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/trigger.c.

   409    409   /*
   410    410   ** Construct a trigger step that implements a DELETE statement and return
   411    411   ** a pointer to that trigger step.  The parser calls this routine when it
   412    412   ** sees a DELETE statement inside the body of a CREATE TRIGGER.
   413    413   */
   414    414   TriggerStep *sqlite3TriggerDeleteStep(Token *pTableName, Expr *pWhere){
   415    415     TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
   416         -  if( pTriggerStep==0 ) return 0;
          416  +  if( pTriggerStep==0 ){
          417  +    sqlite3ExprDelete(pWhere);
          418  +    return 0;
          419  +  }
   417    420   
   418    421     pTriggerStep->op = TK_DELETE;
   419    422     pTriggerStep->target  = *pTableName;
   420    423     pTriggerStep->pWhere = pWhere;
   421    424     pTriggerStep->orconf = OE_Default;
   422    425     sqlitePersistTriggerStep(pTriggerStep);
   423    426   

Changes to src/where.c.

    12     12   ** This module contains C code that generates VDBE code used to process
    13     13   ** the WHERE clause of SQL statements.  This module is reponsible for
    14     14   ** generating the code that loops through a table looking for applicable
    15     15   ** rows.  Indices are selected and used to speed the search when doing
    16     16   ** so is applicable.  Because this module is responsible for selecting
    17     17   ** indices, you might also think of this module as the "query optimizer".
    18     18   **
    19         -** $Id: where.c,v 1.244 2007/03/30 14:56:35 danielk1977 Exp $
           19  +** $Id: where.c,v 1.245 2007/03/31 01:34:45 drh Exp $
    20     20   */
    21     21   #include "sqliteInt.h"
    22     22   
    23     23   /*
    24     24   ** The number of bits in a Bitmask.  "BMS" means "BitMask Size".
    25     25   */
    26     26   #define BMS  (sizeof(Bitmask)*8)
................................................................................
   216    216     }
   217    217   }
   218    218   
   219    219   /*
   220    220   ** Add a new entries to the WhereClause structure.  Increase the allocated
   221    221   ** space as necessary.
   222    222   **
          223  +** If the flags argument includes TERM_DYNAMIC, then responsibility
          224  +** for freeing the expression p is assumed by the WhereClause object.
          225  +**
   223    226   ** WARNING:  This routine might reallocate the space used to store
   224    227   ** WhereTerms.  All pointers to WhereTerms should be invalided after
   225    228   ** calling this routine.  Such pointers may be reinitialized by referencing
   226    229   ** the pWC->a[] array.
   227    230   */
   228    231   static int whereClauseInsert(WhereClause *pWC, Expr *p, int flags){
   229    232     WhereTerm *pTerm;
   230    233     int idx;
   231    234     if( pWC->nTerm>=pWC->nSlot ){
   232    235       WhereTerm *pOld = pWC->a;
   233    236       pWC->a = sqliteMalloc( sizeof(pWC->a[0])*pWC->nSlot*2 );
   234         -    if( pWC->a==0 ) return 0;
          237  +    if( pWC->a==0 ){
          238  +      if( flags & TERM_DYNAMIC ){
          239  +        sqlite3ExprDelete(p);
          240  +      }
          241  +      return 0;
          242  +    }
   235    243       memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm);
   236    244       if( pOld!=pWC->aStatic ){
   237    245         sqliteFree(pOld);
   238    246       }
   239    247       pWC->nSlot *= 2;
   240    248     }
   241    249     pTerm = &pWC->a[idx = pWC->nTerm];
................................................................................
   730    738       if( pRight && pRight->op==TK_COLUMN ){
   731    739         WhereTerm *pNew;
   732    740         Expr *pDup;
   733    741         if( pTerm->leftCursor>=0 ){
   734    742           int idxNew;
   735    743           pDup = sqlite3ExprDup(pExpr);
   736    744           if( sqlite3MallocFailed() ){
   737         -          sqliteFree(pDup);
          745  +          sqlite3ExprDelete(pDup);
   738    746             return;
   739    747           }
   740    748           idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC);
   741    749           if( idxNew==0 ) return;
   742    750           pNew = &pWC->a[idxNew];
   743    751           pNew->iParent = idxTerm;
   744    752           pTerm = &pWC->a[idxTerm];