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: case 22:
#line 306 "bison_parser.y" /* yacc.c:1646 */ #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 */ #line 1972 "bison_parser.cpp" /* yacc.c:1646 */
break; break;

View File

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

View File

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

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