fix: fix mbs2ucs4 crash issue in taosd

This commit is contained in:
dapan1121 2022-07-30 11:31:05 +08:00
parent f1cb48fc08
commit 80a32d6235
4 changed files with 8 additions and 10 deletions

View File

@ -62,7 +62,6 @@ typedef int32_t TdUcs4;
int32_t taosUcs4len(TdUcs4 *ucs4); int32_t taosUcs4len(TdUcs4 *ucs4);
int64_t taosStr2int64(const char *str); int64_t taosStr2int64(const char *str);
int32_t taosConvInit(int32_t maxNum);
void taosConvDestroy(); void taosConvDestroy();
int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs); 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); bool taosMbsToUcs4(const char *mbs, size_t mbs_len, TdUcs4 *ucs4, int32_t ucs4_max_len, int32_t *len);

View File

@ -361,8 +361,6 @@ void taos_init_imp(void) {
initQueryModuleMsgHandle(); initQueryModuleMsgHandle();
taosConvInit(256);
rpcInit(); rpcInit();
SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100}; SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100};

View File

@ -215,6 +215,7 @@ void dmCleanupDnode(SDnode *pDnode) {
dmClearVars(pDnode); dmClearVars(pDnode);
rpcCleanup(); rpcCleanup();
indexCleanup(); indexCleanup();
taosConvDestroy();
dDebug("dnode is closed, ptr:%p", pDnode); dDebug("dnode is closed, ptr:%p", pDnode);
} }

View File

@ -143,14 +143,17 @@ SConv *gConv = NULL;
int32_t convUsed = 0; int32_t convUsed = 0;
int32_t gConvMaxNum = 0; int32_t gConvMaxNum = 0;
int32_t taosConvInit(int32_t maxNum) { void taosConvInitImpl(void) {
gConvMaxNum = maxNum * 2; gConvMaxNum = 512;
gConv = taosMemoryCalloc(gConvMaxNum, sizeof(SConv)); gConv = taosMemoryCalloc(gConvMaxNum, sizeof(SConv));
for (int32_t i = 0; i < gConvMaxNum; ++i) { for (int32_t i = 0; i < gConvMaxNum; ++i) {
gConv[i].conv = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset); gConv[i].conv = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
} }
}
return 0; static TdThreadOnce convInit = PTHREAD_ONCE_INIT;
void taosConvInit() {
taosThreadOnce(&convInit, taosConvInitImpl);
} }
void taosConvDestroy() { void taosConvDestroy() {
@ -162,10 +165,7 @@ void taosConvDestroy() {
void taosAcquireConv(int32_t *idx) { void taosAcquireConv(int32_t *idx) {
if (0 == gConvMaxNum) { if (0 == gConvMaxNum) {
gConv = taosMemoryCalloc(1, sizeof(SConv)); taosConvInit();
gConv[0].conv = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
*idx = 0;
return;
} }
while (true) { while (true) {