diff options
author | Thomas Haller <thaller@redhat.com> | 2014-04-23 17:12:45 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-06-05 18:12:57 +0200 |
commit | 9df3a23d26e1c2da04a0db9e048d01d358862145 (patch) | |
tree | 1a3f3320cb8470a6f2a7a80986bd1e92b13b1836 /include | |
parent | 8af001eae44caa65b714233f1870119a3129558e (diff) | |
download | NetworkManager-9df3a23d26e1c2da04a0db9e048d01d358862145.tar.gz |
nmtst: add nmtst_free()
Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/nm-test-utils.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h index 3d807153a0..c50f041851 100644 --- a/include/nm-test-utils.h +++ b/include/nm-test-utils.h @@ -26,6 +26,7 @@ #include <arpa/inet.h> #include <stdio.h> #include <unistd.h> +#include <stdlib.h> #include <glib.h> #include <glib-object.h> #include <string.h> @@ -100,9 +101,25 @@ BREAK_INNER_LOOPS: } +/* free instances allocated by nmtst (especially nmtst_init()) on shutdown + * to release memory. After nmtst_free(), the test is uninitialized again. */ +inline static void +nmtst_free (void) +{ + if (!nmtst_initialized ()) + return; + + g_rand_free (__nmtst_internal.rand0); + if (__nmtst_internal.rand) + g_rand_free (__nmtst_internal.rand); + + memset (&__nmtst_internal, 0, sizeof (__nmtst_internal)); +} + inline static void nmtst_init (int *argc, char ***argv, const char *log_level, const char *log_domains) { + static gsize atexit_registered = 0; const char *nmtst_debug; gboolean is_debug = FALSE; char *c_log_level = NULL, *c_log_domains = NULL; @@ -197,6 +214,11 @@ nmtst_init (int *argc, char ***argv, const char *log_level, const char *log_doma g_strfreev ((char **) g_array_free (debug_messages, FALSE)); g_free (c_log_level); g_free (c_log_domains); + + if (g_once_init_enter (&atexit_registered)) { + atexit (nmtst_free); + g_once_init_leave (&atexit_registered, 1); + } } inline static gboolean |