diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 7d737fbb8e..724229af16 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -35,6 +35,7 @@ #include "tsched.h" #include "ttime.h" #include "tversion.h" +#include "tcompare.h" #if defined(CUS_NAME) || defined(CUS_PROMPT) || defined(CUS_EMAIL) #include "cus_name.h" @@ -875,6 +876,12 @@ void taos_init_imp(void) { } rpcInit(); + if (InitRegexCache() != 0) { + tscInitRes = -1; + tscError("failed to init regex cache"); + return; + } + SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100}; catalogInit(&cfg); diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index f65edc103a..35e0b61114 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -28,6 +28,7 @@ #include "tref.h" #include "trpc.h" #include "version.h" +#include "tcompare.h" #define TSC_VAR_NOT_RELEASE 1 #define TSC_VAR_RELEASED 0 @@ -78,6 +79,7 @@ void taos_cleanup(void) { clientConnRefPool = -1; taosCloseRef(id); + DestroyRegexCache(); rpcCleanup(); tscDebug("rpc cleanup"); diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c index 09599cead4..b3e1da5f1c 100644 --- a/source/util/src/tcompare.c +++ b/source/util/src/tcompare.c @@ -1299,6 +1299,7 @@ static UsingRegex **getRegComp(const char *pPattern) { UsingRegex *pUsingRegex = taosMemoryMalloc(sizeof(UsingRegex)); if (pUsingRegex == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; uError("Failed to Malloc when compile regex pattern %s.", pPattern); return NULL; } @@ -1309,6 +1310,7 @@ static UsingRegex **getRegComp(const char *pPattern) { regerror(ret, &pUsingRegex->pRegex, msgbuf, tListLen(msgbuf)); uError("Failed to compile regex pattern %s. reason %s", pPattern, msgbuf); taosMemoryFree(pUsingRegex); + terrno = TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR; return NULL; } @@ -1317,6 +1319,7 @@ static UsingRegex **getRegComp(const char *pPattern) { if (code != 0 && code != TSDB_CODE_DUP_KEY) { regexCacheFree(&pUsingRegex); uError("Failed to put regex pattern %s into cache, exception internal error.", pPattern); + terrno = code; return NULL; } ppUsingRegex = (UsingRegex **)taosHashAcquire(sRegexCache.regexHash, pPattern, strlen(pPattern)); @@ -1350,6 +1353,7 @@ static int32_t doExecRegexMatch(const char *pString, const char *pPattern) { ret = regexec(&(*pUsingRegex)->pRegex, pString, 1, pmatch, 0); releaseRegComp(pUsingRegex); if (ret != 0 && ret != REG_NOMATCH) { + terrno = TSDB_CODE_PAR_REGULAR_EXPRESSION_ERROR; regerror(ret, &(*pUsingRegex)->pRegex, msgbuf, sizeof(msgbuf)); uDebug("Failed to match %s with pattern %s, reason %s", pString, pPattern, msgbuf) }