Fix memory leak in pcre2test (found by Coverity Scan).

This commit is contained in:
Philip.Hazel 2017-05-07 15:55:41 +00:00
parent ba1c759c90
commit 587011e326
1 changed files with 47 additions and 36 deletions

View File

@ -5310,6 +5310,7 @@ it ends up back in the usual place. */
if (pat_patctl.convert_type != CONVERT_UNSET)
{
int rc;
int convert_return = PR_OK;
uint32_t convert_options = pat_patctl.convert_type;
void *converted_pattern;
PCRE2_SIZE converted_length;
@ -5338,32 +5339,42 @@ if (pat_patctl.convert_type != CONVERT_UNSET)
{
fprintf(outfile, "** Invalid glob separator '%c'\n",
pat_patctl.convert_glob_separator);
return PR_SKIP;
convert_return = PR_SKIP;
goto CONVERT_FINISH;
}
}
PCRE2_PATTERN_CONVERT(rc, pbuffer, patlen, convert_options,
&converted_pattern, &converted_length, con_context);
if (rc != 0)
{
fprintf(outfile, "** Pattern conversion error at offset %lu: ",
converted_length);
if (!print_error_message(rc, "", "\n")) return PR_ABEND;
return PR_SKIP;
convert_return = print_error_message(rc, "", "\n")? PR_SKIP:PR_ABEND;
}
/* Output the converted pattern, copy it, then free it. */
/* Output the converted pattern, then copy it. */
else
{
PCHARSV(converted_pattern, 0, converted_length, utf, outfile);
fprintf(outfile, "\n");
patlen = converted_length;
CONVERT_COPY(pbuffer, converted_pattern, converted_length + 1);
}
/* Free the converted pattern. */
CONVERT_FINISH:
if (pat_patctl.convert_length != 0)
free(converted_pattern);
else
PCRE2_CONVERTED_PATTERN_FREE(converted_pattern);
/* Return if conversion was unsuccessful. */
if (convert_return != PR_OK) return convert_return;
}
/* By default we pass a zero-terminated pattern, but a length is passed if