From: drh Date: Fri, 29 Sep 2006 14:01:04 +0000 (+0000) Subject: Make sure memory does not leak when patching up column names so that X-Git-Tag: version-3.6.10~2716 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2564ef97816d988203860f776a74ca9da7ad34a6;p=thirdparty%2Fsqlite.git Make sure memory does not leak when patching up column names so that they are unique in a join or view. Tickets #1952 and #2002. (CVS 3451) FossilOrigin-Name: fcde639119c309c699ee9dd60ed60fd6e9c8c077 --- diff --git a/manifest b/manifest index a90c69385c..acb6eab802 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sbug\sin\sthe\shandling\sof\sthe\sOR\soperator\sin\sFTS1.\s\sTest\scases\sadded\sto\nprevent\sa\srepeat.\s(CVS\s3450) -D 2006-09-28T19:43:32 +C Make\ssure\smemory\sdoes\snot\sleak\swhen\spatching\sup\scolumn\snames\sso\sthat\nthey\sare\sunique\sin\sa\sjoin\sor\sview.\s\sTickets\s#1952\sand\s#2002.\s(CVS\s3451) +D 2006-09-29T14:01:05 F Makefile.in cabd42d34340f49260bc2a7668c38eba8d4cfd99 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -83,7 +83,7 @@ F src/pragma.c 2ef4353448e202961a22312f34695128bbb6d69a F src/prepare.c 3d9a1bb0644e8bccb3b78cb0833d269719237f4e F src/printf.c b179b6ed12f793e028dd169e2e2e2b2a37eedc63 F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261 -F src/select.c 0d4724930a1f34c747105ed1802fa4af0d8eb519 +F src/select.c e247a5e1ea64dc3273a165549f0391fde8472f39 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96 F src/shell.c 1c17cd03c9cc2ff618435156038f508c159ecf12 F src/sqlite.h.in bf935004029631fd93d119bcf2f7259b9cb9ad5e @@ -233,7 +233,7 @@ F test/memdb.test a67bda4ff90a38f2b19f6c7f95aa7289e051d893 F test/memleak.test df2b2b96e77f8ba159a332299535b1e5f18e49ac F test/minmax.test 66434d8ee04869fe4c220b665b73748accbb9163 F test/misc1.test 27a6ad11ba6e4b73aeee650ab68053ad7dfd0433 -F test/misc2.test 9740c2fb7e4a69b2bebd4c5fd9ba45ae27b27e98 +F test/misc2.test 0b45deedcfd6ba857ea2f377c5669d3501a535c7 F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03 F test/misc4.test b043a05dea037cca5989f3ae09552fa16119bc80 F test/misc5.test 83bceca3d38ed10ced00271e02b26b24795def83 @@ -399,7 +399,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 0934d220b33c52024f42c89fa13326bd52333f39 -R 105e424a6b1cb9ae66050c731572cf3e +P 8cdf1d6ae018dfc93f8f0962b2530e31aa0bebff +R e0824515a1c2aeb5e0fc636e6263bbc4 U drh -Z ffcf097b13ab31485785605d678fc1c5 +Z 2aee5ccd57b1e344909056652e85b596 diff --git a/manifest.uuid b/manifest.uuid index fe39979038..afa6e27615 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8cdf1d6ae018dfc93f8f0962b2530e31aa0bebff \ No newline at end of file +fcde639119c309c699ee9dd60ed60fd6e9c8c077 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 25fe010b22..38dcf97488 100644 --- a/src/select.c +++ b/src/select.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.320 2006/08/11 19:08:27 drh Exp $ +** $Id: select.c,v 1.321 2006/09/29 14:01:05 drh Exp $ */ #include "sqliteInt.h" @@ -1071,7 +1071,7 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){ Expr *p, *pR; char *zType; char *zName; - char *zBasename; + int nName; CollSeq *pColl; int cnt; NameContext sNC; @@ -1104,17 +1104,15 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){ /* Make sure the column name is unique. If the name is not unique, ** append a integer to the name so that it becomes unique. */ - zBasename = zName; + nName = strlen(zName); for(j=cnt=0; jzName = zName; /* Get the typename, type affinity, and collating sequence for the diff --git a/test/misc2.test b/test/misc2.test index 44cb47d58e..1eaf62e379 100644 --- a/test/misc2.test +++ b/test/misc2.test @@ -13,7 +13,7 @@ # This file implements tests for miscellanous features that were # left out of other test files. # -# $Id: misc2.test,v 1.25 2006/08/16 16:42:48 drh Exp $ +# $Id: misc2.test,v 1.26 2006/09/29 14:01:07 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -48,14 +48,14 @@ do_test misc2-2.1 { INSERT INTO t2 VALUES(7,8,9); } } {} +ifcapable subquery { + do_test misc2-2.2 { + execsql { + SELECT rowid, * FROM (SELECT * FROM t1, t2); + } + } {{} 1 2 3 7 8 9} +} ifcapable view { - ifcapable subquery { - do_test misc2-2.2 { - execsql { - SELECT rowid, * FROM (SELECT * FROM t1, t2); - } - } {{} 1 2 3 7 8 9} - } do_test misc2-2.3 { execsql { CREATE VIEW v1 AS SELECT * FROM t1, t2; @@ -64,6 +64,15 @@ ifcapable view { } {{} 1 2 3 7 8 9} } ;# ifcapable view +# Ticket #2002 and #1952. +ifcapable subquery { + do_test misc2-2.4 { + execsql2 { + SELECT * FROM (SELECT a, b AS 'a', c AS 'a', 4 AS 'a' FROM t1) + } + } {a 1 a:1 2 a:2 3 a:3 4} +} + # Check name binding precedence. Ticket #387 # do_test misc2-3.1 {