/ 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 Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/select.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 SELECT statements in SQLite.
    14     14   **
    15         -** $Id: select.c,v 1.408 2008/01/23 15:44:51 danielk1977 Exp $
           15  +** $Id: select.c,v 1.409 2008/01/23 17:13:41 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   
    20     20   /*
    21     21   ** Delete all the content of a Select structure but do not deallocate
    22     22   ** the select structure itself.
................................................................................
  1672   1672     }
  1673   1673     while( pSelect->pPrior ){
  1674   1674       pSelect = pSelect->pPrior;
  1675   1675     }
  1676   1676     while( pSelect && moreToDo ){
  1677   1677       moreToDo = 0;
  1678   1678       for(i=0; i<pOrderBy->nExpr; i++){
  1679         -      int iCol;
         1679  +      int iCol = -1;
  1680   1680         Expr *pE, *pDup;
  1681   1681         if( pOrderBy->a[i].done ) continue;
  1682   1682         pE = pOrderBy->a[i].pExpr;
  1683   1683         pDup = sqlite3ExprDup(db, pE);
  1684         -      if( pDup==0 ){
  1685         -        return 1;
         1684  +      if( !db->mallocFailed ){
         1685  +        assert(pDup);
         1686  +        iCol = matchOrderByTermToExprList(pParse, pSelect, pDup, i+1, 1, 0);
  1686   1687         }
  1687         -      iCol = matchOrderByTermToExprList(pParse, pSelect, pDup, i+1, 1, 0);
  1688   1688         sqlite3ExprDelete(pDup);
  1689   1689         if( iCol<0 ){
  1690   1690           return 1;
  1691   1691         }
  1692   1692         pEList = pSelect->pEList;
  1693   1693         if( pEList==0 ){
  1694   1694           return 1;

Changes to test/malloc.test.

    12     12   # This file attempts to check the behavior of the SQLite library in 
    13     13   # an out-of-memory situation. When compiled with -DSQLITE_DEBUG=1, 
    14     14   # the SQLite library accepts a special command (sqlite3_memdebug_fail N C)
    15     15   # which causes the N-th malloc to fail.  This special feature is used
    16     16   # to see what happens in the library if a malloc were to really fail
    17     17   # due to an out-of-memory situation.
    18     18   #
    19         -# $Id: malloc.test,v 1.56 2008/01/23 15:44:51 danielk1977 Exp $
           19  +# $Id: malloc.test,v 1.57 2008/01/23 17:13:41 danielk1977 Exp $
    20     20   
    21     21   set testdir [file dirname $argv0]
    22     22   source $testdir/tester.tcl
    23     23   
    24     24   # Only run these tests if memory debugging is turned on.
    25     25   #
    26     26   ifcapable !memdebug {
................................................................................
   568    568     } -sqlbody {
   569    569       SELECT * FROM abc LIMIT 10;
   570    570     } -cleanup {
   571    571       set e [db eval {PRAGMA integrity_check}]
   572    572       if {$e ne "ok"} {error $e}
   573    573     }
   574    574   }
          575  +
          576  +ifcapable compound {
          577  +  do_malloc_test 24 -start 19 -sqlprep {
          578  +    CREATE TABLE t1(a, b, c)
          579  +  } -sqlbody {
          580  +    SELECT 1 FROM t1 UNION SELECT 2 FROM t1 ORDER BY 1
          581  +  }
          582  +}
   575    583   
   576    584   # Ensure that no file descriptors were leaked.
   577    585   do_test malloc-99.X {
   578    586     catch {db close}
   579    587     set sqlite_open_file_count
   580    588   } {0}
   581    589   
   582    590   puts open-file-count=$sqlite_open_file_count
   583    591   finish_test