[glib/wip/gcleanup: 14/21] option-context: Fix leaks in tests



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

    option-context: Fix leaks in tests
    
    https://bugzilla.gnome.org/show_bug.cgi?id=627423

 glib/tests/option-context.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)
---
diff --git a/glib/tests/option-context.c b/glib/tests/option-context.c
index 75ec4fd..33a48bf 100644
--- a/glib/tests/option-context.c
+++ b/glib/tests/option-context.c
@@ -2249,11 +2249,13 @@ flag_reverse_string (void)
   GOptionEntry entries [] =
     { { "test", 't', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_STRING, &arg, NULL, NULL },
       { NULL } };
-  gchar **argv;
   gint argc;
   gboolean retval;
   GError *error = NULL;
 
+  gchar *args[] = { "program", "--test", "bla" };
+  gchar **argv = args;
+
   if (!g_test_undefined ())
     return;
 
@@ -2264,12 +2266,11 @@ flag_reverse_string (void)
   g_option_context_add_main_entries (context, entries, NULL);
   g_test_assert_expected_messages ();
 
-  argv = split_string ("program --test bla", &argc);
-
+  argc = G_N_ELEMENTS (args);
   retval = g_option_context_parse (context, &argc, &argv, &error);
   g_assert (retval == TRUE);
   g_assert_no_error (error);
-  g_strfreev (argv);
+  g_free (arg);
   g_option_context_free (context);
 }
 
@@ -2281,11 +2282,13 @@ flag_optional_int (void)
   GOptionEntry entries [] =
     { { "test", 't', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &arg, NULL, NULL },
       { NULL } };
-  gchar **argv;
   gint argc;
   gboolean retval;
   GError *error = NULL;
 
+  gchar *args[] = { "program", "--test", "5" };
+  gchar **argv = args;
+
   if (!g_test_undefined ())
     return;
 
@@ -2296,12 +2299,10 @@ flag_optional_int (void)
   g_option_context_add_main_entries (context, entries, NULL);
   g_test_assert_expected_messages ();
 
-  argv = split_string ("program --test 5", &argc);
-
+  argc = G_N_ELEMENTS (args);
   retval = g_option_context_parse (context, &argc, &argv, &error);
   g_assert (retval == TRUE);
   g_assert_no_error (error);
-  g_strfreev (argv);
   g_option_context_free (context);
 }
 


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