-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
commit-message: 释放未解析成语法树的id #479 #485
Conversation
src/observer/sql/parser/lex_sql.l
Outdated
@@ -46,6 +47,7 @@ while (0); | |||
extern int atoi(); | |||
extern double atof(); | |||
|
|||
std::vector<char *> allocated_strings; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用全局变量的话,并发时会出现访问冲突。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那我选择在全局变量上加锁这种方式可以吗
使用全局变量的话,并发时会出现访问冲突。
加锁只能解决访问冲突,但是一个线程会把另一个线程的数据给释放掉。应该每次仅记录当前请求的信息,在语法解析完成时释放掉。 |
我大概看了下lex的相关内容,这里有一个yyscan_t的结构,执行lex相关的函数时都会带上这个对象。可以看到 int sql_parse(const char *s, ParsedSqlResult *sql_result) {
yyscan_t scanner;
yylex_init(&scanner);
scan_string(s, scanner);
int result = yyparse(s, sql_result, scanner);
yylex_destroy(scanner);
return result;
}
可以在 int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t* scanner); 看起来就是除了lex本身需要的一些成员变量,我们还可以在scanner里面塞一些自己的信息,就是
/* yylex_init_extra has the same functionality as yylex_init, but follows the
* convention of taking the scanner as the last argument. Note however, that
* this is a *pointer* to a scanner, as it will be allocated by this call (and
* is the reason, too, why this function also must handle its own declaration).
* The user defined value in the first argument will be available to yyalloc in
* the yyextra field.
*/ |
What problem were solved in this pull request?
当输入sql语句错误并exit后,会出现内存未释放错误
Issue Number: close #479
Problem:
在处理 SQL 解析时,如果 SQL 语句错误且调用 exit,程序未正确释放分配的内存,导致内存泄漏。
What is changed and how it works?
修改了lex_sql.l文件,跟踪了所有使用strdup复制的变量的地址,新写统一释放函数
修改了yacc_sql.y文件,在语法解析结束后调用释放函数,统一释放由strdup复制的变量