提交 720c16bf 编写于 作者: A Alex Duan

fix(shell): coverity problem for some

上级 c58daa70
......@@ -944,6 +944,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
if (taosReadFile(pFile, buf, fileSize) <= 0) {
taosCloseFile(&pFile);
uError("load json file error: %s", filepath);
taosMemoryFreeClear(buf);
return -1;
}
taosCloseFile(&pFile);
......@@ -953,6 +954,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
if (jsonParseError != NULL) {
uError("load json file parse error: %s", jsonParseError);
}
taosMemoryFreeClear(buf);
return -1;
}
taosMemoryFreeClear(buf);
......
......@@ -562,23 +562,15 @@ void parseCommand(SWords* command, bool pattern) {
// free SShellCmd
void freeCommand(SWords* command) {
SWord* word = command->head;
if (word == NULL) {
return;
}
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) taosMemoryFree(tmp->word);
taosMemoryFree(tmp);
}
// if malloc need free
if (word->free && word->word) taosMemoryFree(word->word);
taosMemoryFree(word);
}
void GenerateVarType(int type, char** p, int count) {
......@@ -1204,11 +1196,11 @@ bool nextMatchCommand(TAOS* con, SShellCmd* cmd, SWords* firstMatch) {
#endif
// free
freeCommand(input);
if (input->source) {
taosMemoryFree(input->source);
input->source = NULL;
}
freeCommand(input);
taosMemoryFree(input);
return true;
......@@ -1377,7 +1369,7 @@ bool appendAfterSelect(TAOS* con, SShellCmd* cmd, char* sql, int32_t len) {
bool ret = false;
if (from == NULL) {
bool fieldEnd = fieldsInputEnd(p);
// cheeck fields input end then insert from keyword
// check fields input end then insert from keyword
if (fieldEnd && p[len - 1] == ' ') {
shellInsertChar(cmd, "from", 4);
taosMemoryFree(p);
......
......@@ -103,6 +103,8 @@ void shellInsertChar(SShellCmd *cmd, char *c, int32_t size) {
cmd->cursorOffset += size;
cmd->screenOffset += taosWcharWidth(wc);
cmd->endOffset += taosWcharWidth(wc);
// set string end
cmd->command[cmd->commandSize] = 0;
#ifdef WINDOWS
#else
shellShowOnScreen(cmd);
......@@ -123,6 +125,8 @@ void shellBackspaceChar(SShellCmd *cmd) {
cmd->cursorOffset -= size;
cmd->screenOffset -= width;
cmd->endOffset -= width;
// set string end
cmd->command[cmd->commandSize] = 0;
shellShowOnScreen(cmd);
}
}
......@@ -136,6 +140,8 @@ void shellClearLineBefore(SShellCmd *cmd) {
cmd->cursorOffset = 0;
cmd->screenOffset = 0;
cmd->endOffset = cmd->commandSize;
// set string end
cmd->command[cmd->commandSize] = 0;
shellShowOnScreen(cmd);
}
......@@ -160,6 +166,8 @@ void shellDeleteChar(SShellCmd *cmd) {
cmd->commandSize - cmd->cursorOffset - size);
cmd->commandSize -= size;
cmd->endOffset -= width;
// set string end
cmd->command[cmd->commandSize] = 0;
shellShowOnScreen(cmd);
}
}
......
......@@ -309,27 +309,24 @@ void matchPrefixFromTree(STire* tire, char* prefix, SMatch* match) {
}
SMatch* matchPrefix(STire* tire, char* prefix, SMatch* match) {
if (match == NULL) {
match = (SMatch*)taosMemoryMalloc(sizeof(SMatch));
memset(match, 0, sizeof(SMatch));
SMatch* rMatch = match; // define return match
if (rMatch == NULL) {
rMatch = (SMatch*)taosMemoryMalloc(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
......@@ -378,8 +375,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.
先完成此消息的编辑!
想要评论请 注册