提交 6ed6f0fc 编写于 作者: A Alex Duan

feat(shell): -DMEMORY_SANITIZER=true check memory leak and fix

上级 a6dda144
...@@ -83,11 +83,11 @@ SWords shellCommands[] = { ...@@ -83,11 +83,11 @@ SWords shellCommands[] = {
{"delete from <all_table> where", 0, 0, NULL}, {"delete from <all_table> where", 0, 0, NULL},
#endif #endif
{"drop database <db_name>", 0, 0, NULL}, {"drop database <db_name>", 0, 0, NULL},
{"drop table <all_table> ", 0, 0, NULL},
{"drop dnode <dnode_id>", 0, 0, NULL}, {"drop dnode <dnode_id>", 0, 0, NULL},
{"drop user <user_name> ;", 0, 0, NULL},
{"drop function", 0, 0, NULL}, {"drop function", 0, 0, NULL},
{"drop topic", 0, 0, NULL}, {"drop topic", 0, 0, NULL},
{"drop table <all_table>;", 0, 0, NULL},
{"drop user <user_name>;", 0, 0, NULL},
{"kill connection", 0, 0, NULL}, {"kill connection", 0, 0, NULL},
{"kill query", 0, 0, NULL}, {"kill query", 0, 0, NULL},
{"kill stream", 0, 0, NULL}, {"kill stream", 0, 0, NULL},
...@@ -366,10 +366,10 @@ void showHelp() { ...@@ -366,10 +366,10 @@ void showHelp() {
describe <all_table> ;\n\ describe <all_table> ;\n\
delete from <all_table> where ... \n\ delete from <all_table> where ... \n\
drop database <db_name>;\n\ drop database <db_name>;\n\
drop table <all_table>;\n\
drop dnode <dnode_id>;\n\ drop dnode <dnode_id>;\n\
drop function <function_id>;\n\ drop function <function_id>;\n\
drop topic <topic_id>;\n\ drop topic <topic_id>;\n\
drop table <all_table>;\n\
drop user <user_name>;\n\ drop user <user_name>;\n\
----- K ----- \n\ ----- K ----- \n\
kill connection <connection_id>; \n\ kill connection <connection_id>; \n\
...@@ -1087,12 +1087,14 @@ bool firstMatchCommand(TAOS * con, Command * cmd) { ...@@ -1087,12 +1087,14 @@ bool firstMatchCommand(TAOS * con, Command * cmd) {
if (match == NULL) { if (match == NULL) {
// not match , nothing to do // not match , nothing to do
freeCommand(input); freeCommand(input);
free(input);
return false; return false;
} }
// print to screen // print to screen
printScreen(con, cmd, match); printScreen(con, cmd, match);
freeCommand(input); freeCommand(input);
free(input);
return true; return true;
} }
...@@ -1145,6 +1147,9 @@ bool nextMatchCommand(TAOS * con, Command * cmd, SWords * firstMatch) { ...@@ -1145,6 +1147,9 @@ bool nextMatchCommand(TAOS * con, Command * cmd, SWords * firstMatch) {
match = matchCommand(input, false); match = matchCommand(input, false);
if (match == NULL) { if (match == NULL) {
freeCommand(input); freeCommand(input);
if (input->source)
free(input->source);
free(input);
return false; return false;
} }
} }
...@@ -1158,6 +1163,7 @@ bool nextMatchCommand(TAOS * con, Command * cmd, SWords * firstMatch) { ...@@ -1158,6 +1163,7 @@ bool nextMatchCommand(TAOS * con, Command * cmd, SWords * firstMatch) {
input->source = NULL; input->source = NULL;
} }
freeCommand(input); freeCommand(input);
free(input);
return true; return true;
} }
...@@ -1247,22 +1253,20 @@ bool fieldsInputEnd(char* sql) { ...@@ -1247,22 +1253,20 @@ bool fieldsInputEnd(char* sql) {
} }
// not in ',' // not in ','
char * p = strrchr(sql, ','); char * p3 = strrchr(sql, ',');
char * p = p3;
// like select ts, age,' ' // like select ts, age,' '
if (p) { if (p) {
++p; ++p;
bool allBlank = true; bool allBlank = true; // after last ',' all char is blank
int cnt = 0; // blank count , continue many blank is one blank int cnt = 0; // blank count , like ' ' as one blank
char * plast = NULL; char * plast = NULL; // last blank position
while(*p) { while(*p) {
if (*p != ' ') { if (*p == ' ') {
allBlank = false;
plast = NULL;
} else {
if(plast == NULL) {
plast = p; plast = p;
cnt ++; cnt ++;
} } else {
allBlank = false;
} }
++p; ++p;
} }
...@@ -1272,14 +1276,19 @@ bool fieldsInputEnd(char* sql) { ...@@ -1272,14 +1276,19 @@ bool fieldsInputEnd(char* sql) {
return false; return false;
} }
// if last char not ' ', then not end field, like select count(*), su + tab can fill sum( // like 'select count(*),sum(age) fr' need return true
if (plast && plast > p3 && p2 > p1 && plast > p2 && p1 > p3) {
return true;
}
// if last char not ' ', then not end field, like 'select count(*), su' can fill sum(
if(sql[strlen(sql)-1] != ' ' && cnt <= 1) { if(sql[strlen(sql)-1] != ' ' && cnt <= 1) {
return false; return false;
} }
} }
char * p3 = strrchr(sql, ' '); char * p4 = strrchr(sql, ' ');
if(p3 == NULL) { if(p4 == NULL) {
// only one word // only one word
return false; return false;
} }
......
...@@ -58,13 +58,14 @@ void freeTire(STire* tire) { ...@@ -58,13 +58,14 @@ void freeTire(STire* tire) {
// free from list // free from list
StrName * item = tire->head; StrName * item = tire->head;
while (item) { while (item) {
StrName * next = item->next;
// free string // free string
tfree(item->name); tfree(item->name);
// free node // free node
tfree(item); tfree(item);
// move next // move next
item = item->next; item = next;
} }
tire->head = tire->tail = NULL; tire->head = tire->tail = NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册