From 25c5e370e776ceb0e9cf3d6b70997582d5be7788 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Sat, 12 Jan 2019 14:18:21 +0000 Subject: [PATCH] libre2c_posix: fixed memleaks. --- re2c/Makefile.libre2c_posix.am | 1 + re2c/libre2c_posix/regcomp.cc | 1 + re2c/libre2c_posix/regex.h | 4 +++- re2c/libre2c_posix/regfree.cc | 22 ++++++++++++++++++++++ re2c/libre2c_posix/test.cpp | 2 ++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 re2c/libre2c_posix/regfree.cc diff --git a/re2c/Makefile.libre2c_posix.am b/re2c/Makefile.libre2c_posix.am index 34036407..05729ede 100644 --- a/re2c/Makefile.libre2c_posix.am +++ b/re2c/Makefile.libre2c_posix.am @@ -72,6 +72,7 @@ libre2c_posix_a_HDR = \ libre2c_posix_a_SRC = \ libre2c_posix/regcomp.cc \ libre2c_posix/regexec.cc \ + libre2c_posix/regfree.cc \ libre2c_posix/stubs.cc \ src/parse/ast.cc \ src/options/msg.cc \ diff --git a/re2c/libre2c_posix/regcomp.cc b/re2c/libre2c_posix/regcomp.cc index 0a2e994f..3c8334c8 100644 --- a/re2c/libre2c_posix/regcomp.cc +++ b/re2c/libre2c_posix/regcomp.cc @@ -52,5 +52,6 @@ int regcomp(regex_t *preg, const char *pattern, int /* cflags */) preg->nfa = nfa; preg->dfa = dfa; + delete opt; return 0; } diff --git a/re2c/libre2c_posix/regex.h b/re2c/libre2c_posix/regex.h index 31242d1a..ef166b43 100644 --- a/re2c/libre2c_posix/regex.h +++ b/re2c/libre2c_posix/regex.h @@ -4,13 +4,15 @@ #include #include +#include "src/util/c99_stdint.h" + // fwd namespace re2c { struct nfa_t; struct dfa_t; } -typedef ssize_t regoff_t; +typedef ptrdiff_t regoff_t; struct regex_t { const re2c::nfa_t *nfa; diff --git a/re2c/libre2c_posix/regfree.cc b/re2c/libre2c_posix/regfree.cc new file mode 100644 index 00000000..d0d95962 --- /dev/null +++ b/re2c/libre2c_posix/regfree.cc @@ -0,0 +1,22 @@ +#include "libre2c_posix/regex.h" +#include "src/nfa/nfa.h" +#include "src/dfa/dfa.h" + + +using namespace re2c; + +void regfree(regex_t *preg) +{ + const nfa_t *nfa = preg->nfa; + const dfa_t *dfa = preg->dfa; + + delete &dfa->charset; + delete &dfa->rules; + delete &dfa->tags; + delete &dfa->mtagvers; + delete[] dfa->finvers; + delete &dfa->tcpool; + + delete dfa; + delete nfa; +} diff --git a/re2c/libre2c_posix/test.cpp b/re2c/libre2c_posix/test.cpp index c1463c53..6a46a0e0 100644 --- a/re2c/libre2c_posix/test.cpp +++ b/re2c/libre2c_posix/test.cpp @@ -50,7 +50,9 @@ int test(const char *pattern, const char *string, size_t nmatch, ...) end: va_end(vl); + regfree(&re); delete[] pmatch; + return result; } -- 2.40.0