[glib/wip/gcleanup: 27/79] private: Fix memory leak in tests



commit 31ae3ed153082e5c88da9ed376f1c997f0012c1a
Author: Stef Walter <stefw gnome org>
Date:   Thu Oct 31 14:41:34 2013 +0100

    private: Fix memory leak in tests
    
    Don't use g_private_new(), it's deprecated, and leaks by definition.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711751

 glib/tests/private.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)
---
diff --git a/glib/tests/private.c b/glib/tests/private.c
index c647719..63c7b43 100644
--- a/glib/tests/private.c
+++ b/glib/tests/private.c
@@ -32,20 +32,18 @@
 static void
 test_private1 (void)
 {
-  GPrivate *private1;
+  static GPrivate private = G_PRIVATE_INIT (NULL);
   gpointer value;
 
-  private1 = g_private_new (NULL);
-
-  value = g_private_get (private1);
+  value = g_private_get (&private);
   g_assert (value == NULL);
 
-  g_private_set (private1, GINT_TO_POINTER(1));
-  value = g_private_get (private1);
+  g_private_set (&private, GINT_TO_POINTER(1));
+  value = g_private_get (&private);
   g_assert_cmpint (GPOINTER_TO_INT (value), ==, 1);
 
-  g_private_set (private1, GINT_TO_POINTER(2));
-  value = g_private_get (private1);
+  g_private_set (&private, GINT_TO_POINTER(2));
+  value = g_private_get (&private);
   g_assert_cmpint (GPOINTER_TO_INT (value), ==, 2);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]