fix: memleak in initWktRegex

This commit is contained in:
Shungang Li 2024-08-06 15:39:12 +08:00
parent 3ef0acc115
commit 4068e3d73b
2 changed files with 25 additions and 5 deletions

View File

@ -147,7 +147,17 @@ static int32_t initWktRegex(pcre2_code **ppRegex, pcre2_match_data **ppMatchData
"*)(([-+]?[0-9]+\\.?[0-9]*)|([-+]?[0-9]*\\.?[0-9]+))(e[-+]?[0-9]+)?){1,3}( *))*( *)\\)))( *))*( *)\\)))( *))*( "
"*)\\)))|(GEOCOLLECTION\\((?R)(( *)(,)( *)(?R))*( *)\\))( *)$");
code = doRegComp(ppRegex, ppMatchData, wktPatternWithSpace);
pcre2_code *pRegex = NULL;
pcre2_match_data *pMatchData = NULL;
code = doRegComp(&pRegex, &pMatchData, wktPatternWithSpace);
if (code < 0) {
taosMemoryFree(wktPatternWithSpace);
return TSDB_CODE_OUT_OF_MEMORY;
}
*ppRegex = pRegex;
*ppMatchData = pMatchData;
taosMemoryFree(wktPatternWithSpace);
return code;
}

View File

@ -5,14 +5,24 @@ int32_t doRegComp(pcre2_code** ppRegex, pcre2_match_data** ppMatchData, const ch
int errorcode;
PCRE2_SIZE erroroffset;
*ppRegex = pcre2_compile((PCRE2_SPTR8)pattern, PCRE2_ZERO_TERMINATED, options, &errorcode, &erroroffset, NULL);
if (*ppRegex == NULL) {
pcre2_code* pRegex = NULL;
pcre2_match_data* pMatchData = NULL;
pRegex = pcre2_compile((PCRE2_SPTR8)pattern, PCRE2_ZERO_TERMINATED, options, &errorcode, &erroroffset, NULL);
if (pRegex == NULL) {
PCRE2_UCHAR buffer[256];
(void)pcre2_get_error_message(errorcode, buffer, sizeof(buffer));
return 1;
return -1;
}
*ppMatchData = pcre2_match_data_create_from_pattern(*ppRegex, NULL);
pMatchData = pcre2_match_data_create_from_pattern(pRegex, NULL);
if (pMatchData == NULL) {
pcre2_code_free(pRegex);
return -1;
}
*ppRegex = pRegex;
*ppMatchData = pMatchData;
return 0;
}