r20644 - gnucash/trunk/src/gnome - Correct memory leaks found with Valgrind.
J. Alex Aycinena
alex.aycinena at code.gnucash.org
Sat May 14 12:17:08 EDT 2011
Author: alex.aycinena
Date: 2011-05-14 12:17:07 -0400 (Sat, 14 May 2011)
New Revision: 20644
Trac: http://svn.gnucash.org/trac/changeset/20644
Modified:
gnucash/trunk/src/gnome/dialog-tax-info.c
Log:
Correct memory leaks found with Valgrind.
Modified: gnucash/trunk/src/gnome/dialog-tax-info.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-tax-info.c 2011-05-13 20:22:32 UTC (rev 20643)
+++ gnucash/trunk/src/gnome/dialog-tax-info.c 2011-05-14 16:17:07 UTC (rev 20644)
@@ -275,14 +275,15 @@
{
TXFInfo *txf_info;
SCM code_scm;
- const gchar *str;
const gchar *last_yr = _("Last Valid Year: ");
const gchar *form_line = _("Form Line Data: ");
const gchar *code_line_word = _("Code");
const gchar *code_line_colon = ": ";
- const gchar *num_code = NULL;
const gchar *prefix = "N";
+ gchar *str = NULL;
+ gchar *num_code = NULL;
gchar *form_line_data = NULL;
+ gchar *help_text = NULL;
SCM scm;
gint year;
gboolean cpy;
@@ -292,9 +293,13 @@
scm = scm_call_3 (getters.payer_name_source, category, code_scm,
tax_entity_type);
- str = scm_is_symbol(scm) ? SCM_SYMBOL_CHARS (scm) : "";
+ if (scm_is_symbol(scm))
+ str = g_strdup (SCM_SYMBOL_CHARS (scm));
+ else
+ str = g_strdup ("");
if (safe_strcmp (str, "not-impl") == 0)
{
+ g_free (str);
continue;
}
@@ -304,79 +309,144 @@
txf_info->payer_name_source = NULL;
else
txf_info->payer_name_source = g_strdup (str);
+ g_free (str);
- str = scm_is_symbol(code_scm) ? SCM_SYMBOL_CHARS(code_scm) : "";
+ if (scm_is_symbol(code_scm))
+ str = g_strdup (SCM_SYMBOL_CHARS (code_scm));
+ else
+ str = g_strdup ("");
txf_info->code = g_strdup (str);
- num_code = g_strdup (str);
- if (g_str_has_prefix (num_code, prefix))
- num_code++; /* to lose the leading N */
+ if (g_str_has_prefix (str, prefix))
+ {
+ const gchar *num_code_tmp;
+ num_code_tmp = g_strdup (str);
+ num_code_tmp++; /* to lose the leading N */
+ num_code = g_strdup (num_code_tmp);
+ num_code_tmp--;
+ g_free ((gpointer *) num_code_tmp);
+ }
+ else
+ num_code = g_strdup (str);
+ g_free (str);
scm = scm_call_3 (getters.form, category, code_scm, tax_entity_type);
- str = scm_is_string(scm) ? scm_to_locale_string(scm) : "";
- txf_info->form = g_strdup (str);
+ if (scm_is_string(scm))
+ {
+ scm_dynwind_begin (0);
+ str = scm_to_locale_string(scm);
+ txf_info->form = g_strdup (str);
+ scm_dynwind_free (str);
+ scm_dynwind_end ();
+ }
+ else
+ txf_info->form = g_strdup ("");
scm = scm_call_3 (getters.description, category, code_scm, tax_entity_type);
- str = scm_is_string(scm) ? scm_to_locale_string(scm) : "";
- txf_info->description = g_strdup (str);
+ if (scm_is_string(scm))
+ {
+ scm_dynwind_begin (0);
+ str = scm_to_locale_string(scm);
+ txf_info->description = g_strdup (str);
+ scm_dynwind_free (str);
+ scm_dynwind_end ();
+ }
+ else
+ txf_info->description = g_strdup ("");
scm = scm_call_2 (getters.help, category, code_scm);
- str = scm_is_string(scm) ? scm_to_locale_string(scm) : "";
+ if (scm_is_string(scm))
+ {
+ scm_dynwind_begin (0);
+ str = scm_to_locale_string(scm);
+ help_text = g_strdup (str);
+ scm_dynwind_free (str);
+ scm_dynwind_end ();
+ }
+ else
+ help_text = g_strdup ("");
+
scm = scm_call_3 (getters.last_year, category, code_scm, tax_entity_type);
year = scm_is_bool (scm) ? 0 : scm_to_int(scm);
scm = scm_call_3 (getters.line_data, category, code_scm, tax_entity_type);
if (scm_is_list (scm))
{
- const gchar *until = _("now");
+ const gchar *now = _("now");
+ gchar *until;
+ until = (gchar *) now;
form_line_data = g_strconcat ("\n", "\n", form_line, NULL);
while (!scm_is_null (scm))
{
SCM year_scm;
gint line_year;
- const gchar *line;
- gchar *temp;
+ gchar *line = NULL;
+ gchar *temp = NULL;
+ gchar *temp2 = NULL;
year_scm = SCM_CAR (scm);
scm = SCM_CDR (scm);
line_year = scm_is_bool (SCM_CAR (year_scm)) ? 0 :
scm_to_int (SCM_CAR (year_scm));
- line = scm_is_string((SCM_CAR (SCM_CDR (year_scm))))
- ? scm_to_locale_string((SCM_CAR (SCM_CDR (year_scm)))) : "";
- temp = g_strconcat (form_line_data, "\n",
- g_strdup_printf ("%d", line_year), " - ", until,
- " ", line, NULL);
+ if (scm_is_string((SCM_CAR (SCM_CDR (year_scm)))))
+ {
+ gchar *temp_line;
+ scm_dynwind_begin (0);
+ temp_line = scm_to_locale_string((SCM_CAR (SCM_CDR
+ (year_scm))));
+ line = g_strdup (temp_line);
+ scm_dynwind_free (temp_line);
+ scm_dynwind_end ();
+ }
+ else
+ line = g_strdup ("");
+ temp2 = g_strdup_printf ("%d", line_year);
+ temp = g_strconcat (form_line_data, "\n", temp2, " - ",
+ until, " ", line, NULL);
+ if (until != now)
+ g_free (until);
until = g_strdup_printf ("%d", (line_year - 1));
- g_free(form_line_data);
+ g_free (form_line_data);
form_line_data = g_strdup (temp);
- g_free(temp);
+ g_free (line);
+ g_free (temp);
+ g_free (temp2);
}
+ if (safe_strcmp (until, now) != 0)
+ g_free (until);
}
if (year != 0)
{
+ gchar *temp = g_strdup_printf("%d", year);
if (form_line_data != NULL)
- txf_info->help = g_strconcat (last_yr, g_strdup_printf ("%d", year),
- "\n", "\n", str, "\n", "\n",
- code_line_word, code_line_colon, num_code,
+ txf_info->help = g_strconcat (last_yr, temp, "\n", "\n",
+ help_text, "\n", "\n",
+ code_line_word,
+ code_line_colon, num_code,
form_line_data, NULL);
else
- txf_info->help = g_strconcat (last_yr, g_strdup_printf ("%d", year),
- "\n", "\n", str, "\n", "\n",
- code_line_word, code_line_colon, num_code, NULL);
+ txf_info->help = g_strconcat (last_yr, temp, "\n", "\n",
+ help_text, "\n", "\n",
+ code_line_word,
+ code_line_colon, num_code, NULL);
+ g_free (temp);
}
else
{
if (form_line_data != NULL)
- txf_info->help = g_strconcat (str, "\n", "\n",
- code_line_word, code_line_colon, num_code,
+ txf_info->help = g_strconcat (help_text, "\n", "\n",
+ code_line_word,
+ code_line_colon, num_code,
form_line_data, NULL);
else
- txf_info->help = g_strconcat (str, "\n", "\n",
- code_line_word, code_line_colon, num_code, NULL);
+ txf_info->help = g_strconcat (help_text, "\n", "\n",
+ code_line_word,
+ code_line_colon, num_code, NULL);
}
- if (form_line_data != NULL)
- g_free(form_line_data);
+ g_free (num_code);
+ g_free (help_text);
+ g_free (form_line_data);
scm = scm_call_3 (getters.copy, category, code_scm, tax_entity_type);
cpy = scm_is_bool (scm) ? (scm_is_false (scm) ? FALSE : TRUE): FALSE;
@@ -419,7 +489,7 @@
{
TaxTypeInfo *tax_type_info;
SCM type_scm;
- const gchar *str;
+ gchar *str = NULL;
SCM scm;
type_scm = SCM_CAR (tax_types);
@@ -429,24 +499,45 @@
tax_type_info = g_new0 (TaxTypeInfo, 1);
- str = scm_is_symbol(type_scm) ? SCM_SYMBOL_CHARS(type_scm) : "";
+ if (scm_is_symbol(type_scm))
+ str = g_strdup (SCM_SYMBOL_CHARS (type_scm));
+ else
+ str = g_strdup ("");
tax_type_info->type_code = g_strdup (str);
+ g_free (str);
scm = scm_call_1 (getters.tax_entity_type, type_scm);
- str = scm_is_string(scm) ? scm_to_locale_string (scm) : "";
- tax_type_info->type = g_strdup (str);
+ if (scm_is_string(scm))
+ {
+ scm_dynwind_begin (0);
+ str = scm_to_locale_string(scm);
+ tax_type_info->type = g_strdup (str);
+ scm_dynwind_free (str);
+ scm_dynwind_end ();
+ }
+ else
+ tax_type_info->type = g_strdup ("");
scm = scm_call_1 (getters.tax_entity_desc, type_scm);
- str = scm_is_string(scm) ? scm_to_locale_string (scm) : "";
- tax_type_info->description = g_strdup (str);
-
- tax_type_info->combo_box_entry = g_strconcat(tax_type_info->type, " - ",
+ if (scm_is_string(scm))
+ {
+ scm_dynwind_begin (0);
+ str = scm_to_locale_string(scm);
+ tax_type_info->description = g_strdup (str);
+ scm_dynwind_free (str);
+ scm_dynwind_end ();
+ }
+ else
+ tax_type_info->description = g_strdup ("");
+
+ tax_type_info->combo_box_entry = g_strconcat(tax_type_info->type,
+ " - ",
tax_type_info->description, NULL);
/* save combo text for current tax type code */
if (safe_strcmp (ti_dialog->tax_type, tax_type_info->type_code) == 0)
- ti_dialog->tax_type_combo_text = g_strdup (tax_type_info->combo_box_entry);
+ ti_dialog->tax_type_combo_text = tax_type_info->combo_box_entry;
/* the last will be default */
- ti_dialog->default_tax_type = g_strdup (tax_type_info->combo_box_entry);
+ ti_dialog->default_tax_type = tax_type_info->combo_box_entry;
types = g_list_prepend (types, tax_type_info);
}
@@ -671,6 +762,7 @@
xaccAccountCommitEdit (account);
}
+ g_list_free (accounts);
}
static void
@@ -1021,7 +1113,7 @@
{
ti_dialog->tax_type_changed = TRUE;
gnc_set_current_book_tax_type (entry_type);
- ti_dialog->tax_type = g_strdup (entry_type);
+ ti_dialog->tax_type = entry_type;
if (entry_type != NULL)
{
gtk_label_set_text (GTK_LABEL (ti_dialog->entity_type_display),
@@ -1032,9 +1124,17 @@
gtk_label_set_text (GTK_LABEL (ti_dialog->entity_type_display),
ti_dialog->default_tax_type);
}
+ if (ti_dialog->income_txf_infos != NULL)
+ destroy_txf_infos (ti_dialog->income_txf_infos);
ti_dialog->income_txf_infos = load_txf_info (INCOME, ti_dialog);
+ if (ti_dialog->expense_txf_infos != NULL)
+ destroy_txf_infos (ti_dialog->expense_txf_infos);
ti_dialog->expense_txf_infos = load_txf_info (EXPENSE, ti_dialog);
+ if (ti_dialog->asset_txf_infos != NULL)
+ destroy_txf_infos (ti_dialog->asset_txf_infos);
ti_dialog->asset_txf_infos = load_txf_info (ASSET, ti_dialog);
+ if (ti_dialog->liab_eq_txf_infos != NULL)
+ destroy_txf_infos (ti_dialog->liab_eq_txf_infos);
ti_dialog->liab_eq_txf_infos = load_txf_info (LIAB_EQ, ti_dialog);
gtk_toggle_button_set_active
(GTK_TOGGLE_BUTTON(ti_dialog->expense_radio), TRUE);
@@ -1322,7 +1422,8 @@
/* account tree */
{
- GtkWidget *income_radio, *expense_radio, *asset_radio, *liab_eq_radio, *box;
+ GtkWidget *income_radio, *expense_radio, *asset_radio,
+ *liab_eq_radio, *box;
ti_dialog->acct_info = glade_xml_get_widget (xml, "acct_info_vbox");
box = glade_xml_get_widget (xml, "account_scroll");
More information about the gnucash-changes
mailing list