From 80a32d623535afdf99111c8cf0debafcbe127998 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Sat, 30 Jul 2022 11:31:05 +0800 Subject: [PATCH] fix: fix mbs2ucs4 crash issue in taosd --- include/os/osString.h | 1 - source/client/src/clientEnv.c | 2 -- source/dnode/mgmt/node_mgmt/src/dmMgmt.c | 1 + source/os/src/osString.c | 14 +++++++------- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/os/osString.h b/include/os/osString.h index 74d5e52a1b..2a22c6d8ff 100644 --- a/include/os/osString.h +++ b/include/os/osString.h @@ -62,7 +62,6 @@ typedef int32_t TdUcs4; int32_t taosUcs4len(TdUcs4 *ucs4); int64_t taosStr2int64(const char *str); -int32_t taosConvInit(int32_t maxNum); void taosConvDestroy(); int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs); bool taosMbsToUcs4(const char *mbs, size_t mbs_len, TdUcs4 *ucs4, int32_t ucs4_max_len, int32_t *len); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index c012533056..893aa39ce3 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -361,8 +361,6 @@ void taos_init_imp(void) { initQueryModuleMsgHandle(); - taosConvInit(256); - rpcInit(); SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100}; diff --git a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c index c2e8a55271..582b16ce99 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c +++ b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c @@ -215,6 +215,7 @@ void dmCleanupDnode(SDnode *pDnode) { dmClearVars(pDnode); rpcCleanup(); indexCleanup(); + taosConvDestroy(); dDebug("dnode is closed, ptr:%p", pDnode); } diff --git a/source/os/src/osString.c b/source/os/src/osString.c index 329b039084..503b8e0c6b 100644 --- a/source/os/src/osString.c +++ b/source/os/src/osString.c @@ -143,14 +143,17 @@ SConv *gConv = NULL; int32_t convUsed = 0; int32_t gConvMaxNum = 0; -int32_t taosConvInit(int32_t maxNum) { - gConvMaxNum = maxNum * 2; +void taosConvInitImpl(void) { + gConvMaxNum = 512; gConv = taosMemoryCalloc(gConvMaxNum, sizeof(SConv)); for (int32_t i = 0; i < gConvMaxNum; ++i) { gConv[i].conv = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset); } +} - return 0; +static TdThreadOnce convInit = PTHREAD_ONCE_INIT; +void taosConvInit() { + taosThreadOnce(&convInit, taosConvInitImpl); } void taosConvDestroy() { @@ -162,10 +165,7 @@ void taosConvDestroy() { void taosAcquireConv(int32_t *idx) { if (0 == gConvMaxNum) { - gConv = taosMemoryCalloc(1, sizeof(SConv)); - gConv[0].conv = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset); - *idx = 0; - return; + taosConvInit(); } while (true) { -- GitLab