[gedit/wip/gtkapp: 14/16] we actually need the ugly hack on both sides :(



commit 6b2d24566d5231d0f1512136c767b2b431c0cfb3
Author: Paolo Borelli <pborelli gnome org>
Date:   Tue Jul 31 16:57:02 2012 +0200

    we actually need the ugly hack on both sides :(

 gedit/gedit-app.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
---
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index 53c25bc..52b3fb7 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -578,6 +578,8 @@ gedit_app_command_line (GApplication            *application,
 	GError *error = NULL;
 	gint argc;
 	gchar **argv;
+	gchar **argv_tofree;
+	gint i;
 
 	/* reset values */
 	g_free (encoding_charset);
@@ -599,6 +601,15 @@ gedit_app_command_line (GApplication            *application,
 
 	argv = g_application_command_line_get_arguments (command_line, &argc);
 
+	/* We have to make an extra copy of the array, since g_option_context_parse()
+	 * assumes that it can remove strings from the array without freeing them.
+	 */
+	argv_tofree = g_new (gchar*, argc + 1);
+	for (i = 0; i <= argc; i++)
+	{
+		argv[i] = argv[i];
+	}
+
 	/* Setup command line options */
 	context = g_option_context_new (_("- Edit text files"));
 	g_option_context_set_help_enabled (context, FALSE);
@@ -639,6 +650,7 @@ gedit_app_command_line (GApplication            *application,
 	}
 
 	g_option_context_free (context);
+	g_free (argv_tofree);
 
 	return 0;
 }



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