thread mem leak

This commit is contained in:
factosea 2024-04-17 20:06:29 +08:00
parent bac72b2dd2
commit 9c5f7d6656
3 changed files with 15 additions and 10 deletions

View File

@ -83,6 +83,7 @@ int32_t compareLenBinaryVal(const void *pLeft, const void *pRight);
int32_t comparestrRegexMatch(const void *pLeft, const void *pRight);
int32_t comparestrRegexNMatch(const void *pLeft, const void *pRight);
void DestoryThreadLocalRegComp();
int32_t comparewcsRegexMatch(const void *pLeft, const void *pRight);
int32_t comparewcsRegexNMatch(const void *pLeft, const void *pRight);

View File

@ -24,7 +24,6 @@
#include "tutil.h"
#include "types.h"
#include "osString.h"
#include <pthread.h>
int32_t setChkInBytes1(const void *pLeft, const void *pRight) {
return NULL != taosHashGet((SHashObj *)pRight, pLeft, 1) ? 1 : 0;
@ -1204,19 +1203,16 @@ int32_t comparestrRegexNMatch(const void *pLeft, const void *pRight) {
return comparestrRegexMatch(pLeft, pRight) ? 0 : 1;
}
static threadlocal regex_t pRegex;
static threadlocal char *pOldPattern;
static regex_t *threadGetRegComp(const char *pPattern) {
static __thread regex_t pRegex;
static __thread char *pOldPattern;
if (NULL != pOldPattern) {
if( strcmp(pOldPattern, pPattern) == 0) {
return &pRegex;
} else {
regfree(&pRegex);
taosMemoryFree(pOldPattern);
pOldPattern == NULL;
DestoryThreadLocalRegComp();
}
}
pOldPattern = taosMemoryMalloc(strlen(pPattern) + 1);
if (NULL == pOldPattern) {
uError("Failed to Malloc when compile regex pattern %s.", pPattern);
@ -1229,14 +1225,20 @@ static regex_t *threadGetRegComp(const char *pPattern) {
char msgbuf[256] = {0};
regerror(ret, &pRegex, msgbuf, tListLen(msgbuf));
uError("Failed to compile regex pattern %s. reason %s", pPattern, msgbuf);
regfree(&pRegex);
taosMemoryFree(pOldPattern);
pOldPattern == NULL;
DestoryThreadLocalRegComp();
return NULL;
}
return &pRegex;
}
void DestoryThreadLocalRegComp() {
if (NULL != pOldPattern) {
regfree(&pRegex);
taosMemoryFree(pOldPattern);
pOldPattern == NULL;
}
}
static int32_t doExecRegexMatch(const char *pString, const char *pPattern) {
int32_t ret = 0;
char msgbuf[256] = {0};

View File

@ -18,6 +18,7 @@
#include "taoserror.h"
#include "tgeosctx.h"
#include "tlog.h"
#include "tcompare.h"
#define QUEUE_THRESHOLD (1000 * 1000)
@ -103,6 +104,7 @@ static void *tQWorkerThreadFp(SQueueWorker *worker) {
}
destroyThreadLocalGeosCtx();
DestoryThreadLocalRegComp();
return NULL;
}