fix: fix crash issue
This commit is contained in:
parent
80a32d6235
commit
77837f6e6a
|
@ -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) {
|
||||||
|
|
||||||
initQueryModuleMsgHandle();
|
initQueryModuleMsgHandle();
|
||||||
|
|
||||||
|
taosConvInit();
|
||||||
|
|
||||||
rpcInit();
|
rpcInit();
|
||||||
|
|
||||||
SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100};
|
SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100};
|
||||||
|
|
|
@ -219,6 +219,8 @@ int mainWindows(int argc,char** argv) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
taosConvInit();
|
||||||
|
|
||||||
if (global.dumpConfig) {
|
if (global.dumpConfig) {
|
||||||
dmDumpCfg();
|
dmDumpCfg();
|
||||||
taosCleanupCfg();
|
taosCleanupCfg();
|
||||||
|
|
|
@ -143,17 +143,15 @@ 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() {
|
||||||
|
@ -161,11 +159,13 @@ void taosConvDestroy() {
|
||||||
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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
*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
|
||||||
#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) {
|
||||||
|
|
Loading…
Reference in New Issue