From fc5e4563889e0d8cd00df149ff34dac3ecdbba7f Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Thu, 20 Oct 2022 09:26:02 +0800 Subject: [PATCH] fix(shell): coverity scan problem fixed --- src/kit/shell/src/tire.c | 42 +++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/kit/shell/src/tire.c b/src/kit/shell/src/tire.c index b4dc7976bd..9464a4f025 100644 --- a/src/kit/shell/src/tire.c +++ b/src/kit/shell/src/tire.c @@ -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)); - } - - switch (tire->type) { - case TIRE_TREE: - matchPrefixFromTree(tire, prefix, match); - case TIRE_LIST: - matchPrefixFromList(tire, prefix, match); - default: - break; - } - - // return if need - if (match->count == 0) { - freeMatch(match); - match = NULL; - } - - return match; + 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, rMatch); + break; + case TIRE_LIST: + matchPrefixFromList(tire, prefix, rMatch); + break; + default: + break; + } + + 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; } -- GitLab