Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Fix a bug whereby sqlite3_prepare_v2() could return both an out-of-memory error and a valid statement handle. (CVS 3858) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
8795d11c3c5bb39d34bc5194621ce970 |
User & Date: | danielk1977 2007-04-19 11:09:01.000 |
Context
2007-04-19
| ||
12:30 | Comment changes in the ioerr tests. No changes to code. (CVS 3859) (check-in: b7ed0e1e88 user: drh tags: trunk) | |
11:09 | Fix a bug whereby sqlite3_prepare_v2() could return both an out-of-memory error and a valid statement handle. (CVS 3858) (check-in: 8795d11c3c user: danielk1977 tags: trunk) | |
00:24 | Get the build working with SQLITE_OMIT_SHARED_CACHE. Ticket #2307. (CVS 3857) (check-in: b623538c55 user: drh tags: trunk) | |
Changes
Changes to src/prepare.c.
︙ | ︙ | |||
9 10 11 12 13 14 15 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains the implementation of the sqlite3_prepare() ** interface, and routines that contribute to loading the database schema ** from disk. ** | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains the implementation of the sqlite3_prepare() ** interface, and routines that contribute to loading the database schema ** from disk. ** ** $Id: prepare.c,v 1.46 2007/04/19 11:09:01 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" #include <ctype.h> /* ** Fill the InitData structure with an error message that indicates |
︙ | ︙ | |||
533 534 535 536 537 538 539 | } } #endif if( sqlite3SafetyOff(db) ){ rc = SQLITE_MISUSE; } | | | | | > | > | | | 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | } } #endif if( sqlite3SafetyOff(db) ){ rc = SQLITE_MISUSE; } if( saveSqlFlag ){ sqlite3VdbeSetSql(sParse.pVdbe, zSql, sParse.zTail - zSql); } if( rc!=SQLITE_OK || sqlite3MallocFailed() ){ sqlite3_finalize((sqlite3_stmt*)sParse.pVdbe); assert(!(*ppStmt)); }else{ *ppStmt = (sqlite3_stmt*)sParse.pVdbe; } if( zErrMsg ){ sqlite3Error(db, rc, "%s", zErrMsg); sqliteFree(zErrMsg); }else{ sqlite3Error(db, rc, 0); |
︙ | ︙ |
Changes to src/test1.c.
︙ | ︙ | |||
9 10 11 12 13 14 15 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** Code for testing all sorts of SQLite interfaces. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** Code for testing all sorts of SQLite interfaces. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** ** $Id: test1.c,v 1.238 2007/04/19 11:09:02 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" #include "os.h" #include <stdlib.h> #include <string.h> |
︙ | ︙ | |||
2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 | return TCL_ERROR; } if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; zSql = Tcl_GetString(objv[2]); if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR; rc = sqlite3_prepare_v2(db, zSql, bytes, &pStmt, &zTail); if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; if( zTail ){ if( bytes>=0 ){ bytes = bytes - (zTail-zSql); } Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0); } | > | 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 | return TCL_ERROR; } if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; zSql = Tcl_GetString(objv[2]); if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR; rc = sqlite3_prepare_v2(db, zSql, bytes, &pStmt, &zTail); assert(rc==SQLITE_OK || pStmt==0); if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; if( zTail ){ if( bytes>=0 ){ bytes = bytes - (zTail-zSql); } Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0); } |
︙ | ︙ |
Changes to test/malloc.test.
︙ | ︙ | |||
10 11 12 13 14 15 16 | #*********************************************************************** # 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. # | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #*********************************************************************** # 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.41 2007/04/19 11:09:02 danielk1977 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]==""} { |
︙ | ︙ | |||
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | } # Test malloc failure whilst installing a foreign key. # do_malloc_test 21 -sqlbody { CREATE TABLE abc(a, b, c, FOREIGN KEY(a) REFERENCES abc(b)) } # 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 sqlite_malloc_fail 0 finish_test | > > > > > > > > > > > > > > > > > | 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | } # Test malloc failure whilst installing a foreign key. # do_malloc_test 21 -sqlbody { CREATE TABLE abc(a, b, c, FOREIGN KEY(a) REFERENCES abc(b)) } # Test malloc failure in an sqlite3_prepare_v2() call. # do_malloc_test 22 -tclbody { set ::STMT "" set r [catch { set ::STMT [ sqlite3_prepare_v2 $::DB "SELECT * FROM sqlite_master" -1 DUMMY ] } msg] if {$r} {error [string range $msg 4 end]} } -cleanup { if {$::STMT ne ""} { sqlite3_finalize $::STMT set ::STMT "" } } # 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 sqlite_malloc_fail 0 finish_test |
Changes to test/vtab_err.test.
1 2 3 4 5 6 7 8 9 10 11 | # 2006 June 10 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # 2006 June 10 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # # $Id: vtab_err.test,v 1.5 2007/04/19 11:09:02 danielk1977 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]==""} { |
︙ | ︙ | |||
141 142 143 144 145 146 147 | COMMIT; BEGIN; CREATE TABLE r2(a, b, c); INSERT INTO r2 SELECT * FROM e; INSERT INTO e SELECT a||'x', b, c FROM r2; COMMIT; } | < | 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | COMMIT; BEGIN; CREATE TABLE r2(a, b, c); INSERT INTO r2 SELECT * FROM e; INSERT INTO e SELECT a||'x', b, c FROM r2; COMMIT; } do_malloc_test vtab_err-2 -tclprep { register_echo_module [sqlite3_connection_pointer db] } -sqlbody { BEGIN; CREATE TABLE r(a PRIMARY KEY, b, c); CREATE VIRTUAL TABLE e USING echo(r); |
︙ | ︙ |