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

fix(shell): coverity problem for some

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