diff options
author | drh <drh@noemail.net> | 2006-07-11 13:15:08 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2006-07-11 13:15:08 +0000 |
commit | 206f3d96d140c9480f19bf92e8f7f35132048d4b (patch) | |
tree | b5e49af529118b78d55a415f27edbee35c6c0cc2 /src/expr.c | |
parent | 76f8079623ba1e5b21dd4942fc6d53768abd96c1 (diff) | |
download | sqlite-206f3d96d140c9480f19bf92e8f7f35132048d4b.tar.gz sqlite-206f3d96d140c9480f19bf92e8f7f35132048d4b.zip |
Prevent memory leak and possible NULL pointer deference after malloc
failure. Ticket #1886. (CVS 3329)
FossilOrigin-Name: b1f326e6959ef3be11f772e80f5ab6dd65b2d065
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/expr.c b/src/expr.c index 5ba7cde7c..4e8d322b9 100644 --- a/src/expr.c +++ b/src/expr.c @@ -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.265 2006/07/08 18:41:37 drh Exp $ +** $Id: expr.c,v 1.266 2006/07/11 13:15:08 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -212,6 +212,19 @@ Expr *sqlite3Expr(int op, Expr *pLeft, Expr *pRight, const Token *pToken){ } /* +** Works like sqlite3Expr() but frees its pLeft and pRight arguments +** if it fails due to a malloc problem. +*/ +Expr *sqlite3ExprOrFree(int op, Expr *pLeft, Expr *pRight, const Token *pToken){ + Expr *pNew = sqlite3Expr(op, pLeft, pRight, pToken); + if( pNew==0 ){ + sqlite3ExprDelete(pLeft); + sqlite3ExprDelete(pRight); + } + return pNew; +} + +/* ** When doing a nested parse, you can include terms in an expression ** that look like this: #0 #1 #2 ... These terms refer to elements ** on the stack. "#0" means the top of the stack. |