From 6103fe972e84561a3dedf1f3bb37df266fde6487 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 5 Apr 2006 11:57:37 +0000 Subject: [PATCH] Make sure SQLITE_NOMEM is reported out on a malloc failure in an ATTACH even if the malloc failure reports within a nested calls to sqlite3_prepare(). (CVS 3164) FossilOrigin-Name: 3538a4e30fb5131b461bb0cf72cada63e9724e14 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/attach.c | 9 +++++++-- test/malloc.test | 22 +++++++++++++++++++++- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 64d8282d86..b8cb7519f8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sdocumentation\son\snew\ssqlite_authorizer\scallback\stypes.\sTicket\s#1744.\s(CVS\s3163) -D 2006-04-05T01:08:35 +C Make\ssure\sSQLITE_NOMEM\sis\sreported\sout\son\sa\smalloc\sfailure\sin\san\sATTACH\neven\sif\sthe\smalloc\sfailure\sreports\swithin\sa\snested\scalls\sto\ssqlite3_prepare().\s(CVS\s3164) +D 2006-04-05T11:57:37 F Makefile.in 5d8dff443383918b700e495de42ec65bc1c8865b F Makefile.linux-gcc 74ba0eadf88748a9ce3fd03d2a3ede2e6715baec F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -32,7 +32,7 @@ F sqlite3.def f756049b1bf3e8442baf6862db393ca423225262 F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a F src/alter.c 451b34fc4eb2475ca76a2e86b21e1030a9428091 F src/analyze.c 7d2b7ab9a9c2fd6e55700f69064dfdd3e36d7a8a -F src/attach.c d73a3505de3fb9e373d0a158978116c4212031d0 +F src/attach.c 514f90623c891143846625afcab409d6b4986565 F src/auth.c 9ae84d2d94eb96195e04515715e08e85963e96c2 F src/btree.c ed343b3dbcbc7da9ac481ef2b98c4239fe6d9629 F src/btree.h 40055cfc09defd1146bc5b922399c035f969e56d @@ -191,7 +191,7 @@ F test/lock.test 9b7afcb24f53d24da502abb33daaad2cd6d44107 F test/lock2.test d83ba79d3c4fffdb5b926c7d8ca7a36c34288a55 F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9 F test/main.test e7212ce1023957c7209778cc87fa932bd79ba89a -F test/malloc.test 7d875b2b59ae1d79fba71403298a1eb4a1ed7c38 +F test/malloc.test 8580d8fe1f5e78e4ddbe07530e7a5d4ee36aac8f F test/malloc2.test e6e321db96d6c94cb18bf82ad7215070c41e624e F test/malloc3.test fd4186bee73c2a2638f4e2a05a684c06836f725b F test/malloc4.test 59cd02f71b363302a04c4e77b97c0a1572eaa210 @@ -355,7 +355,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 51b35ace203a33f6f04f1139ca8ab652c5c76f9a -R 37db2ed2a2f394b32b2c98ec1c3f61dd +P fdbff3f145296d5dcba8987c25629e27353e2ab0 +R a178117f13217df6aee4e3891a129fac U drh -Z bea39b4c4681bce541ac61af0db836c7 +Z 43dddd673d1c73ea60cfe59bfb56a0fc diff --git a/manifest.uuid b/manifest.uuid index cb159aa223..8f8062d8d9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fdbff3f145296d5dcba8987c25629e27353e2ab0 \ No newline at end of file +3538a4e30fb5131b461bb0cf72cada63e9724e14 \ No newline at end of file diff --git a/src/attach.c b/src/attach.c index c66b212d16..318ffa5088 100644 --- a/src/attach.c +++ b/src/attach.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the ATTACH and DETACH commands. ** -** $Id: attach.c,v 1.49 2006/01/24 12:09:18 danielk1977 Exp $ +** $Id: attach.c,v 1.50 2006/04/05 11:57:37 drh Exp $ */ #include "sqliteInt.h" @@ -185,7 +185,12 @@ static void attachFunc( } sqlite3ResetInternalSchema(db, 0); db->nDb = iDb; - sqlite3_snprintf(127, zErr, "unable to open database: %s", zFile); + if( rc==SQLITE_NOMEM ){ + sqlite3MallocFailed(); + sqlite3_snprintf(127, zErr, "out of memory"); + }else{ + sqlite3_snprintf(127, zErr, "unable to open database: %s", zFile); + } goto attach_error; } diff --git a/test/malloc.test b/test/malloc.test index cbeef245de..2067b5b021 100644 --- a/test/malloc.test +++ b/test/malloc.test @@ -14,7 +14,7 @@ # 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.30 2006/01/24 10:58:23 danielk1977 Exp $ +# $Id: malloc.test,v 1.31 2006/04/05 11:57:37 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -513,6 +513,26 @@ do_malloc_test 19 -tclprep { } unset static_string +# Make sure SQLITE_NOMEM is reported out on an ATTACH failure even +# when the malloc failure occurs within the nested parse. +# +do_malloc_test 20 -tclprep { + db close + file delete -force test2.db test2.db-journal + sqlite3 db test2.db + db eval {CREATE TABLE t1(x);} + db close +} -tclbody { + if {[catch {sqlite3 db test.db}]} { + error "out of memory" + } +} -sqlbody { + ATTACH DATABASE 'test2.db' AS t2; + SELECT * FROM t1; + DETACH DATABASE t2; +} + + # Ensure that no file descriptors were leaked. do_test malloc-99.X { catch {db close} -- 2.47.2