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