};
+/**
+ * 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)
{
}
len = strlen (regex);
if (1 == len)
+ {
+ GNUNET_free (regex);
return GNUNET_strdup ("");
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pre-partial: %s\n", regex);
if ('|' == regex[len - 1])
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)
{
}
+/**
+ * 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.
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;
}
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Can't get size of file %s\n", filename);
+ GNUNET_DISK_file_close (f);
return NULL;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
GNUNET_array_grow (regexes, nr, nr + 1);
regexes[nr - 2] = regex;
regexes[nr - 1] = NULL;
+ regex = NULL;
} while (offset < size);
+ GNUNET_free_non_null (regex);
GNUNET_free (buffer);
return regexes;