Index: src/select.c ================================================================== --- src/select.c +++ src/select.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** 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 $ +** $Id: select.c,v 1.409 2008/01/23 17:13:41 danielk1977 Exp $ */ #include "sqliteInt.h" /* @@ -1674,19 +1674,19 @@ pSelect = pSelect->pPrior; } while( pSelect && moreToDo ){ moreToDo = 0; for(i=0; inExpr; i++){ - int iCol; + int iCol = -1; Expr *pE, *pDup; if( pOrderBy->a[i].done ) continue; pE = pOrderBy->a[i].pExpr; pDup = sqlite3ExprDup(db, pE); - if( pDup==0 ){ - return 1; + if( !db->mallocFailed ){ + assert(pDup); + iCol = matchOrderByTermToExprList(pParse, pSelect, pDup, i+1, 1, 0); } - iCol = matchOrderByTermToExprList(pParse, pSelect, pDup, i+1, 1, 0); sqlite3ExprDelete(pDup); if( iCol<0 ){ return 1; } pEList = pSelect->pEList; Index: test/malloc.test ================================================================== --- test/malloc.test +++ test/malloc.test @@ -14,11 +14,11 @@ # 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 $ +# $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. @@ -570,14 +570,22 @@ } -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