Fix memory leaks in WHERE clause processing and in TRIGGER parsing. (CVS 3775)

FossilOrigin-Name: 6736f4547c0cc2123d1a19ed2d6915712718d22e
This commit is contained in:
drh
2007-03-31 01:34:44 +00:00
parent 331e8d6216
commit b63a53dcf7
4 changed files with 23 additions and 12 deletions
+4 -1
View File
@@ -413,7 +413,10 @@ TriggerStep *sqlite3TriggerUpdateStep(
*/
TriggerStep *sqlite3TriggerDeleteStep(Token *pTableName, Expr *pWhere){
TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
if( pTriggerStep==0 ) return 0;
if( pTriggerStep==0 ){
sqlite3ExprDelete(pWhere);
return 0;
}
pTriggerStep->op = TK_DELETE;
pTriggerStep->target = *pTableName;
+11 -3
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.244 2007/03/30 14:56:35 danielk1977 Exp $
** $Id: where.c,v 1.245 2007/03/31 01:34:45 drh Exp $
*/
#include "sqliteInt.h"
@@ -220,6 +220,9 @@ static void whereClauseClear(WhereClause *pWC){
** Add a new entries to the WhereClause structure. Increase the allocated
** space as necessary.
**
** If the flags argument includes TERM_DYNAMIC, then responsibility
** for freeing the expression p is assumed by the WhereClause object.
**
** WARNING: This routine might reallocate the space used to store
** WhereTerms. All pointers to WhereTerms should be invalided after
** calling this routine. Such pointers may be reinitialized by referencing
@@ -231,7 +234,12 @@ static int whereClauseInsert(WhereClause *pWC, Expr *p, int flags){
if( pWC->nTerm>=pWC->nSlot ){
WhereTerm *pOld = pWC->a;
pWC->a = sqliteMalloc( sizeof(pWC->a[0])*pWC->nSlot*2 );
if( pWC->a==0 ) return 0;
if( pWC->a==0 ){
if( flags & TERM_DYNAMIC ){
sqlite3ExprDelete(p);
}
return 0;
}
memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm);
if( pOld!=pWC->aStatic ){
sqliteFree(pOld);
@@ -734,7 +742,7 @@ static void exprAnalyze(
int idxNew;
pDup = sqlite3ExprDup(pExpr);
if( sqlite3MallocFailed() ){
sqliteFree(pDup);
sqlite3ExprDelete(pDup);
return;
}
idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC);