提交 77837f6e 编写于 作者: D dapan1121

fix: fix crash issue

上级 80a32d62
...@@ -62,6 +62,7 @@ typedef int32_t TdUcs4; ...@@ -62,6 +62,7 @@ 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);
void taosConvInit(void);
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);
......
...@@ -361,6 +361,8 @@ void taos_init_imp(void) { ...@@ -361,6 +361,8 @@ void taos_init_imp(void) {
initQueryModuleMsgHandle(); initQueryModuleMsgHandle();
taosConvInit();
rpcInit(); rpcInit();
SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100}; SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100};
......
...@@ -218,6 +218,8 @@ int mainWindows(int argc,char** argv) { ...@@ -218,6 +218,8 @@ int mainWindows(int argc,char** argv) {
taosCleanupArgs(); taosCleanupArgs();
return -1; return -1;
} }
taosConvInit();
if (global.dumpConfig) { if (global.dumpConfig) {
dmDumpCfg(); dmDumpCfg();
......
...@@ -143,29 +143,29 @@ SConv *gConv = NULL; ...@@ -143,29 +143,29 @@ SConv *gConv = NULL;
int32_t convUsed = 0; int32_t convUsed = 0;
int32_t gConvMaxNum = 0; int32_t gConvMaxNum = 0;
void taosConvInitImpl(void) { void taosConvInit(void) {
gConvMaxNum = 512; 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);
if ((iconv_t)-1 == gConv[i].conv || (iconv_t)0 == gConv[i].conv) {
ASSERT(0);
}
} }
} }
static TdThreadOnce convInit = PTHREAD_ONCE_INIT;
void taosConvInit() {
taosThreadOnce(&convInit, taosConvInitImpl);
}
void taosConvDestroy() { void taosConvDestroy() {
for (int32_t i = 0; i < gConvMaxNum; ++i) { for (int32_t i = 0; i < gConvMaxNum; ++i) {
iconv_close(gConv[i].conv); iconv_close(gConv[i].conv);
} }
taosMemoryFreeClear(gConv); taosMemoryFreeClear(gConv);
gConvMaxNum = -1;
} }
void taosAcquireConv(int32_t *idx) { iconv_t taosAcquireConv(int32_t *idx) {
if (0 == gConvMaxNum) { if (gConvMaxNum <= 0) {
taosConvInit(); *idx = -1;
return iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
} }
while (true) { while (true) {
...@@ -193,12 +193,12 @@ void taosAcquireConv(int32_t *idx) { ...@@ -193,12 +193,12 @@ void taosAcquireConv(int32_t *idx) {
} }
*idx = startId; *idx = startId;
return gConv[startId].conv;
} }
void taosReleaseConv(int32_t idx) { void taosReleaseConv(int32_t idx, iconv_t conv) {
if (0 == gConvMaxNum) { if (idx < 0) {
iconv_close(gConv[0].conv); iconv_close(conv);
taosMemoryFreeClear(gConv);
return; return;
} }
...@@ -213,16 +213,16 @@ bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4 ...@@ -213,16 +213,16 @@ bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4
#else #else
memset(ucs4, 0, ucs4_max_len); memset(ucs4, 0, ucs4_max_len);
int32_t idx = 0; int32_t idx = -1;
taosAcquireConv(&idx); iconv_t conv = taosAcquireConv(&idx);
size_t ucs4_input_len = mbsLength; size_t ucs4_input_len = mbsLength;
size_t outLeft = ucs4_max_len; size_t outLeft = ucs4_max_len;
if (iconv(gConv[idx].conv, (char **)&mbs, &ucs4_input_len, (char **)&ucs4, &outLeft) == -1) { if (iconv(conv, (char **)&mbs, &ucs4_input_len, (char **)&ucs4, &outLeft) == -1) {
taosReleaseConv(idx); taosReleaseConv(idx, conv);
return false; return false;
} }
taosReleaseConv(idx); taosReleaseConv(idx, conv);
if (len != NULL) { if (len != NULL) {
*len = (int32_t)(ucs4_max_len - outLeft); *len = (int32_t)(ucs4_max_len - outLeft);
if (*len < 0) { if (*len < 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册