Skip to content

Commit 3621bee

Browse files
committedAug 25, 2015
Fix leaks in QgsExpression
1 parent b20b4d8 commit 3621bee

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed
 

‎src/core/qgsexpressionlexer.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ struct expression_parser_context;
5050

5151
#define B_OP(x) yylval->b_op = QgsExpression::x
5252
#define U_OP(x) yylval->u_op = QgsExpression::x
53-
#define TEXT yylval->text = new QString(); *yylval->text = QString::fromUtf8(yytext);
54-
#define TEXT_FILTER(filter_fn) yylval->text = new QString(); *yylval->text = filter_fn( QString::fromUtf8(yytext) );
53+
#define TEXT yylval->text = new QString( QString::fromUtf8(yytext) );
54+
#define TEXT_FILTER(filter_fn) yylval->text = new QString( filter_fn( QString::fromUtf8(yytext) ) );
5555

5656
static QString stripText(QString text)
5757
{

‎src/core/qgsexpressionparser.yy

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ struct expression_parser_context
149149
%destructor { delete $$; } <node>
150150
%destructor { delete $$; } <nodelist>
151151
%destructor { delete $$; } <text>
152+
%destructor { delete $$; } <whenthen>
153+
%destructor { delete $$; } <whenthenlist>
152154

153155
%%
154156

@@ -181,26 +183,29 @@ expression:
181183
| FUNCTION '(' exp_list ')'
182184
{
183185
int fnIndex = QgsExpression::functionIndex(*$1);
186+
delete $1;
184187
if (fnIndex == -1)
185188
{
186189
// this should not actually happen because already in lexer we check whether an identifier is a known function
187190
// (if the name is not known the token is parsed as a column)
188191
exp_error(parser_ctx, "Function is not known");
192+
delete $3;
189193
YYERROR;
190194
}
191195
if ( QgsExpression::Functions()[fnIndex]->params() != -1
192196
&& QgsExpression::Functions()[fnIndex]->params() != $3->count() )
193197
{
194198
exp_error(parser_ctx, "Function is called with wrong number of arguments");
199+
delete $3;
195200
YYERROR;
196201
}
197202
$$ = new QgsExpression::NodeFunction(fnIndex, $3);
198-
delete $1;
199203
}
200204

201205
| FUNCTION '(' ')'
202206
{
203207
int fnIndex = QgsExpression::functionIndex(*$1);
208+
delete $1;
204209
if (fnIndex == -1)
205210
{
206211
// this should not actually happen because already in lexer we check whether an identifier is a known function
@@ -214,7 +219,6 @@ expression:
214219
YYERROR;
215220
}
216221
$$ = new QgsExpression::NodeFunction(fnIndex, new QgsExpression::NodeList());
217-
delete $1;
218222
}
219223

220224
| expression IN '(' exp_list ')' { $$ = new QgsExpression::NodeInOperator($1, $4, false); }
@@ -236,30 +240,31 @@ expression:
236240
if (fnIndex == -1)
237241
{
238242
if ( !QgsExpression::hasSpecialColumn( *$1 ) )
239-
{
243+
{
240244
exp_error(parser_ctx, "Special column is not known");
241-
YYERROR;
242-
}
243-
// $var is equivalent to _specialcol_( "$var" )
244-
QgsExpression::NodeList* args = new QgsExpression::NodeList();
245-
QgsExpression::NodeLiteral* literal = new QgsExpression::NodeLiteral( *$1 );
246-
args->append( literal );
247-
$$ = new QgsExpression::NodeFunction( QgsExpression::functionIndex( "_specialcol_" ), args );
245+
delete $1;
246+
YYERROR;
247+
}
248+
// $var is equivalent to _specialcol_( "$var" )
249+
QgsExpression::NodeList* args = new QgsExpression::NodeList();
250+
QgsExpression::NodeLiteral* literal = new QgsExpression::NodeLiteral( *$1 );
251+
args->append( literal );
252+
$$ = new QgsExpression::NodeFunction( QgsExpression::functionIndex( "_specialcol_" ), args );
248253
}
249-
else
250-
{
251-
$$ = new QgsExpression::NodeFunction( fnIndex, NULL );
252-
delete $1;
253-
}
254+
else
255+
{
256+
$$ = new QgsExpression::NodeFunction( fnIndex, NULL );
257+
}
258+
delete $1;
254259
}
255260

256261
// variables
257262
| VARIABLE
258263
{
259-
// @var is equivalent to var( "var" )
260-
QgsExpression::NodeList* args = new QgsExpression::NodeList();
261-
QgsExpression::NodeLiteral* literal = new QgsExpression::NodeLiteral( QString(*$1).mid(1) );
262-
args->append( literal );
264+
// @var is equivalent to var( "var" )
265+
QgsExpression::NodeList* args = new QgsExpression::NodeList();
266+
QgsExpression::NodeLiteral* literal = new QgsExpression::NodeLiteral( QString(*$1).mid(1) );
267+
args->append( literal );
263268
$$ = new QgsExpression::NodeFunction( QgsExpression::functionIndex( "var" ), args );
264269
delete $1;
265270
}
@@ -308,6 +313,7 @@ QgsExpression::Node* parseExpression(const QString& str, QString& parserErrorMsg
308313
else // error?
309314
{
310315
parserErrorMsg = ctx.errorMsg;
316+
delete ctx.rootNode;
311317
return NULL;
312318
}
313319
}

0 commit comments

Comments
 (0)
Please sign in to comment.