1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-19 21:43:15 +03:00

Fix a memory leak on ORDER BY of a compound select caused by the resolver

on a flattened query.  Also fix a OOM segfault in WHERE clause processing. (CVS 5801)

FossilOrigin-Name: d2c252d6bbde4ae14da6c9e6c2683d763d11c59f
This commit is contained in:
drh
2008-10-11 16:47:35 +00:00
parent 4150ebf86f
commit 10fe840e4d
6 changed files with 30 additions and 23 deletions

View File

@@ -12,7 +12,7 @@
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.398 2008/10/07 19:53:14 drh Exp $
** $Id: expr.c,v 1.399 2008/10/11 16:47:36 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -601,16 +601,24 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
}
/*
** Recursively delete an expression tree.
** Clear an expression structure without deleting the structure itself.
** Substructure is deleted.
*/
void sqlite3ExprDelete(sqlite3 *db, Expr *p){
if( p==0 ) return;
void sqlite3ExprClear(sqlite3 *db, Expr *p){
if( p->span.dyn ) sqlite3DbFree(db, (char*)p->span.z);
if( p->token.dyn ) sqlite3DbFree(db, (char*)p->token.z);
sqlite3ExprDelete(db, p->pLeft);
sqlite3ExprDelete(db, p->pRight);
sqlite3ExprListDelete(db, p->pList);
sqlite3SelectDelete(db, p->pSelect);
}
/*
** Recursively delete an expression tree.
*/
void sqlite3ExprDelete(sqlite3 *db, Expr *p){
if( p==0 ) return;
sqlite3ExprClear(db, p);
sqlite3DbFree(db, p);
}

View File

@@ -14,7 +14,7 @@
** resolve all identifiers by associating them with a particular
** table and column.
**
** $Id: resolve.c,v 1.8 2008/10/10 04:34:16 shane Exp $
** $Id: resolve.c,v 1.9 2008/10/11 16:47:36 drh Exp $
*/
#include "sqliteInt.h"
#include <stdlib.h>
@@ -77,8 +77,7 @@ static void resolveAlias(
pDup->pColl = pExpr->pColl;
pDup->flags |= EP_ExpCollate;
}
if( pExpr->span.dyn ) sqlite3DbFree(db, (char*)pExpr->span.z);
if( pExpr->token.dyn ) sqlite3DbFree(db, (char*)pExpr->token.z);
sqlite3ExprClear(db, pExpr);
memcpy(pExpr, pDup, sizeof(*pExpr));
sqlite3DbFree(db, pDup);
}

View File

@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.781 2008/10/10 18:25:46 shane Exp $
** @(#) $Id: sqliteInt.h,v 1.782 2008/10/11 16:47:36 drh Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
@@ -2100,6 +2100,7 @@ Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
void sqlite3ExprSpan(Expr*,Token*,Token*);
Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
void sqlite3ExprAssignVarNumber(Parse*, Expr*);
void sqlite3ExprClear(sqlite3*, Expr*);
void sqlite3ExprDelete(sqlite3*, Expr*);
ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*,Token*);
void sqlite3ExprListDelete(sqlite3*, ExprList*);

View File

@@ -16,7 +16,7 @@
** so is applicable. Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
**
** $Id: where.c,v 1.325 2008/10/07 23:46:38 drh Exp $
** $Id: where.c,v 1.326 2008/10/11 16:47:36 drh Exp $
*/
#include "sqliteInt.h"
@@ -1931,10 +1931,9 @@ static int nQPlan = 0; /* Next free slow in _query_plan[] */
/*
** Free a WhereInfo structure
*/
static void whereInfoFree(WhereInfo *pWInfo){
static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
if( pWInfo ){
int i;
sqlite3 *db = pWInfo->pParse->db;
for(i=0; i<pWInfo->nLevel; i++){
sqlite3_index_info *pInfo = pWInfo->a[i].pIdxInfo;
if( pInfo ){
@@ -2812,7 +2811,7 @@ WhereInfo *sqlite3WhereBegin(
/* Jump here if malloc fails */
whereBeginError:
whereClauseClear(&wc);
whereInfoFree(pWInfo);
whereInfoFree(db, pWInfo);
return 0;
}
@@ -2926,6 +2925,6 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
/* Final cleanup
*/
whereInfoFree(pWInfo);
whereInfoFree(db, pWInfo);
return;
}