未验证 提交 0d487ceb 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #17500 from taosdata/fix/TD-19655-V26

fix(shell): coverity scan problem fixed
...@@ -533,26 +533,16 @@ void parseCommand(SWords * command, bool pattern) { ...@@ -533,26 +533,16 @@ void parseCommand(SWords * command, bool pattern) {
} }
// free Command // free Command
void freeCommand(SWords * command) { void freeCommand(SWords* command) {
SWord * word = command->head; SWord* item = command->head;
if (word == NULL) { // loop
return ; while (item) {
} SWord* tmp = item;
item = item->next;
// loop
while (word->next) {
SWord * tmp = word;
word = word->next;
// if malloc need free // if malloc need free
if(tmp->free && tmp->word) if (tmp->free && tmp->word) free(tmp->word);
free(tmp->word);
free(tmp); free(tmp);
} }
// if malloc need free
if(word->free && word->word)
free(word->word);
free(word);
} }
void GenerateVarType(int type, char** p, int count) { void GenerateVarType(int type, char** p, int count) {
...@@ -1178,11 +1168,11 @@ bool nextMatchCommand(TAOS * con, Command * cmd, SWords * firstMatch) { ...@@ -1178,11 +1168,11 @@ bool nextMatchCommand(TAOS * con, Command * cmd, SWords * firstMatch) {
printScreen(con, cmd, match); printScreen(con, cmd, match);
// free // free
freeCommand(input);
if (input->source) { if (input->source) {
free(input->source); free(input->source);
input->source = NULL; input->source = NULL;
} }
freeCommand(input);
free(input); free(input);
return true; return true;
......
...@@ -325,30 +325,26 @@ void matchPrefixFromTree(STire* tire, char* prefix, SMatch* match) { ...@@ -325,30 +325,26 @@ void matchPrefixFromTree(STire* tire, char* prefix, SMatch* match) {
} }
SMatch* matchPrefix(STire* tire, char* prefix, SMatch* match) { SMatch* matchPrefix(STire* tire, char* prefix, SMatch* match) {
if(match == NULL) { SMatch* rMatch = match; // define return match
match = (SMatch* )tmalloc(sizeof(SMatch)); if (rMatch == NULL) {
memset(match, 0, sizeof(SMatch)); rMatch = (SMatch*)malloc(sizeof(SMatch));
} memset(rMatch, 0, sizeof(SMatch));
}
switch (tire->type) {
case TIRE_TREE: switch (tire->type) {
matchPrefixFromTree(tire, prefix, match); case TIRE_TREE:
case TIRE_LIST: matchPrefixFromTree(tire, prefix, rMatch);
matchPrefixFromList(tire, prefix, match); break;
default: case TIRE_LIST:
break; matchPrefixFromList(tire, prefix, rMatch);
} break;
default:
// return if need break;
if (match->count == 0) { }
freeMatch(match);
match = NULL; return rMatch;
}
return match;
} }
// get all items from tires tree // get all items from tires tree
void enumFromList(STire* tire, SMatch* match) { void enumFromList(STire* tire, SMatch* match) {
StrName * item = tire->head; StrName * item = tire->head;
...@@ -395,8 +391,10 @@ SMatch* enumAll(STire* tire) { ...@@ -395,8 +391,10 @@ SMatch* enumAll(STire* tire) {
switch (tire->type) { switch (tire->type) {
case TIRE_TREE: case TIRE_TREE:
enumFromTree(tire, match); enumFromTree(tire, match);
break;
case TIRE_LIST: case TIRE_LIST:
enumFromList(tire, match); enumFromList(tire, match);
break;
default: default:
break; break;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册