fix memory leaks

This commit is contained in:
Pedro 2017-03-07 15:09:39 +01:00
parent b7828e698e
commit bf255c65ac
4 changed files with 37 additions and 4 deletions

View File

@ -478,7 +478,12 @@ select_no_paren:
select_clause opt_order opt_limit { select_clause opt_order opt_limit {
$$ = $1; $$ = $1;
$$->order = $2; $$->order = $2;
$$->limit = $3;
// Limit could have been set by TOP.
if ($3 != NULL) {
delete $$->limit;
$$->limit = $3;
}
} }
| select_clause set_operator select_clause opt_order opt_limit { | select_clause set_operator select_clause opt_order opt_limit {
// TODO: allow multiple unions (through linked list) // TODO: allow multiple unions (through linked list)
@ -487,13 +492,23 @@ select_no_paren:
$$ = $1; $$ = $1;
$$->unionSelect = $3; $$->unionSelect = $3;
$$->order = $4; $$->order = $4;
$$->limit = $5;
// Limit could have been set by TOP.
if ($5 != NULL) {
delete $$->limit;
$$->limit = $5;
}
} }
| select_clause set_operator select_with_paren opt_order opt_limit { | select_clause set_operator select_with_paren opt_order opt_limit {
$$ = $1; $$ = $1;
$$->unionSelect = $3; $$->unionSelect = $3;
$$->order = $4; $$->order = $4;
$$->limit = $5;
// Limit could have been set by TOP.
if ($5 != NULL) {
delete $$->limit;
$$->limit = $5;
}
} }
; ;

View File

@ -2,6 +2,7 @@
#include "Expr.h" #include "Expr.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "SelectStatement.h"
namespace hsql { namespace hsql {
@ -9,6 +10,8 @@ namespace hsql {
type(type), type(type),
expr(NULL), expr(NULL),
expr2(NULL), expr2(NULL),
exprList(NULL),
select(NULL),
name(NULL), name(NULL),
table(NULL), table(NULL),
alias(NULL) {}; alias(NULL) {};
@ -16,9 +19,17 @@ namespace hsql {
Expr::~Expr() { Expr::~Expr() {
delete expr; delete expr;
delete expr2; delete expr2;
delete select;
free(name); free(name);
free(table); free(table);
free(alias); free(alias);
if (exprList != NULL) {
for (Expr* e : *exprList) {
delete e;
}
delete exprList;
}
} }
Expr* Expr::makeOpUnary(OperatorType op, Expr* expr) { Expr* Expr::makeOpUnary(OperatorType op, Expr* expr) {

View File

@ -193,7 +193,6 @@ namespace hsql {
delete whereClause; delete whereClause;
delete groupBy; delete groupBy;
delete unionSelect; delete unionSelect;
delete order;
delete limit; delete limit;
// Delete each element in the select list. // Delete each element in the select list.
@ -203,6 +202,13 @@ namespace hsql {
} }
delete selectList; delete selectList;
} }
if (order != NULL) {
for (OrderDescription* desc : *order) {
delete desc;
}
delete order;
}
} }
// UpdateStatement // UpdateStatement

View File

@ -38,6 +38,7 @@ TEST(TPCHQueryTests) {
} else { } else {
mt::printOk(file_path.c_str()); mt::printOk(file_path.c_str());
} }
delete result;
} }
ASSERT_EQ(testsFailed, 0); ASSERT_EQ(testsFailed, 0);
} }