1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Handle transient malloc() failures in sqlite3CreateFunc(). (CVS 4371)

FossilOrigin-Name: c0ce63196458c81e0859fc8a38f2dd2145a580bc
This commit is contained in:
danielk1977
2007-09-03 11:04:22 +00:00
parent 369ff42e77
commit fa18bece7a
8 changed files with 75 additions and 38 deletions

View File

@ -1,5 +1,5 @@
C Fixes\sto\stest\scode\sso\sthat\sthe\stest\ssuite\spasses\swithout\sSQLITE_MEMDEBUG\sdefined.\s(CVS\s4370) C Handle\stransient\smalloc()\sfailures\sin\ssqlite3CreateFunc().\s(CVS\s4371)
D 2007-09-03T07:31:10 D 2007-09-03T11:04:22
F Makefile.in bfcc303429a5d9dcd552d807ee016c77427418c3 F Makefile.in bfcc303429a5d9dcd552d807ee016c77427418c3
F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499 F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -91,7 +91,7 @@ F src/date.c af235f38f50809abd0a96da3bb3e0cc32be6226e
F src/delete.c 849846d06d29851dde0d9f424a5de5817eb140d1 F src/delete.c 849846d06d29851dde0d9f424a5de5817eb140d1
F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
F src/expr.c 7853a8161ec0b0fce62fc8da921db557899f1ec1 F src/expr.c 7853a8161ec0b0fce62fc8da921db557899f1ec1
F src/func.c 7c59882c72b2a2b7bf5a2e121f0727e7527bf7cd F src/func.c 9d88141c4cffb3a04719e5a0fda65cde34bfa1e5
F src/hash.c 8fe2fa52bd17869c87748e42cff5b1e7fbf90822 F src/hash.c 8fe2fa52bd17869c87748e42cff5b1e7fbf90822
F src/hash.h 3ad3da76bfb954978d227bf495568b0e6da2c19e F src/hash.h 3ad3da76bfb954978d227bf495568b0e6da2c19e
F src/insert.c b11e5ca0d68bf2a7a56f47a052a0ee67dd4e2f89 F src/insert.c b11e5ca0d68bf2a7a56f47a052a0ee67dd4e2f89
@ -99,7 +99,7 @@ F src/journal.c 63f8a40827e871997272eb2598f5cd9e66aa0947
F src/legacy.c 4ac53191fad2e3c4d59bde1228879b2dc5a96d66 F src/legacy.c 4ac53191fad2e3c4d59bde1228879b2dc5a96d66
F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35 F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35
F src/loadext.c 6894dbbf1666577d957922811620375d6c2f058d F src/loadext.c 6894dbbf1666577d957922811620375d6c2f058d
F src/main.c c271d9104b6bff13d2ddd9a72fcf0926e635a9fd F src/main.c 04191005169375a45a8ef2afe9596d3bda8194b2
F src/malloc.c de4e77fe70a9a0ac47a1c3a874422b107231bf31 F src/malloc.c de4e77fe70a9a0ac47a1c3a874422b107231bf31
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217 F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/mem1.c 1f85902b98b38bd8a8b0c24012933957256db13e F src/mem1.c 1f85902b98b38bd8a8b0c24012933957256db13e
@ -136,7 +136,7 @@ F src/sqliteInt.h adc8a20e80ccf9eef24cc32f241a3427915a136e
F src/sqliteLimit.h 1bcbbdfa856f8b71b561abb31edb864b0eca1d12 F src/sqliteLimit.h 1bcbbdfa856f8b71b561abb31edb864b0eca1d12
F src/table.c 1aeb9eab57b4235db86fe15a35dec76fb445a9c4 F src/table.c 1aeb9eab57b4235db86fe15a35dec76fb445a9c4
F src/tclsqlite.c 8db035768623779c97d0509eb88ecbb49c51abca F src/tclsqlite.c 8db035768623779c97d0509eb88ecbb49c51abca
F src/test1.c f43580b00e3f764015acd52892690ee4f28ce775 F src/test1.c 6103787d839c2056a42b88082b53d0b79f62285d
F src/test2.c 4ab230fbdc0decfa7422f6a052b609ba54f4dfac F src/test2.c 4ab230fbdc0decfa7422f6a052b609ba54f4dfac
F src/test3.c 199a440ba2b38b26251393b609451a3484a15907 F src/test3.c 199a440ba2b38b26251393b609451a3484a15907
F src/test4.c c2c0f5dc907f1346f5d4b65eb5799f11eb9e4071 F src/test4.c c2c0f5dc907f1346f5d4b65eb5799f11eb9e4071
@ -302,7 +302,7 @@ F test/fts3an.test 2da4df52fe8ea8389f6fa7a01e4c1a0f091118d6
F test/fts3ao.test 0aa29dd4fc1c8d46b1f7cfe5926f7ac97551bea9 F test/fts3ao.test 0aa29dd4fc1c8d46b1f7cfe5926f7ac97551bea9
F test/fts3atoken.test 25c2070e1e8755d414bf9c8200427b277a9f99fa F test/fts3atoken.test 25c2070e1e8755d414bf9c8200427b277a9f99fa
F test/fts3b.test 94cd8a2fb709c99c1617df01f6908de77892d8bc F test/fts3b.test 94cd8a2fb709c99c1617df01f6908de77892d8bc
F test/func.test 605989453d1b42cec1d05c17aa232dc98e3e04e6 F test/func.test 71b39d44a0dffe123145b7c2973e8c4fb8a67ffd
F test/fuzz.test 62fc19dd36a427777fd671b569df07166548628a F test/fuzz.test 62fc19dd36a427777fd671b569df07166548628a
F test/fuzz2.test ea38692ce2da99ad79fe0be5eb1a452c1c4d37bb F test/fuzz2.test ea38692ce2da99ad79fe0be5eb1a452c1c4d37bb
F test/fuzz_common.tcl ff4bc2dfc465f6878f8e2d819620914365382731 F test/fuzz_common.tcl ff4bc2dfc465f6878f8e2d819620914365382731
@ -345,11 +345,11 @@ F test/lock2.test 5f9557b775662c2a5ee435378f39e10d64f65cb3
F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9 F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9
F test/lock4.test 49e22396b9be6e047b3d35469f233be79153c9d5 F test/lock4.test 49e22396b9be6e047b3d35469f233be79153c9d5
F test/main.test 913427b847c6cfba055c9d0629f7479f51ba1a48 F test/main.test 913427b847c6cfba055c9d0629f7479f51ba1a48
F test/malloc.test 52306f056e7359e68ed2e204f37f47a0e2020c57 F test/malloc.test bb1c95fb536cfefd3a5b4ce8ca1d4c99e73b1e33
F test/malloc2.test c1a74f46a3581b56df29ff46a4e1c99b41c44ad9 F test/malloc2.test c1a74f46a3581b56df29ff46a4e1c99b41c44ad9
F test/malloc3.test 39b72b04436a81e0c3d548d195f8bdbf1ebf4b52 F test/malloc3.test 39b72b04436a81e0c3d548d195f8bdbf1ebf4b52
F test/malloc4.test 2691bdd25fc764449051b2098692e739555246a7 F test/malloc4.test 2691bdd25fc764449051b2098692e739555246a7
F test/malloc5.test 9db9205a5d444e23043368f961f92641c7770199 F test/malloc5.test 4ff75206deb43120a6fc686220db13b45b9f76c7
F test/malloc6.test 3733b9bd4e039c3239f869c40edbb88172025e2e F test/malloc6.test 3733b9bd4e039c3239f869c40edbb88172025e2e
F test/malloc7.test dd66d8f82916becf1d29b6640e4f4855485570f8 F test/malloc7.test dd66d8f82916becf1d29b6640e4f4855485570f8
F test/malloc8.test 5ff95278bc73e815e295971afcdd175f6ba19258 F test/malloc8.test 5ff95278bc73e815e295971afcdd175f6ba19258
@ -568,7 +568,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P 4a9999a36d01a8c6490792605a6f7e233cc4402c P ed2a2e0102c4fd2221096028d55a6f1d54f97274
R 7d21bfe5332f51fbfd47107d9eb37c68 R a8071f6051ea0c2f23cdc36ae305ef4b
U danielk1977 U danielk1977
Z 34ef56b14cc4c07e252ab613eb7ad3cf Z fb15b228bac149e738b86ec4993bbe7d

View File

@ -1 +1 @@
ed2a2e0102c4fd2221096028d55a6f1d54f97274 c0ce63196458c81e0859fc8a38f2dd2145a580bc

View File

@ -16,7 +16,7 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope. ** All other code has file scope.
** **
** $Id: func.c,v 1.173 2007/09/01 17:00:13 danielk1977 Exp $ ** $Id: func.c,v 1.174 2007/09/03 11:04:22 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <ctype.h> #include <ctype.h>
@ -1133,17 +1133,17 @@ static void test_auxdata(
if( zAux ){ if( zAux ){
zRet[i*2] = '1'; zRet[i*2] = '1';
if( strcmp(zAux, z) ){ if( strcmp(zAux, z) ){
free_test_auxdata((void *)zRet);
sqlite3_result_error(pCtx, "Auxilary data corruption", -1); sqlite3_result_error(pCtx, "Auxilary data corruption", -1);
return; return;
} }
}else{ }else {
zRet[i*2] = '0'; zRet[i*2] = '0';
zAux = contextMalloc(pCtx, strlen(z)+1); }
if( zAux ){
strcpy(zAux, z); zAux = contextMalloc(pCtx, strlen(z)+1);
sqlite3_set_auxdata(pCtx, i, zAux, free_test_auxdata); if( zAux ){
} strcpy(zAux, z);
sqlite3_set_auxdata(pCtx, i, zAux, free_test_auxdata);
} }
zRet[i*2+1] = ' '; zRet[i*2+1] = ' ';
} }

View File

@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be ** other files are for internal use by SQLite and should not be
** accessed by users of the library. ** accessed by users of the library.
** **
** $Id: main.c,v 1.402 2007/09/01 06:51:28 danielk1977 Exp $ ** $Id: main.c,v 1.403 2007/09/03 11:04:22 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <ctype.h> #include <ctype.h>
@ -511,14 +511,16 @@ int sqlite3CreateFunc(
} }
p = sqlite3FindFunction(db, zFunctionName, nName, nArg, enc, 1); p = sqlite3FindFunction(db, zFunctionName, nName, nArg, enc, 1);
if( p ){ assert(p || db->mallocFailed);
p->flags = 0; if( !p ){
p->xFunc = xFunc; return SQLITE_NOMEM;
p->xStep = xStep;
p->xFinalize = xFinal;
p->pUserData = pUserData;
p->nArg = nArg;
} }
p->flags = 0;
p->xFunc = xFunc;
p->xStep = xStep;
p->xFinalize = xFinal;
p->pUserData = pUserData;
p->nArg = nArg;
return SQLITE_OK; return SQLITE_OK;
} }

View File

@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated ** is not included in the SQLite library. It is used for automated
** testing of the SQLite library. ** testing of the SQLite library.
** **
** $Id: test1.c,v 1.274 2007/09/01 11:04:26 danielk1977 Exp $ ** $Id: test1.c,v 1.275 2007/09/03 11:04:22 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "tcl.h" #include "tcl.h"
@ -1012,12 +1012,24 @@ static void t1CountFinalize(sqlite3_context *context){
} }
} }
static void legacyCountStep(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
/* no-op */
}
static void legacyCountFinalize(sqlite3_context *context){
sqlite3_result_int(context, sqlite3_aggregate_count(context));
}
/* /*
** Usage: sqlite_test_create_aggregate DB ** Usage: sqlite3_create_aggregate DB
** **
** Call the sqlite3_create_function API on the given database in order ** Call the sqlite3_create_function API on the given database in order
** to create a function named "x_count". This function does the same thing ** to create a function named "x_count". This function is similar
** as the "md5sum" function. ** to the built-in count() function, with a few special quirks
** for testing the sqlite3_result_error() APIs.
** **
** The original motivation for this routine was to be able to call the ** The original motivation for this routine was to be able to call the
** sqlite3_create_aggregate function while a query is in progress in order ** sqlite3_create_aggregate function while a query is in progress in order
@ -1025,6 +1037,10 @@ static void t1CountFinalize(sqlite3_context *context){
** **
** This routine was later extended to test the use of sqlite3_result_error() ** This routine was later extended to test the use of sqlite3_result_error()
** within aggregate functions. ** within aggregate functions.
**
** Later: It is now also extended to register the aggregate function
** "legacy_count()" with the supplied database handle. This is used
** to test the deprecated sqlite3_aggregate_count() API.
*/ */
static int test_create_aggregate( static int test_create_aggregate(
void *NotUsed, void *NotUsed,
@ -1043,10 +1059,16 @@ static int test_create_aggregate(
rc = sqlite3_create_function(db, "x_count", 0, SQLITE_UTF8, 0, 0, rc = sqlite3_create_function(db, "x_count", 0, SQLITE_UTF8, 0, 0,
t1CountStep,t1CountFinalize); t1CountStep,t1CountFinalize);
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
sqlite3_create_function(db, "x_count", 1, SQLITE_UTF8, 0, 0, rc = sqlite3_create_function(db, "x_count", 1, SQLITE_UTF8, 0, 0,
t1CountStep,t1CountFinalize); t1CountStep,t1CountFinalize);
} }
if( rc==SQLITE_OK ){
rc = sqlite3_create_function(db, "legacy_count", 0, SQLITE_ANY, 0, 0,
legacyCountStep, legacyCountFinalize
);
}
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR; if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0);
return TCL_OK; return TCL_OK;
} }

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The # This file implements regression tests for SQLite library. The
# focus of this file is testing built-in functions. # focus of this file is testing built-in functions.
# #
# $Id: func.test,v 1.67 2007/05/15 18:35:21 drh Exp $ # $Id: func.test,v 1.68 2007/09/03 11:04:22 danielk1977 Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@ -870,4 +870,13 @@ do_test func-22.22 {
execsql {SELECT typeof(trim('hello',NULL));} execsql {SELECT typeof(trim('hello',NULL));}
} {null} } {null}
# This is to test the deprecated sqlite3_aggregate_count() API.
#
do_test func-23.1 {
sqlite3_create_aggregate db
execsql {
SELECT legacy_count() FROM t6;
}
} {3}
finish_test finish_test

View File

@ -16,7 +16,7 @@
# to see what happens in the library if a malloc were to really fail # to see what happens in the library if a malloc were to really fail
# due to an out-of-memory situation. # due to an out-of-memory situation.
# #
# $Id: malloc.test,v 1.45 2007/08/29 12:31:29 danielk1977 Exp $ # $Id: malloc.test,v 1.46 2007/09/03 11:04:22 danielk1977 Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@ -259,6 +259,9 @@ do_malloc_test 10 -sqlprep {
# sqlite3_create_function(). # sqlite3_create_function().
do_malloc_test 11 -tclbody { do_malloc_test 11 -tclbody {
set rc [sqlite3_create_function db] set rc [sqlite3_create_function db]
if {[string match $rc SQLITE_OK]} {
set rc [sqlite3_create_aggregate db]
}
if {[string match $rc SQLITE_NOMEM]} { if {[string match $rc SQLITE_NOMEM]} {
error "out of memory" error "out of memory"
} }

View File

@ -12,7 +12,7 @@
# This file contains test cases focused on the two memory-management APIs, # This file contains test cases focused on the two memory-management APIs,
# sqlite3_soft_heap_limit() and sqlite3_release_memory(). # sqlite3_soft_heap_limit() and sqlite3_release_memory().
# #
# $Id: malloc5.test,v 1.14 2007/08/28 08:00:18 danielk1977 Exp $ # $Id: malloc5.test,v 1.15 2007/09/03 11:04:22 danielk1977 Exp $
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# NOTES ON EXPECTED BEHAVIOUR # NOTES ON EXPECTED BEHAVIOUR
@ -298,8 +298,9 @@ do_test malloc5-6.1.1 {
} }
copy_file test.db test2.db copy_file test.db test2.db
sqlite3 db2 test2.db sqlite3 db2 test2.db
list [expr [file size test.db]/1024] [expr [file size test2.db]/1024] list \
} {23 23} [expr ([file size test.db]/1024)>20] [expr ([file size test2.db]/1024)>20]
} {1 1}
do_test malloc5-6.1.2 { do_test malloc5-6.1.2 {
list [execsql {PRAGMA cache_size}] [execsql {PRAGMA cache_size} db2] list [execsql {PRAGMA cache_size}] [execsql {PRAGMA cache_size} db2]
} {10 10} } {10 10}