fix all leaks triggered by sql_grammar_test.cpp

This commit is contained in:
Pedro 2017-02-08 04:27:04 +01:00
parent 69e9673763
commit 5041dccf70
5 changed files with 21 additions and 6 deletions

View File

@ -1967,7 +1967,7 @@ yyreduce:
case 22:
#line 306 "bison_parser.y" /* yacc.c:1646 */
{ (yyval.sval) = (yyvsp[0].expr)->name; }
{ (yyval.sval) = strdup((yyvsp[0].expr)->name); delete (yyvsp[0].expr); }
#line 1972 "bison_parser.cpp" /* yacc.c:1646 */
break;

View File

@ -303,7 +303,7 @@ import_file_type:
;
file_path:
string_literal { $$ = $1->name; }
string_literal { $$ = strdup($1->name); delete $1; }
;

View File

@ -192,6 +192,7 @@ namespace hsql {
delete fromTable;
delete whereClause;
delete groupBy;
delete unionSelect;
delete order;
delete limit;
@ -236,10 +237,19 @@ namespace hsql {
join(NULL) {}
TableRef::~TableRef() {
free(schema);
free(name);
free(alias);
delete select;
delete list;
delete join;
if (list != NULL) {
for (TableRef* table : *list) {
delete table;
}
delete list;
}
}
bool TableRef::hasSchema() {

View File

@ -6,7 +6,7 @@ SELECT * from "table" JOIN table2 ON a = b WHERE (b OR NOT a) AND a = 12.5
(SELECT a FROM foo WHERE a > 12 OR b > 3 AND c NOT LIKE 's%' LIMIT 10);
SELECT * FROM "table" LIMIT 10 OFFSET 10; SELECT * FROM second;
SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY col1;
# SELECT * FROM t1 UNION (SELECT * FROM t2 UNION SELECT * FROM t3) ORDER BY col1;
-- SELECT * FROM t1 UNION (SELECT * FROM t2 UNION SELECT * FROM t3) ORDER BY col1;
# JOIN
SELECT t1.a, t1.b, t2.c FROM "table" AS t1 JOIN (SELECT * FROM foo JOIN bar ON foo.id = bar.id) t2 ON t1.a = t2.b WHERE (t1.b OR NOT t1.a) AND t2.c = 12.5
SELECT * FROM t1 JOIN t2 ON c1 = c2;

View File

@ -18,9 +18,12 @@ std::vector<std::string> readlines(std::string path) {
std::istringstream iss(line);
// Skip comments
if (line[0] != '#') {
lines.push_back(line);
if (line[0] == '#' ||
(line[0] == '-' && line[1] == '-')) {
continue;
}
lines.push_back(line);
}
return lines;
}
@ -82,6 +85,8 @@ int main(int argc, char *argv[]) {
// TODO: indicate whether expectFalse was set
printf("\033[0;32m{ ok} (%.1fus)\033[0m %s\n", us, sql.c_str());
}
delete result;
}
if (numFailed == 0) {