gdesktopappinfo: Pass a copy of the URIs list to expand_application_parameters()

This list will be modified in-place when calling expand_macro(), so pass a copy
of it instead the original pointer, that is supposed to be an input parameter
only for g_desktop_app_info_launch_uris_with_spawn().

https://bugzilla.gnome.org/show_bug.cgi?id=791337
This commit is contained in:
Mario Sanchez Prada
2017-12-07 13:33:20 +00:00
committed by Philip Withnall
parent 2c066d5d39
commit d42115b013

View File

@@ -2658,6 +2658,8 @@ g_desktop_app_info_launch_uris_with_spawn (GDesktopAppInfo *info,
{ {
gboolean completed = FALSE; gboolean completed = FALSE;
GList *old_uris; GList *old_uris;
GList *dup_uris;
char **argv, **envp; char **argv, **envp;
int argc; int argc;
ChildSetupData data; ChildSetupData data;
@@ -2671,6 +2673,11 @@ g_desktop_app_info_launch_uris_with_spawn (GDesktopAppInfo *info,
else else
envp = g_get_environ (); envp = g_get_environ ();
/* The GList* passed to expand_application_parameters() will be modified
* internally by expand_macro(), so we need to pass a copy of it instead,
* and also use that copy to control the exit condition of the loop below.
*/
dup_uris = g_list_copy (uris);
do do
{ {
GPid pid; GPid pid;
@@ -2678,13 +2685,13 @@ g_desktop_app_info_launch_uris_with_spawn (GDesktopAppInfo *info,
GList *iter; GList *iter;
char *sn_id = NULL; char *sn_id = NULL;
old_uris = uris; old_uris = dup_uris;
if (!expand_application_parameters (info, exec_line, &uris, &argc, &argv, error)) if (!expand_application_parameters (info, exec_line, &dup_uris, &argc, &argv, error))
goto out; goto out;
/* Get the subset of URIs we're launching with this process */ /* Get the subset of URIs we're launching with this process */
launched_uris = NULL; launched_uris = NULL;
for (iter = old_uris; iter != NULL && iter != uris; iter = iter->next) for (iter = old_uris; iter != NULL && iter != dup_uris; iter = iter->next)
launched_uris = g_list_prepend (launched_uris, iter->data); launched_uris = g_list_prepend (launched_uris, iter->data);
launched_uris = g_list_reverse (launched_uris); launched_uris = g_list_reverse (launched_uris);
@@ -2780,11 +2787,12 @@ g_desktop_app_info_launch_uris_with_spawn (GDesktopAppInfo *info,
g_strfreev (argv); g_strfreev (argv);
argv = NULL; argv = NULL;
} }
while (uris != NULL); while (dup_uris != NULL);
completed = TRUE; completed = TRUE;
out: out:
g_list_free (dup_uris);
g_strfreev (argv); g_strfreev (argv);
g_strfreev (envp); g_strfreev (envp);