From: Ben Pfaff Date: Fri, 8 Apr 2011 04:05:31 +0000 (-0700) Subject: gui: widget-io: Fix cleanup code in widget_printf(), widget_scanf(). X-Git-Tag: v0.7.8~85 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=commitdiff_plain;h=4142c5a08fc22235c21f686f2979a4c1c83741b7 gui: widget-io: Fix cleanup code in widget_printf(), widget_scanf(). The 'arg' member of arguments and the 'dir' member of char_directives are only allocated from malloc() if there are more than fit in the arrays that are included inside their respective structures, so they must only be freed when that internal structure is not used. Also, these arrays are allocated with malloc() and so must be freed with free(), not g_free(). Thanks to Benoit Flippen for reporting the problem. --- diff --git a/src/ui/gui/widget-io.c b/src/ui/gui/widget-io.c index 3771cad6..73a73016 100644 --- a/src/ui/gui/widget-io.c +++ b/src/ui/gui/widget-io.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007, 2009 Free Software Foundation + Copyright (C) 2007, 2009, 2011 Free Software Foundation This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -100,7 +100,8 @@ widget_printf (const gchar *fmt, ...) } va_end (ap); - g_free (a.arg); + if (a.arg != a.direct_alloc_arg) + free (a.arg); output = g_string_sized_new (strlen (fmt)); @@ -128,7 +129,8 @@ widget_printf (const gchar *fmt, ...) } free (widgets); - free (d.dir); + if (d.dir != d.direct_alloc_dir) + free (d.dir); if (*s) g_string_append_len (output, s, -1); @@ -162,7 +164,8 @@ widget_scanf (const gchar *fmt, ...) if ( 0 != printf_parse (fmt, &d, &a) ) return NULL; - g_free (a.arg); + if (a.arg != a.direct_alloc_arg) + free (a.arg); va_start (ap, fmt); @@ -232,7 +235,8 @@ widget_scanf (const gchar *fmt, ...) g_free (widgets); - free (d.dir); + if (d.dir != d.direct_alloc_dir) + free (d.dir); return hbox; }