summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/nslog/nslog.h18
-rw-r--r--src/core.c15
-rw-r--r--test/basictests.c6
3 files changed, 36 insertions, 3 deletions
diff --git a/include/nslog/nslog.h b/include/nslog/nslog.h
index 0288f5d..9113527 100644
--- a/include/nslog/nslog.h
+++ b/include/nslog/nslog.h
@@ -258,6 +258,24 @@ nslog_error nslog_set_render_callback(nslog_callback cb, void *context);
nslog_error nslog_uncork(void);
/**
+ * Finalise log categories, release filter handles, etc.
+ *
+ * Since logging categories can have memory allocated to them at runtime,
+ * and the logging filters can have references held inside the library,
+ * clients which wish to be 'valgrind clean' may wish to call this to
+ * ensure that any memory allocated inside the nslog library is released.
+ *
+ * This does not remove the active log callback, so logging calls after this
+ * returns will still work (though will be unfiltered). Of course, they will
+ * cause memory to be allocated once more. This function can be called as
+ * many times as desired, it is idempotent.
+ *
+ * If the logging was corked when this was called, pending corked messages
+ * will be delivered if necessary before any filters are removed.
+ */
+void nslog_cleanup(void);
+
+/**
* Log filter handle
*
* nslog allows clients to set a complex filter which can be used to restrict
diff --git a/src/core.c b/src/core.c
index b09a002..15cb79a 100644
--- a/src/core.c
+++ b/src/core.c
@@ -164,3 +164,18 @@ nslog_error nslog_uncork()
return NSLOG_UNCORKED;
}
}
+
+void nslog_cleanup()
+{
+ nslog_category_t *cat = nslog__all_categories;
+ (void)nslog_uncork();
+ (void)nslog_filter_set_active(NULL, NULL);
+ while (cat != NULL) {
+ nslog_category_t *nextcat = cat->next;
+ free(cat->name);
+ cat->name = NULL;
+ cat->namelen = 0;
+ cat->next = NULL;
+ cat = nextcat;
+ }
+}
diff --git a/test/basictests.c b/test/basictests.c
index a331b2f..19e8bd2 100644
--- a/test/basictests.c
+++ b/test/basictests.c
@@ -61,7 +61,7 @@ with_simple_context_setup(void)
static void
with_simple_context_teardown(void)
{
- /* Nothing to do to tear down */
+ nslog_cleanup();
}
START_TEST (test_nslog_trivial_corked_message)
@@ -194,12 +194,12 @@ with_simple_filter_context_setup(void)
static void
with_simple_filter_context_teardown(void)
{
- /* Nothing to do to tear down */
fail_unless(nslog_filter_set_active(NULL, NULL) == NSLOG_NO_ERROR,
"Unable to clear active filter");
cat_test = nslog_filter_unref(cat_test);
cat_another = nslog_filter_unref(cat_another);
cat_test_sub = nslog_filter_unref(cat_test_sub);
+ nslog_cleanup();
}
START_TEST (test_nslog_simple_filter_corked_message)
@@ -377,9 +377,9 @@ with_trivial_filter_context_setup(void)
static void
with_trivial_filter_context_teardown(void)
{
- /* Nothing to do to tear down */
fail_unless(nslog_filter_set_active(NULL, NULL) == NSLOG_NO_ERROR,
"Unable to clear active filter");
+ nslog_cleanup();
}
START_TEST (test_nslog_filter_filename)