diff options
author | bartpolot <bartpolot@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-12-17 19:10:43 +0000 |
---|---|---|
committer | bartpolot <bartpolot@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-12-17 19:10:43 +0000 |
commit | 7f3d792391ba96a3264b93448d41833986f69ef8 (patch) | |
tree | 33db348a47d5a517d4147173f6a2130dc09483c3 /src/regex/regex_test_lib.c | |
parent | 9e34e8e2ceeea0b02c73663b68039ea67239087d (diff) |
- free memory
git-svn-id: https://gnunet.org/svn/gnunet@25522 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src/regex/regex_test_lib.c')
-rw-r--r-- | src/regex/regex_test_lib.c | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/src/regex/regex_test_lib.c b/src/regex/regex_test_lib.c index d02afa942c..9863d6f4f2 100644 --- a/src/regex/regex_test_lib.c +++ b/src/regex/regex_test_lib.c @@ -39,6 +39,13 @@ struct RegexCombineCtx { }; +/** + * Extract a string from all prefix-combined regexes. + * + * @param ctx Context with 0 or more regexes. + * + * @return Regex that matches any of the added regexes. + */ static char * regex_combine (struct RegexCombineCtx *ctx) { @@ -76,6 +83,13 @@ regex_combine (struct RegexCombineCtx *ctx) return regex; } + +/** + * Add a single regex to a context, combining with exisiting regex by-prefix. + * + * @param ctx Context with 0 or more regexes. + * @param regex Regex to add. + */ static void regex_add (struct RegexCombineCtx *ctx, const char *regex) { @@ -120,6 +134,27 @@ regex_add (struct RegexCombineCtx *ctx, const char *regex) /** + * Free all resources used by the context node and all its children. + * + * @param ctx Context to free. + */ +static void +regex_ctx_destroy (struct RegexCombineCtx *ctx) +{ + struct RegexCombineCtx *p; + struct RegexCombineCtx *next; + + for (p = ctx->head; NULL != p; p = next) + { + next = p->next; + regex_ctx_destroy (p); + } + GNUNET_free (ctx->s); + GNUNET_free (ctx); +} + + +/** * Return a prefix-combine regex that matches the same strings as * any of the original regexes. * @@ -133,18 +168,20 @@ GNUNET_REGEX_combine (char * const regexes[]) unsigned int i; char *combined; const char *current; - struct RegexCombineCtx ctx; + struct RegexCombineCtx *ctx; - memset (&ctx, 0, sizeof (struct RegexCombineCtx)); + ctx = GNUNET_malloc (sizeof (struct RegexCombineCtx)); for (i = 0; regexes[i]; i++) { current = regexes[i]; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Regex %u: %s\n", i, current); - regex_add (&ctx, current); + regex_add (ctx, current); } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\nCombining...\n"); - combined = regex_combine (&ctx); + combined = regex_combine (ctx); + + regex_ctx_destroy (ctx); return combined; } |