fix memory leaks when parsing fails

This commit is contained in:
Pedro 2017-02-08 04:56:07 +01:00
parent 043e34b70c
commit 1f183147ec
6 changed files with 743 additions and 261 deletions

View File

@ -28,11 +28,12 @@ namespace hsql {
// Parser and return early if it failed.
if (hsql_parse(&result, scanner)) {
// Returns an error stmt object.
hsql__delete_buffer(state, scanner);
hsql_lex_destroy(scanner);
return result;
}
hsql__delete_buffer(state, scanner);
hsql_lex_destroy(scanner);
return result;
}

View File

@ -18,7 +18,7 @@ namespace hsql {
delete statement;
}
delete errorMsg_;
free(errorMsg_);
}
void SQLParserResult::addStatement(SQLStatement* stmt) {
@ -57,7 +57,7 @@ namespace hsql {
isValid_ = isValid;
}
void SQLParserResult::setErrorDetails(const char* errorMsg, int errorLine, int errorColumn) {
void SQLParserResult::setErrorDetails(char* errorMsg, int errorLine, int errorColumn) {
errorMsg_ = errorMsg;
errorLine_ = errorLine;
errorColumn_ = errorColumn;

View File

@ -47,7 +47,8 @@ namespace hsql {
void setIsValid(bool isValid);
// Set the details of the error, if available.
void setErrorDetails(const char* errorMsg, int errorLine, int errorColumn);
// Takes ownership of errorMsg.
void setErrorDetails(char* errorMsg, int errorLine, int errorColumn);
private:
@ -58,7 +59,7 @@ namespace hsql {
bool isValid_;
// Error message, if an error occurred.
const char* errorMsg_;
char* errorMsg_;
// Line number of the occurrance of the error in the query.
int errorLine_;

File diff suppressed because it is too large Load Diff

View File

@ -48,7 +48,7 @@
extern int hsql_debug;
#endif
/* "%code requires" blocks. */
#line 40 "bison_parser.y" /* yacc.c:1909 */
#line 41 "bison_parser.y" /* yacc.c:1909 */
// %code requires block
@ -209,7 +209,7 @@ extern int hsql_debug;
typedef union HSQL_STYPE HSQL_STYPE;
union HSQL_STYPE
{
#line 99 "bison_parser.y" /* yacc.c:1909 */
#line 100 "bison_parser.y" /* yacc.c:1909 */
double fval;
int64_t ival;

View File

@ -19,6 +19,7 @@
using namespace hsql;
int yyerror(YYLTYPE* llocp, SQLParserResult** result, yyscan_t scanner, const char *msg) {
delete *result;
SQLParserResult* list = new SQLParserResult();
list->setIsValid(false);
@ -133,6 +134,19 @@ int yyerror(YYLTYPE* llocp, SQLParserResult** result, yyscan_t scanner, const ch
}
/*********************************
** Descrutor symbols
*********************************/
%destructor { } <fval> <ival> <uval> <bval> <order_type>
%destructor { free( ($$) ); } <sval>
%destructor {
for (auto ptr : *($$)) {
delete ptr;
}
delete ($$);
} <str_vec> <table_vec> <column_vec> <update_vec> <expr_vec>
%destructor { delete ($$); } <*>
/*********************************
** Token Definition