/ Check-in [9d98a3f0]
Login

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

Overview
Comment:Fix another segfault that can occur following a malloc failure in the SQL compiler. (CVS 4748)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9d98a3f0dded4ee7ed53872f48ee8592ff077f92
User & Date: danielk1977 2008-01-23 17:13:41
Context
2008-01-24
14:27
Fix a segfault that may follow a malloc failure during compilation of an INSTEAD OF trigger. (CVS 4749) check-in: c6635a71 user: danielk1977 tags: trunk
2008-01-23
17:13
Fix another segfault that can occur following a malloc failure in the SQL compiler. (CVS 4748) check-in: 9d98a3f0 user: danielk1977 tags: trunk
15:44
Fix a couple of segfaults that could occur after a malloc() failure in the SQL compiler. (CVS 4747) check-in: 6bd8db38 user: danielk1977 tags: trunk
Changes
Hide Diffs Unified Diffs Show Whitespace Changes Patch

Changes to src/select.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
....
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687

1688
1689
1690
1691
1692
1693
1694
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.408 2008/01/23 15:44:51 danielk1977 Exp $
*/
#include "sqliteInt.h"


/*
** Delete all the content of a Select structure but do not deallocate
** the select structure itself.
................................................................................
  }
  while( pSelect->pPrior ){
    pSelect = pSelect->pPrior;
  }
  while( pSelect && moreToDo ){
    moreToDo = 0;
    for(i=0; i<pOrderBy->nExpr; i++){
      int iCol;
      Expr *pE, *pDup;
      if( pOrderBy->a[i].done ) continue;
      pE = pOrderBy->a[i].pExpr;
      pDup = sqlite3ExprDup(db, pE);
      if( pDup==0 ){
        return 1;
      }
      iCol = matchOrderByTermToExprList(pParse, pSelect, pDup, i+1, 1, 0);

      sqlite3ExprDelete(pDup);
      if( iCol<0 ){
        return 1;
      }
      pEList = pSelect->pEList;
      if( pEList==0 ){
        return 1;







|







 







|




|
|
<
|
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
....
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685

1686
1687
1688
1689
1690
1691
1692
1693
1694
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.409 2008/01/23 17:13:41 danielk1977 Exp $
*/
#include "sqliteInt.h"


/*
** Delete all the content of a Select structure but do not deallocate
** the select structure itself.
................................................................................
  }
  while( pSelect->pPrior ){
    pSelect = pSelect->pPrior;
  }
  while( pSelect && moreToDo ){
    moreToDo = 0;
    for(i=0; i<pOrderBy->nExpr; i++){
      int iCol = -1;
      Expr *pE, *pDup;
      if( pOrderBy->a[i].done ) continue;
      pE = pOrderBy->a[i].pExpr;
      pDup = sqlite3ExprDup(db, pE);
      if( !db->mallocFailed ){
        assert(pDup);

        iCol = matchOrderByTermToExprList(pParse, pSelect, pDup, i+1, 1, 0);
      }
      sqlite3ExprDelete(pDup);
      if( iCol<0 ){
        return 1;
      }
      pEList = pSelect->pEList;
      if( pEList==0 ){
        return 1;

Changes to test/malloc.test.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
568
569
570
571
572
573
574








575
576
577
578
579
580
581
582
583
# This file attempts to check the behavior of the SQLite library in 
# an out-of-memory situation. When compiled with -DSQLITE_DEBUG=1, 
# the SQLite library accepts a special command (sqlite3_memdebug_fail N C)
# 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.56 2008/01/23 15:44:51 danielk1977 Exp $

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

# Only run these tests if memory debugging is turned on.
#
ifcapable !memdebug {
................................................................................
  } -sqlbody {
    SELECT * FROM abc LIMIT 10;
  } -cleanup {
    set e [db eval {PRAGMA integrity_check}]
    if {$e ne "ok"} {error $e}
  }
}









# Ensure that no file descriptors were leaked.
do_test malloc-99.X {
  catch {db close}
  set sqlite_open_file_count
} {0}

puts open-file-count=$sqlite_open_file_count
finish_test







|







 







>
>
>
>
>
>
>
>









12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
# This file attempts to check the behavior of the SQLite library in 
# an out-of-memory situation. When compiled with -DSQLITE_DEBUG=1, 
# the SQLite library accepts a special command (sqlite3_memdebug_fail N C)
# 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.57 2008/01/23 17:13:41 danielk1977 Exp $

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

# Only run these tests if memory debugging is turned on.
#
ifcapable !memdebug {
................................................................................
  } -sqlbody {
    SELECT * FROM abc LIMIT 10;
  } -cleanup {
    set e [db eval {PRAGMA integrity_check}]
    if {$e ne "ok"} {error $e}
  }
}

ifcapable compound {
  do_malloc_test 24 -start 19 -sqlprep {
    CREATE TABLE t1(a, b, c)
  } -sqlbody {
    SELECT 1 FROM t1 UNION SELECT 2 FROM t1 ORDER BY 1
  }
}

# Ensure that no file descriptors were leaked.
do_test malloc-99.X {
  catch {db close}
  set sqlite_open_file_count
} {0}

puts open-file-count=$sqlite_open_file_count
finish_test