GNOME Bugzilla – Bug 647031
Bug in GApplicationCommandLine example code
Last modified: 2011-04-08 21:03:33 UTC
http://developer.gnome.org/gio/unstable/GApplicationCommandLine.html#gapplication-example-cmdline2 for (j = i + 1; argv[j]; j++) { argv[j - 1] = argv[j]; argv[j] = NULL; } If you're on the last argument (i.e. argv[i + 1] == NULL), you won't get a single iteration of this loop, and the argument won't be popped. I think this simpler loop works correctly: for (j = i; argv[j]; j++) { argv[j] = argv[j + 1]; } Also, my understanding here is that the arguments as passed are a deep copy. If that's the case, I believe the popped option is being leaked by this code. Shouldn't it g_free (argv[i]) before the loop?
Thanks, fixed