1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

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
This commit is contained in:
drh
2006-09-29 14:01:04 +00:00
parent 7cf43fa64e
commit 2564ef9781
4 changed files with 30 additions and 23 deletions

View File

@@ -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) 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-28T19:43:32 D 2006-09-29T14:01:05
F Makefile.in cabd42d34340f49260bc2a7668c38eba8d4cfd99 F Makefile.in cabd42d34340f49260bc2a7668c38eba8d4cfd99
F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -83,7 +83,7 @@ F src/pragma.c 2ef4353448e202961a22312f34695128bbb6d69a
F src/prepare.c 3d9a1bb0644e8bccb3b78cb0833d269719237f4e F src/prepare.c 3d9a1bb0644e8bccb3b78cb0833d269719237f4e
F src/printf.c b179b6ed12f793e028dd169e2e2e2b2a37eedc63 F src/printf.c b179b6ed12f793e028dd169e2e2e2b2a37eedc63
F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261 F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261
F src/select.c 0d4724930a1f34c747105ed1802fa4af0d8eb519 F src/select.c e247a5e1ea64dc3273a165549f0391fde8472f39
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c 1c17cd03c9cc2ff618435156038f508c159ecf12 F src/shell.c 1c17cd03c9cc2ff618435156038f508c159ecf12
F src/sqlite.h.in bf935004029631fd93d119bcf2f7259b9cb9ad5e F src/sqlite.h.in bf935004029631fd93d119bcf2f7259b9cb9ad5e
@@ -233,7 +233,7 @@ F test/memdb.test a67bda4ff90a38f2b19f6c7f95aa7289e051d893
F test/memleak.test df2b2b96e77f8ba159a332299535b1e5f18e49ac F test/memleak.test df2b2b96e77f8ba159a332299535b1e5f18e49ac
F test/minmax.test 66434d8ee04869fe4c220b665b73748accbb9163 F test/minmax.test 66434d8ee04869fe4c220b665b73748accbb9163
F test/misc1.test 27a6ad11ba6e4b73aeee650ab68053ad7dfd0433 F test/misc1.test 27a6ad11ba6e4b73aeee650ab68053ad7dfd0433
F test/misc2.test 9740c2fb7e4a69b2bebd4c5fd9ba45ae27b27e98 F test/misc2.test 0b45deedcfd6ba857ea2f377c5669d3501a535c7
F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03 F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03
F test/misc4.test b043a05dea037cca5989f3ae09552fa16119bc80 F test/misc4.test b043a05dea037cca5989f3ae09552fa16119bc80
F test/misc5.test 83bceca3d38ed10ced00271e02b26b24795def83 F test/misc5.test 83bceca3d38ed10ced00271e02b26b24795def83
@@ -399,7 +399,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 0934d220b33c52024f42c89fa13326bd52333f39 P 8cdf1d6ae018dfc93f8f0962b2530e31aa0bebff
R 105e424a6b1cb9ae66050c731572cf3e R e0824515a1c2aeb5e0fc636e6263bbc4
U drh U drh
Z ffcf097b13ab31485785605d678fc1c5 Z 2aee5ccd57b1e344909056652e85b596

View File

@@ -1 +1 @@
8cdf1d6ae018dfc93f8f0962b2530e31aa0bebff fcde639119c309c699ee9dd60ed60fd6e9c8c077

View File

@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser ** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite. ** 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" #include "sqliteInt.h"
@@ -1071,7 +1071,7 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){
Expr *p, *pR; Expr *p, *pR;
char *zType; char *zType;
char *zName; char *zName;
char *zBasename; int nName;
CollSeq *pColl; CollSeq *pColl;
int cnt; int cnt;
NameContext sNC; 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, /* Make sure the column name is unique. If the name is not unique,
** append a integer to the name so that it becomes unique. ** append a integer to the name so that it becomes unique.
*/ */
zBasename = zName; nName = strlen(zName);
for(j=cnt=0; j<i; j++){ for(j=cnt=0; j<i; j++){
if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){ if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){
zName = sqlite3MPrintf("%s:%d", zBasename, ++cnt); zName[nName] = 0;
zName = sqlite3MPrintf("%z:%d", zName, ++cnt);
j = -1; j = -1;
if( zName==0 ) break; if( zName==0 ) break;
} }
} }
if( zBasename!=zName ){
sqliteFree(zBasename);
}
pCol->zName = zName; pCol->zName = zName;
/* Get the typename, type affinity, and collating sequence for the /* Get the typename, type affinity, and collating sequence for the

View File

@@ -13,7 +13,7 @@
# This file implements tests for miscellanous features that were # This file implements tests for miscellanous features that were
# left out of other test files. # 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] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
@@ -48,14 +48,14 @@ do_test misc2-2.1 {
INSERT INTO t2 VALUES(7,8,9); 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 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 { do_test misc2-2.3 {
execsql { execsql {
CREATE VIEW v1 AS SELECT * FROM t1, t2; CREATE VIEW v1 AS SELECT * FROM t1, t2;
@@ -64,6 +64,15 @@ ifcapable view {
} {{} 1 2 3 7 8 9} } {{} 1 2 3 7 8 9}
} ;# ifcapable view } ;# 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 # Check name binding precedence. Ticket #387
# #
do_test misc2-3.1 { do_test misc2-3.1 {