fix memory leaks when parsing fails
This commit is contained in:
parent
043e34b70c
commit
1f183147ec
|
@ -28,11 +28,12 @@ namespace hsql {
|
||||||
// Parser and return early if it failed.
|
// Parser and return early if it failed.
|
||||||
if (hsql_parse(&result, scanner)) {
|
if (hsql_parse(&result, scanner)) {
|
||||||
// Returns an error stmt object.
|
// Returns an error stmt object.
|
||||||
|
hsql__delete_buffer(state, scanner);
|
||||||
|
hsql_lex_destroy(scanner);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
hsql__delete_buffer(state, scanner);
|
hsql__delete_buffer(state, scanner);
|
||||||
|
|
||||||
hsql_lex_destroy(scanner);
|
hsql_lex_destroy(scanner);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace hsql {
|
||||||
delete statement;
|
delete statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete errorMsg_;
|
free(errorMsg_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLParserResult::addStatement(SQLStatement* stmt) {
|
void SQLParserResult::addStatement(SQLStatement* stmt) {
|
||||||
|
@ -57,7 +57,7 @@ namespace hsql {
|
||||||
isValid_ = isValid;
|
isValid_ = isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLParserResult::setErrorDetails(const char* errorMsg, int errorLine, int errorColumn) {
|
void SQLParserResult::setErrorDetails(char* errorMsg, int errorLine, int errorColumn) {
|
||||||
errorMsg_ = errorMsg;
|
errorMsg_ = errorMsg;
|
||||||
errorLine_ = errorLine;
|
errorLine_ = errorLine;
|
||||||
errorColumn_ = errorColumn;
|
errorColumn_ = errorColumn;
|
||||||
|
|
|
@ -47,7 +47,8 @@ namespace hsql {
|
||||||
void setIsValid(bool isValid);
|
void setIsValid(bool isValid);
|
||||||
|
|
||||||
// Set the details of the error, if available.
|
// 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:
|
private:
|
||||||
|
@ -58,7 +59,7 @@ namespace hsql {
|
||||||
bool isValid_;
|
bool isValid_;
|
||||||
|
|
||||||
// Error message, if an error occurred.
|
// Error message, if an error occurred.
|
||||||
const char* errorMsg_;
|
char* errorMsg_;
|
||||||
|
|
||||||
// Line number of the occurrance of the error in the query.
|
// Line number of the occurrance of the error in the query.
|
||||||
int errorLine_;
|
int errorLine_;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -48,7 +48,7 @@
|
||||||
extern int hsql_debug;
|
extern int hsql_debug;
|
||||||
#endif
|
#endif
|
||||||
/* "%code requires" blocks. */
|
/* "%code requires" blocks. */
|
||||||
#line 40 "bison_parser.y" /* yacc.c:1909 */
|
#line 41 "bison_parser.y" /* yacc.c:1909 */
|
||||||
|
|
||||||
// %code requires block
|
// %code requires block
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ extern int hsql_debug;
|
||||||
typedef union HSQL_STYPE HSQL_STYPE;
|
typedef union HSQL_STYPE HSQL_STYPE;
|
||||||
union HSQL_STYPE
|
union HSQL_STYPE
|
||||||
{
|
{
|
||||||
#line 99 "bison_parser.y" /* yacc.c:1909 */
|
#line 100 "bison_parser.y" /* yacc.c:1909 */
|
||||||
|
|
||||||
double fval;
|
double fval;
|
||||||
int64_t ival;
|
int64_t ival;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
using namespace hsql;
|
using namespace hsql;
|
||||||
|
|
||||||
int yyerror(YYLTYPE* llocp, SQLParserResult** result, yyscan_t scanner, const char *msg) {
|
int yyerror(YYLTYPE* llocp, SQLParserResult** result, yyscan_t scanner, const char *msg) {
|
||||||
|
delete *result;
|
||||||
|
|
||||||
SQLParserResult* list = new SQLParserResult();
|
SQLParserResult* list = new SQLParserResult();
|
||||||
list->setIsValid(false);
|
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
|
** Token Definition
|
||||||
|
|
Loading…
Reference in New Issue