Change so that deleting an Expr structure requires only one frame per level in the expression tree, not two.
FossilOrigin-Name: a4380ab326e4b0de29271c824d041193e86b7139
diff --git a/src/expr.c b/src/expr.c
index 5254cd7..aee2b74 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -627,11 +627,10 @@
}
/*
-** Clear an expression structure without deleting the structure itself.
-** Substructure is deleted.
+** Recursively delete an expression tree.
*/
-void sqlite3ExprClear(sqlite3 *db, Expr *p){
- assert( p!=0 );
+void sqlite3ExprDelete(sqlite3 *db, Expr *p){
+ if( p==0 ) return;
if( !ExprHasAnyProperty(p, EP_TokenOnly) ){
sqlite3ExprDelete(db, p->pLeft);
sqlite3ExprDelete(db, p->pRight);
@@ -644,14 +643,6 @@
sqlite3ExprListDelete(db, p->x.pList);
}
}
-}
-
-/*
-** Recursively delete an expression tree.
-*/
-void sqlite3ExprDelete(sqlite3 *db, Expr *p){
- if( p==0 ) return;
- sqlite3ExprClear(db, p);
if( !ExprHasProperty(p, EP_Static) ){
sqlite3DbFree(db, p);
}
diff --git a/src/resolve.c b/src/resolve.c
index b763a80..d913a24 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -87,7 +87,13 @@
pDup->pColl = pExpr->pColl;
pDup->flags |= EP_ExpCollate;
}
- sqlite3ExprClear(db, pExpr);
+
+ /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This
+ ** prevents ExprDelete() from deleting the Expr structure itself,
+ ** allowing it to be repopulated by the memcpy() on the following line.
+ */
+ ExprSetProperty(pExpr, EP_Static);
+ sqlite3ExprDelete(db, pExpr);
memcpy(pExpr, pDup, sizeof(*pExpr));
sqlite3DbFree(db, pDup);
}
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 293c244..a3980a0 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -2544,7 +2544,6 @@
Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
void sqlite3ExprAssignVarNumber(Parse*, Expr*);
-void sqlite3ExprClear(sqlite3*, Expr*);
void sqlite3ExprDelete(sqlite3*, Expr*);
ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);