Skip to content

Commit

Permalink
Free fixed pattern.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Jan 31, 2024
1 parent e6c02a4 commit 3b5ba1c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions librz/util/regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ RZ_API RZ_OWN RzRegex *rz_regex_new(const char *pattern, RzRegexFlags cflags, Rz
RZ_LOG_ERROR("Unicode not supported by PCRE2 library.");
return NULL;
}
char *fixed_pat = NULL;
const char *pat = NULL;
if ((cflags & RZ_REGEX_EXTENDED) || (cflags & RZ_REGEX_EXTENDED_MORE)) {
if (!strchr(pattern, ' ')) {
pat = pattern;
} else {
// In PCRE2 with the extended flag set, ascii space cahracters ' ' are skipped.
// We need to replace them with \s unfortunately to keep our API stable.
char *tmp_ptr = strdup(pattern);
pat = rz_str_replace(tmp_ptr, " ", "\\s", 0);
pat = tmp_ptr;
fixed_pat = rz_str_replace(strdup(pattern), " ", "\\s", 1);
pat = fixed_pat;
}
} else {
pat = pattern;
Expand All @@ -62,6 +62,9 @@ RZ_API RZ_OWN RzRegex *rz_regex_new(const char *pattern, RzRegexFlags cflags, Rz
&err_num,
&err_off,
NULL);
if (fixed_pat) {
free(fixed_pat);
}
if (!regex) {
print_pcre2_err(err_num, err_off);
return NULL;
Expand Down

0 comments on commit 3b5ba1c

Please sign in to comment.