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:
12
src/select.c
12
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; j<i; j++){
|
||||
if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){
|
||||
zName = sqlite3MPrintf("%s:%d", zBasename, ++cnt);
|
||||
zName[nName] = 0;
|
||||
zName = sqlite3MPrintf("%z:%d", zName, ++cnt);
|
||||
j = -1;
|
||||
if( zName==0 ) break;
|
||||
}
|
||||
}
|
||||
if( zBasename!=zName ){
|
||||
sqliteFree(zBasename);
|
||||
}
|
||||
pCol->zName = zName;
|
||||
|
||||
/* Get the typename, type affinity, and collating sequence for the
|
||||
|
||||
Reference in New Issue
Block a user