X-Git-Url: https://git.sur5r.net/?p=i3%2Fi3;a=blobdiff_plain;f=src%2Fregex.c;h=8f039157f6f7547d57e66733aa4bffdb23f72345;hp=9549a98b54ba36980fe956b8957e63d4e21f1c6b;hb=HEAD;hpb=884214f14fdbd0a4a368d2a36d5e50324fa1d52a diff --git a/src/regex.c b/src/regex.c index 9549a98b..8f039157 100644 --- a/src/regex.c +++ b/src/regex.c @@ -1,5 +1,3 @@ -#undef I3__FILE__ -#define I3__FILE__ "regex.c" /* * vim:ts=4:sw=4:expandtab * @@ -25,14 +23,12 @@ struct regex *regex_new(const char *pattern) { const char *error; int errorcode, offset; - struct regex *re = scalloc(sizeof(struct regex)); + struct regex *re = scalloc(1, sizeof(struct regex)); re->pattern = sstrdup(pattern); int options = PCRE_UTF8; -#ifdef PCRE_HAS_UCP /* We use PCRE_UCP so that \B, \b, \D, \d, \S, \s, \W, \w and some POSIX * character classes play nicely with Unicode */ options |= PCRE_UCP; -#endif while (!(re->regex = pcre_compile2(pattern, options, &errorcode, &error, &offset, NULL))) { /* If the error is that PCRE was not compiled with UTF-8 support we * disable it and try again */ @@ -42,6 +38,7 @@ struct regex *regex_new(const char *pattern) { } ELOG("PCRE regular expression compilation failed at %d: %s\n", offset, error); + regex_free(re); return NULL; } re->extra = pcre_study(re->regex, 0, &error); @@ -64,6 +61,7 @@ void regex_free(struct regex *regex) { FREE(regex->pattern); FREE(regex->regex); FREE(regex->extra); + FREE(regex); } /*