summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjell.ahlstedt@bredband.net>2016-08-31 19:09:52 +0200
committerMatthias Clasen <mclasen@redhat.com>2016-09-12 22:27:48 -0400
commitb12e0b886936099a5bcca834a582b3e51241bd4c (patch)
tree0482e18153f3f989ed2c9d8491df01bc48f1483e
parent7bf31065cca37f14aaf46e84c6944876fbeb5f21 (diff)
downloadglib-b12e0b886936099a5bcca834a582b3e51241bd4c.tar.gz
goption: Don't return pointers to deallocated memory
g_option_context_parse() can return pointers to deallocated strings, if the command line contains an unknown option. https://bugzilla.gnome.org/show_bug.cgi?id=646926
-rw-r--r--glib/goption.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/glib/goption.c b/glib/goption.c
index 0464c2e0b..3afdc96d2 100644
--- a/glib/goption.c
+++ b/glib/goption.c
@@ -1281,9 +1281,12 @@ parse_arg (GOptionContext *context,
change = get_change (context, G_OPTION_ARG_STRING,
entry->arg_data);
- g_free (change->allocated.str);
- change->prev.str = *(gchar **)entry->arg_data;
+ if (!change->allocated.str)
+ change->prev.str = *(gchar **)entry->arg_data;
+ else
+ g_free (change->allocated.str);
+
change->allocated.str = data;
*(gchar **)entry->arg_data = data;
@@ -1345,9 +1348,12 @@ parse_arg (GOptionContext *context,
#endif
change = get_change (context, G_OPTION_ARG_FILENAME,
entry->arg_data);
- g_free (change->allocated.str);
- change->prev.str = *(gchar **)entry->arg_data;
+ if (!change->allocated.str)
+ change->prev.str = *(gchar **)entry->arg_data;
+ else
+ g_free (change->allocated.str);
+
change->allocated.str = data;
*(gchar **)entry->arg_data = data;