[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25522 - gnunet/src/regex
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25522 - gnunet/src/regex |
Date: |
Mon, 17 Dec 2012 20:10:43 +0100 |
Author: bartpolot
Date: 2012-12-17 20:10:43 +0100 (Mon, 17 Dec 2012)
New Revision: 25522
Modified:
gnunet/src/regex/regex_test_lib.c
Log:
- free memory
Modified: gnunet/src/regex/regex_test_lib.c
===================================================================
--- gnunet/src/regex/regex_test_lib.c 2012-12-17 16:24:56 UTC (rev 25521)
+++ gnunet/src/regex/regex_test_lib.c 2012-12-17 19:10:43 UTC (rev 25522)
@@ -39,6 +39,13 @@
};
+/**
+ * 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 @@
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 @@
/**
+ * 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,19 +168,21 @@
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;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25522 - gnunet/src/regex,
gnunet <=