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 {
$$ = $1;
$$->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 {
// TODO: allow multiple unions (through linked list)
@ -487,13 +492,23 @@ select_no_paren:
$$ = $1;
$$->unionSelect = $3;
$$->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 {
$$ = $1;
$$->unionSelect = $3;
$$->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 <stdio.h>
#include <string.h>
#include "SelectStatement.h"
namespace hsql {
@ -9,6 +10,8 @@ namespace hsql {
type(type),
expr(NULL),
expr2(NULL),
exprList(NULL),
select(NULL),
name(NULL),
table(NULL),
alias(NULL) {};
@ -16,9 +19,17 @@ namespace hsql {
Expr::~Expr() {
delete expr;
delete expr2;
delete select;
free(name);
free(table);
free(alias);
if (exprList != NULL) {
for (Expr* e : *exprList) {
delete e;
}
delete exprList;
}
}
Expr* Expr::makeOpUnary(OperatorType op, Expr* expr) {

View File

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

View File

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