r20378 - gnucash/trunk/src - Correct memory leaks found with valgrind
J. Alex Aycinena
alex.aycinena at code.gnucash.org
Sat Mar 5 18:29:12 EST 2011
Author: alex.aycinena
Date: 2011-03-05 18:29:12 -0500 (Sat, 05 Mar 2011)
New Revision: 20378
Trac: http://svn.gnucash.org/trac/changeset/20378
Modified:
gnucash/trunk/src/app-utils/gnc-ui-util.c
gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c
gnucash/trunk/src/gnome/gnc-plugin-page-register.c
Log:
Correct memory leaks found with valgrind
Modified: gnucash/trunk/src/app-utils/gnc-ui-util.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.c 2011-03-05 17:31:24 UTC (rev 20377)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.c 2011-03-05 23:29:12 UTC (rev 20378)
@@ -463,13 +463,12 @@
static SCM get_desc = SCM_UNDEFINED;
gboolean tax_related = FALSE;
- const char *code;
- const gchar *tax_type;
+ const char *code = NULL;
+ const gchar *tax_type = NULL;
GNCAccountType atype;
SCM category;
SCM code_scm;
SCM tax_entity_type;
- const gchar *form, *desc, *copy_txt;
gint64 copy_number;
SCM scm;
@@ -500,10 +499,12 @@
{
const gchar *num_code = NULL;
const gchar *prefix = "N";
+ char *return_string = NULL;
tax_type = gnc_get_current_book_tax_type ();
if (tax_type == NULL || (safe_strcmp (tax_type, "") == 0))
return g_strdup (_("Tax entity type not specified"));
+
atype = xaccAccountGetType (account);
/* tax_entity_type = scm_from_locale_string (tax_type); <- requires guile 1.8*/
tax_entity_type = scm_makfrom0str (tax_type); /* <-guile 1.6 */
@@ -561,89 +562,129 @@
(atype == ACCT_TYPE_PAYABLE)) ?
"txf-liab-eq-categories" : ""))));
- num_code = g_strdup (code);
- if (g_str_has_prefix (num_code, prefix))
- num_code++; /* to lose the leading N */
-
- if (category == SCM_UNDEFINED)
+ if (g_str_has_prefix (code, prefix))
{
- if (tax_related)
- return g_strdup_printf
- (_("Tax type %s: invalid code %s for account type"),
- tax_type, num_code);
- else
- return g_strdup_printf
- (_("Not tax-related; tax type %s: invalid code %s for account type"),
- tax_type, num_code);
+ const gchar *num_code_tmp;
+ num_code_tmp = g_strdup (code);
+ num_code_tmp++; /* to lose the leading N */
+ num_code = g_strdup (num_code_tmp);
+ num_code_tmp--;
+ g_free ((gpointer *) num_code_tmp);
}
-
- code_scm = scm_str2symbol (code);
- scm = scm_call_3 (get_form, category, code_scm, tax_entity_type);
- if (!scm_is_string (scm))
+ else
{
- if (tax_related)
- return g_strdup_printf
- (_("Invalid code %s for tax type %s"),
- num_code, tax_type);
- else
- return g_strdup_printf
- (_("Not tax-related; invalid code %s for tax type %s"),
- num_code, tax_type);
+ num_code = g_strdup (code);
}
- form = scm_to_locale_string (scm);
- if (!form)
+ if (category == SCM_UNDEFINED)
{
if (tax_related)
- return g_strdup_printf
- (_("No form: code %s, tax type %s"), num_code, tax_type);
+ return_string = g_strdup_printf
+ (_("Tax type %s: invalid code %s for account type"),
+ tax_type, num_code);
else
- return g_strdup_printf
- (_("Not tax-related; no form: code %s, tax type %s"),
- num_code, tax_type);
+ return_string = g_strdup_printf
+ (_("Not tax-related; tax type %s: invalid code %s for account type"),
+ tax_type, num_code);
}
-
- scm = scm_call_3 (get_desc, category, code_scm, tax_entity_type);
- if (!scm_is_string (scm))
+ else
{
- if (tax_related)
- return g_strdup_printf
- (_("No description: form %s, code %s, tax type %s"),
- form, num_code, tax_type);
+ code_scm = scm_str2symbol (code);
+ scm = scm_call_3 (get_form, category, code_scm,
+ tax_entity_type);
+ if (!scm_is_string (scm))
+ {
+ if (tax_related)
+ return_string = g_strdup_printf
+ (_("Invalid code %s for tax type %s"),
+ num_code, tax_type);
+ else
+ return_string = g_strdup_printf
+ (_("Not tax-related; invalid code %s for tax type %s"),
+ num_code, tax_type);
+ }
else
- return g_strdup_printf
- (_("Not tax-related; no description: form %s, code %s, tax type %s"),
- form, num_code, tax_type);
- }
+ {
+ const gchar *form = NULL;
- desc = scm_to_locale_string (scm);
- if (!desc)
- {
- if (tax_related)
- return g_strdup_printf
- (_("No description: form %s, code %s, tax type %s"),
- form, num_code, tax_type);
- else
- return g_strdup_printf
- (_("Not tax-related; no description: form %s, code %s, tax type %s"),
- form, num_code, tax_type);
- }
+ form = scm_to_locale_string (scm);
+ if (!form)
+ {
+ if (tax_related)
+ return_string = g_strdup_printf
+ (_("No form: code %s, tax type %s"),
+ num_code, tax_type);
+ else
+ return_string = g_strdup_printf
+ (_("Not tax-related; no form: code %s, tax type %s"),
+ num_code, tax_type);
+ }
+ else
+ {
+ scm = scm_call_3 (get_desc, category, code_scm,
+ tax_entity_type);
+ if (!scm_is_string (scm))
+ {
+ if (tax_related)
+ return_string = g_strdup_printf
+ (_("No description: form %s, code %s, tax type %s"),
+ form, num_code, tax_type);
+ else
+ return_string = g_strdup_printf
+ (_("Not tax-related; no description: form %s, code %s, tax type %s"),
+ form, num_code, tax_type);
+ }
+ else
+ {
+ const gchar *desc = NULL;
- copy_number = xaccAccountGetTaxUSCopyNumber (account);
- copy_txt = (copy_number == 1) ? "" : g_strdup_printf ("(%d)",
- (gint) copy_number);
+ desc = scm_to_locale_string (scm);
+ if (!desc)
+ {
+ if (tax_related)
+ return_string = g_strdup_printf
+ (_("No description: form %s, code %s, tax type %s"),
+ form, num_code, tax_type);
+ else
+ return_string = g_strdup_printf
+ (_("Not tax-related; no description: form %s, code %s, tax type %s"),
+ form, num_code, tax_type);
+ }
+ else
+ {
+ const gchar *copy_txt = NULL;
- if (tax_related)
- {
- if (safe_strcmp (form, "") == 0)
- return g_strdup_printf ("%s", desc);
- else
- return g_strdup_printf ("%s%s: %s", form, copy_txt, desc);
+ copy_number
+ = xaccAccountGetTaxUSCopyNumber (account);
+ copy_txt = (copy_number == 1) ?
+ g_strdup ("") :
+ g_strdup_printf ("(%d)",
+ (gint) copy_number);
+ if (tax_related)
+ {
+ if (safe_strcmp (form, "") == 0)
+ return_string
+ = g_strdup_printf ("%s", desc);
+ else
+ return_string
+ = g_strdup_printf ("%s%s: %s",
+ form, copy_txt, desc);
+ }
+ else
+ return_string = g_strdup_printf
+ (_("Not tax-related; %s%s: %s (code %s, tax type %s)"),
+ form, copy_txt, desc, num_code,
+ tax_type);
+ g_free ((gpointer *) copy_txt);
+ }
+ g_free ((gpointer *) desc);
+ }
+ }
+ g_free ((gpointer *) form);
+ }
}
- else
- return g_strdup_printf
- (_("Not tax-related; %s%s: %s (code %s, tax type %s)"),
- form, copy_txt, desc, num_code, tax_type);
+ g_free ((gpointer *) num_code);
+ return return_string;
}
}
Modified: gnucash/trunk/src/gnome/gnc-plugin-page-register.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-register.c 2011-03-05 17:31:24 UTC (rev 20377)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-register.c 2011-03-05 23:29:12 UTC (rev 20378)
@@ -1359,10 +1359,15 @@
switch (ledger_type)
{
case LD_SINGLE:
- return g_strdup(gnc_account_get_full_name (leader));
+ return gnc_account_get_full_name (leader);
case LD_SUBACCOUNT:
- return g_strdup_printf("%s+", gnc_account_get_full_name (leader));
+ {
+ gchar *account_full_name = gnc_account_get_full_name (leader);
+ gchar *return_string = g_strdup_printf("%s+", account_full_name);
+ g_free ((gpointer *) account_full_name);
+ return return_string;
+ }
default:
break;
Modified: gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c 2011-03-05 17:31:24 UTC (rev 20377)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c 2011-03-05 23:29:12 UTC (rev 20378)
@@ -484,7 +484,7 @@
GtkTreeIter *iter,
gpointer view)
{
- const gchar *tax_info, *tax_info_sub_acct;
+ gchar *tax_info = NULL;
GtkTreePath *path;
gtk_tree_model_get(model,
@@ -493,35 +493,44 @@
&tax_info,
-1);
- if (tax_info == NULL)
- tax_info = "";
path = gtk_tree_model_get_path(model, iter);
if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(view), path))
- g_object_set(renderer, "text", tax_info, NULL);
+ g_object_set(renderer, "text",
+ (tax_info == NULL ? "" : tax_info), NULL);
else
{
+ gchar *tax_info_sub_acct = NULL;
+
gtk_tree_model_get(model,
iter,
GNC_TREE_MODEL_ACCOUNT_COL_TAX_INFO_SUB_ACCT,
&tax_info_sub_acct,
-1);
- if (tax_info_sub_acct == NULL)
- tax_info_sub_acct = "";
- if (safe_strcmp (tax_info_sub_acct, "") == 0)
- g_object_set(renderer, "text", tax_info, NULL);
+ if ((safe_strcmp (tax_info_sub_acct, "") == 0) ||
+ (tax_info_sub_acct == NULL))
+ g_object_set(renderer, "text",
+ (tax_info == NULL ? "" : tax_info), NULL);
else
{
- if (safe_strcmp (tax_info, "") == 0)
- g_object_set(renderer, "text", tax_info_sub_acct, NULL);
+ if ((safe_strcmp (tax_info, "") == 0) ||
+ (tax_info == NULL))
+ g_object_set(renderer, "text",
+ (tax_info_sub_acct == NULL ? "" : tax_info_sub_acct),
+ NULL);
else
{
- const gchar *combined_tax_info;
- combined_tax_info = g_strdup_printf ("%s; %s", tax_info,
- tax_info_sub_acct);
+ gchar *combined_tax_info;
+ combined_tax_info = g_strdup_printf ("%s; %s",
+ (tax_info == NULL ? "" : tax_info),
+ (tax_info_sub_acct == NULL ? "" :
+ tax_info_sub_acct));
g_object_set(renderer, "text", combined_tax_info, NULL);
+ g_free(combined_tax_info);
}
}
+ g_free(tax_info_sub_acct);
}
+ g_free(tax_info);
gtk_tree_path_free(path);
}
More information about the gnucash-changes
mailing list