After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 647031 - Bug in GApplicationCommandLine example code
Bug in GApplicationCommandLine example code
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: docs
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-04-07 13:06 UTC by Shaun McCance
Modified: 2011-04-08 21:03 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Shaun McCance 2011-04-07 13:06:42 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?
Comment 1 Matthias Clasen 2011-04-08 21:03:33 UTC
Thanks, fixed