/ Check-in [ee4894b4]
Login

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

Overview
Comment:Fix a problems that arise if malloc() fails while compiling SELECT statements within a TRIGGER. (CVS 3478)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ee4894b49995e4904db1991281563cfbb7b1c16d
User & Date: drh 2006-10-18 23:26:39
Context
2006-10-19
01:58
When converting UTF8 or UTF16 strings, change overlong strings and other illegal codes to 0xFFFD. Ticket #2029. (CVS 3479) check-in: 0c6736df user: drh tags: trunk
2006-10-18
23:26
Fix a problems that arise if malloc() fails while compiling SELECT statements within a TRIGGER. (CVS 3478) check-in: ee4894b4 user: drh tags: trunk
2006-10-13
15:34
Make sure the names of all expressions in compound SELECT statements used as subqueries are correctly resolved. Ticket #2018. (CVS 3477) check-in: b886eaa3 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/trigger.c.

664
665
666
667
668
669
670
671
672
673
674
675
676

677
678
679
680
681
682
683
  sqlite3VdbeAddOp(v, OP_ContextPush, 0, 0);
  VdbeComment((v, "# begin trigger %s", pStepList->pTrig->name));
  while( pTriggerStep ){
    orconf = (orconfin == OE_Default)?pTriggerStep->orconf:orconfin;
    pParse->trigStack->orconf = orconf;
    switch( pTriggerStep->op ){
      case TK_SELECT: {
	Select * ss = sqlite3SelectDup(pTriggerStep->pSelect);		  
	assert(ss);
	assert(ss->pSrc);
        sqlite3SelectResolve(pParse, ss, 0);
	sqlite3Select(pParse, ss, SRT_Discard, 0, 0, 0, 0, 0);
	sqlite3SelectDelete(ss);

	break;
      }
      case TK_UPDATE: {
        SrcList *pSrc;
        pSrc = targetSrcList(pParse, pTriggerStep);
        sqlite3VdbeAddOp(v, OP_ResetCount, 0, 0);
        sqlite3Update(pParse, pSrc,







|
|
<
|
|
|
>







664
665
666
667
668
669
670
671
672

673
674
675
676
677
678
679
680
681
682
683
  sqlite3VdbeAddOp(v, OP_ContextPush, 0, 0);
  VdbeComment((v, "# begin trigger %s", pStepList->pTrig->name));
  while( pTriggerStep ){
    orconf = (orconfin == OE_Default)?pTriggerStep->orconf:orconfin;
    pParse->trigStack->orconf = orconf;
    switch( pTriggerStep->op ){
      case TK_SELECT: {
	Select *ss = sqlite3SelectDup(pTriggerStep->pSelect);
        if( ss ){

          sqlite3SelectResolve(pParse, ss, 0);
          sqlite3Select(pParse, ss, SRT_Discard, 0, 0, 0, 0, 0);
          sqlite3SelectDelete(ss);
        }
	break;
      }
      case TK_UPDATE: {
        SrcList *pSrc;
        pSrc = targetSrcList(pParse, pTriggerStep);
        sqlite3VdbeAddOp(v, OP_ResetCount, 0, 0);
        sqlite3Update(pParse, pSrc,

Changes to src/where.c.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
618
619
620
621
622
623
624




625
626
627
628
629
630
631
** This module contains C code that generates VDBE code used to process
** the WHERE clause of SQL statements.  This module is reponsible for
** generating the code that loops through a table looking for applicable
** rows.  Indices are selected and used to speed the search when doing
** so is applicable.  Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
**
** $Id: where.c,v 1.228 2006/06/27 13:20:22 drh Exp $
*/
#include "sqliteInt.h"

/*
** The number of bits in a Bitmask.  "BMS" means "BitMask Size".
*/
#define BMS  (sizeof(Bitmask)*8)
................................................................................
    }
    if( pRight && pRight->op==TK_COLUMN ){
      WhereTerm *pNew;
      Expr *pDup;
      if( pTerm->leftCursor>=0 ){
        int idxNew;
        pDup = sqlite3ExprDup(pExpr);




        idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC);
        if( idxNew==0 ) return;
        pNew = &pWC->a[idxNew];
        pNew->iParent = idxTerm;
        pTerm = &pWC->a[idxTerm];
        pTerm->nChild = 1;
        pTerm->flags |= TERM_COPIED;







|







 







>
>
>
>







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
** This module contains C code that generates VDBE code used to process
** the WHERE clause of SQL statements.  This module is reponsible for
** generating the code that loops through a table looking for applicable
** rows.  Indices are selected and used to speed the search when doing
** so is applicable.  Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
**
** $Id: where.c,v 1.229 2006/10/18 23:26:39 drh Exp $
*/
#include "sqliteInt.h"

/*
** The number of bits in a Bitmask.  "BMS" means "BitMask Size".
*/
#define BMS  (sizeof(Bitmask)*8)
................................................................................
    }
    if( pRight && pRight->op==TK_COLUMN ){
      WhereTerm *pNew;
      Expr *pDup;
      if( pTerm->leftCursor>=0 ){
        int idxNew;
        pDup = sqlite3ExprDup(pExpr);
        if( sqlite3MallocFailed() ){
          sqliteFree(pDup);
          return;
        }
        idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC);
        if( idxNew==0 ) return;
        pNew = &pWC->a[idxNew];
        pNew->iParent = idxTerm;
        pTerm = &pWC->a[idxTerm];
        pTerm->nChild = 1;
        pTerm->flags |= TERM_COPIED;

Changes to test/malloc.test.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
225
226
227
228
229
230
231
232



233
234
235
236
237
238
239
#***********************************************************************
# This file attempts to check the library in an out-of-memory situation.
# When compiled with -DSQLITE_DEBUG=1, the SQLite library accepts a special
# command (sqlite_malloc_fail N) which causes the N-th malloc to fail.  This
# special feature is used to see what happens in the library if a malloc
# were to really fail due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.35 2006/10/04 11:55:50 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if memory debugging is turned on.
#
if {[info command sqlite_malloc_stat]==""} {
................................................................................
} {0}

do_malloc_test 5 -sqlbody {
  BEGIN TRANSACTION;
  CREATE TABLE t1(a,b);
  CREATE TABLE t2(x,y);
  CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN
  INSERT INTO t2(x,y) VALUES(new.rowid,1);



  END;
  INSERT INTO t1(a,b) VALUES(2,3);
  COMMIT;
} 

# Ensure that no file descriptors were leaked.
do_test malloc-5.X {







|







 







|
>
>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#***********************************************************************
# This file attempts to check the library in an out-of-memory situation.
# When compiled with -DSQLITE_DEBUG=1, the SQLite library accepts a special
# command (sqlite_malloc_fail N) which causes the N-th malloc to fail.  This
# special feature is used to see what happens in the library if a malloc
# were to really fail due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.36 2006/10/18 23:26:39 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if memory debugging is turned on.
#
if {[info command sqlite_malloc_stat]==""} {
................................................................................
} {0}

do_malloc_test 5 -sqlbody {
  BEGIN TRANSACTION;
  CREATE TABLE t1(a,b);
  CREATE TABLE t2(x,y);
  CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN
    INSERT INTO t2(x,y) VALUES(new.rowid,1);
    UPDATE t2 SET y=y+1 WHERE x=new.rowid;
    SELECT 123;
    DELETE FROM t2 WHERE x=new.rowid;
  END;
  INSERT INTO t1(a,b) VALUES(2,3);
  COMMIT;
} 

# Ensure that no file descriptors were leaked.
do_test malloc-5.X {