r20741 - gnucash/trunk/src - Correct memory leaks found with valgrind
J. Alex Aycinena
alex.aycinena at code.gnucash.org
Wed Jun 8 20:29:41 EDT 2011
Author: alex.aycinena
Date: 2011-06-08 20:29:41 -0400 (Wed, 08 Jun 2011)
New Revision: 20741
Trac: http://svn.gnucash.org/trac/changeset/20741
Modified:
gnucash/trunk/src/app-utils/option-util.c
gnucash/trunk/src/gnome-utils/dialog-options.c
Log:
Correct memory leaks found with valgrind
Modified: gnucash/trunk/src/app-utils/option-util.c
===================================================================
--- gnucash/trunk/src/app-utils/option-util.c 2011-06-08 18:14:09 UTC (rev 20740)
+++ gnucash/trunk/src/app-utils/option-util.c 2011-06-09 00:29:41 UTC (rev 20741)
@@ -908,6 +908,8 @@
gnc_option_permissible_value_name(GNCOption *option, int index)
{
SCM name;
+ char * str;
+ char * string;
if (index < 0)
return NULL;
@@ -921,7 +923,13 @@
if (!scm_is_string(name))
return NULL;
- return g_strdup(scm_to_locale_string(name));
+ scm_dynwind_begin (0);
+ str = scm_to_locale_string (name);
+ string = g_strdup (str);
+ scm_dynwind_free (str);
+ scm_dynwind_end ();
+
+ return string;
}
@@ -939,6 +947,8 @@
gnc_option_permissible_value_description(GNCOption *option, int index)
{
SCM help;
+ char * str;
+ char * string;
if (index < 0)
return NULL;
@@ -952,7 +962,13 @@
if (!scm_is_string(help))
return NULL;
- return g_strdup(scm_to_locale_string(help));
+ scm_dynwind_begin (0);
+ str = scm_to_locale_string (help);
+ string = g_strdup (str);
+ scm_dynwind_free (str);
+ scm_dynwind_end ();
+
+ return string;
}
@@ -1713,6 +1729,7 @@
char *section, *name;
const gchar *message;
const gchar *format = _("There is a problem with option %s:%s.\n%s");
+ char * str;
/* Second element is error message */
oops = SCM_CADR(result);
@@ -1722,7 +1739,11 @@
return;
}
- message = scm_to_locale_string(oops);
+ scm_dynwind_begin (0);
+ str = scm_to_locale_string (oops);
+ message = g_strdup (str);
+ scm_dynwind_free (str);
+ scm_dynwind_end ();
name = gnc_option_name(option);
section = gnc_option_section(option);
@@ -1750,6 +1771,7 @@
free(name);
if (section != NULL)
free(section);
+ g_free ((gpointer *) message);
}
}
@@ -1912,6 +1934,8 @@
{
SCM getter;
SCM value;
+ char * str;
+ char * string;
if (odb == NULL)
return NULL;
@@ -1924,7 +1948,12 @@
if (!scm_is_string(value))
return NULL;
- return g_strdup(scm_to_locale_string(value));
+ scm_dynwind_begin (0);
+ str = scm_to_locale_string (value);
+ string = g_strdup (str);
+ scm_dynwind_free (str);
+ scm_dynwind_end ();
+ return string;
}
@@ -2030,7 +2059,16 @@
{
value = scm_call_0(getter);
if (scm_is_string(value))
- return g_strdup(scm_to_locale_string(value));
+ {
+ char * str;
+ char * string;
+ scm_dynwind_begin (0);
+ str = scm_to_locale_string (value);
+ string = g_strdup (str);
+ scm_dynwind_free (str);
+ scm_dynwind_end ();
+ return string;
+ }
}
}
@@ -2771,7 +2809,16 @@
break;
if (custom)
- *custom = g_strdup(scm_to_locale_string(val));
+ {
+ char * tmp_str;
+ char * string;
+ scm_dynwind_begin (0);
+ tmp_str = scm_to_locale_string (val);
+ string = g_strdup (tmp_str);
+ scm_dynwind_free (tmp_str);
+ scm_dynwind_end ();
+ *custom = string;
+ }
return FALSE;
Modified: gnucash/trunk/src/gnome-utils/dialog-options.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-options.c 2011-06-08 18:14:09 UTC (rev 20740)
+++ gnucash/trunk/src/gnome-utils/dialog-options.c 2011-06-09 00:29:41 UTC (rev 20741)
@@ -2250,8 +2250,17 @@
{
if (scm_is_string(value))
{
- const gchar *string = scm_to_locale_string(value);
+ const gchar *string;
+ char * str;
+
+ scm_dynwind_begin (0);
+ str = scm_to_locale_string (value);
+ string = g_strdup (str);
+ scm_dynwind_free (str);
+ scm_dynwind_end ();
+
gtk_entry_set_text(GTK_ENTRY(widget), string);
+ g_free ((gpointer *) string);
return FALSE;
}
else
@@ -2271,8 +2280,17 @@
if (scm_is_string(value))
{
- const gchar *string = scm_to_locale_string(value);
+ const gchar *string;
+ char * str;
+
+ scm_dynwind_begin (0);
+ str = scm_to_locale_string (value);
+ string = g_strdup (str);
+ scm_dynwind_free (str);
+ scm_dynwind_end ();
+
gtk_text_buffer_set_text (buffer, string, scm_c_string_length(value));
+ g_free ((gpointer *) string);
return FALSE;
}
else
@@ -2560,12 +2578,21 @@
{
if (scm_is_string(value))
{
- const gchar *string = scm_to_locale_string(value);
+ const gchar *string;
+ char * str;
+
+ scm_dynwind_begin (0);
+ str = scm_to_locale_string (value);
+ string = g_strdup (str);
+ scm_dynwind_free (str);
+ scm_dynwind_end ();
+
if ((string != NULL) && (*string != '\0'))
{
GtkFontButton *font_button = GTK_FONT_BUTTON(widget);
gtk_font_button_set_font_name(font_button, string);
}
+ g_free ((gpointer *) string);
return FALSE;
}
else
@@ -2579,8 +2606,15 @@
ENTER("option %p(%s)", option, gnc_option_name(option));
if (scm_is_string(value))
{
- const gchar *string = scm_to_locale_string(value);
+ const gchar *string;
+ char * str;
+ scm_dynwind_begin (0);
+ str = scm_to_locale_string (value);
+ string = g_strdup (str);
+ scm_dynwind_free (str);
+ scm_dynwind_end ();
+
if (string && *string)
{
gchar *test;
@@ -2593,6 +2627,7 @@
gnc_image_option_update_preview_cb(GTK_FILE_CHOOSER(widget), option);
}
LEAVE("FALSE");
+ g_free ((gpointer *) string);
return FALSE;
}
More information about the gnucash-changes
mailing list