mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Fix memory leak using qof_instance_get on a GncGUID
The underlying boxed type will return a copy so we should free this when no longer needed.
This commit is contained in:
parent
3845611f30
commit
3634e8f59d
@ -389,6 +389,7 @@ gnc_tree_util_split_reg_template_get_transfer_entry (Split *split)
|
||||
"sx-account", &guid,
|
||||
NULL);
|
||||
account = xaccAccountLookup (guid, gnc_get_current_book ());
|
||||
guid_free (guid);
|
||||
name = account ? gnc_get_account_name_for_register (account) : NULL;
|
||||
|
||||
return name;
|
||||
|
@ -626,6 +626,7 @@ gnc_payment_dialog_owner_changed (PaymentWindow *pw)
|
||||
"payment-last-account", &guid,
|
||||
NULL);
|
||||
last_acct = xaccAccountLookup(guid, pw->book);
|
||||
guid_free (guid);
|
||||
if (last_acct)
|
||||
gnc_tree_view_account_set_selected_account(GNC_TREE_VIEW_ACCOUNT(pw->acct_tree),
|
||||
last_acct);
|
||||
|
@ -643,6 +643,7 @@ gnc_sxed_split_check_account (GncSxEditorDialog *sxed, Split *s,
|
||||
"sx-account", &acct_guid,
|
||||
NULL);
|
||||
acct = xaccAccountLookup (acct_guid, gnc_get_current_book ());
|
||||
guid_free (acct_guid);
|
||||
if (acct == NULL)
|
||||
return FALSE;
|
||||
split_cmdty = xaccAccountGetCommodity(acct);
|
||||
|
@ -617,6 +617,7 @@ gnc_sxed_check_consistent (GncSxEditorDialog2 *sxed)
|
||||
"sx-debit-formula", &debit_formula,
|
||||
NULL);
|
||||
acct = xaccAccountLookup( acct_guid, gnc_get_current_book ());
|
||||
guid_free (acct_guid);
|
||||
split_cmdty = xaccAccountGetCommodity(acct);
|
||||
if (base_cmdty == NULL)
|
||||
{
|
||||
|
@ -3683,6 +3683,7 @@ gnc_plugin_page_register2_cmd_schedule (GtkAction *action,
|
||||
((guid_equal (xaccSchedXactionGetGUID (sx), fromSXId))
|
||||
? sx : NULL);
|
||||
}
|
||||
guid_free (fromSXId);
|
||||
|
||||
if (theSX)
|
||||
{
|
||||
|
@ -1477,6 +1477,7 @@ gsr_default_schedule_handler( GNCSplitReg *gsr, gpointer data )
|
||||
((guid_equal (xaccSchedXactionGetGUID (sx), fromSXId))
|
||||
? sx : NULL);
|
||||
}
|
||||
guid_free (fromSXId);
|
||||
|
||||
if ( theSX )
|
||||
{
|
||||
|
@ -81,13 +81,16 @@ static const char *PROP_OFX_INCOME_ACCOUNT = "ofx-income-account";
|
||||
static Account*
|
||||
get_associated_income_account(const Account* investment_account)
|
||||
{
|
||||
GncGUID *income_guid= NULL;
|
||||
GncGUID *income_guid = NULL;
|
||||
Account *acct = NULL;
|
||||
g_assert(investment_account);
|
||||
qof_instance_get (QOF_INSTANCE (investment_account),
|
||||
PROP_OFX_INCOME_ACCOUNT, &income_guid,
|
||||
NULL);
|
||||
return xaccAccountLookup(income_guid,
|
||||
gnc_account_get_book(investment_account));
|
||||
PROP_OFX_INCOME_ACCOUNT, &income_guid,
|
||||
NULL);
|
||||
acct = xaccAccountLookup (income_guid,
|
||||
gnc_account_get_book(investment_account));
|
||||
guid_free (income_guid);
|
||||
return acct;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -266,6 +266,7 @@ _get_vars_helper(Transaction *txn, void *var_hash_data)
|
||||
"sx-debit-formula", &debit_formula,
|
||||
NULL);
|
||||
acct = xaccAccountLookup(acct_guid, gnc_get_current_book());
|
||||
guid_free (acct_guid);
|
||||
split_cmdty = xaccAccountGetCommodity(acct);
|
||||
// existing... ------------------------------------------
|
||||
if (credit_formula && strlen(credit_formula) != 0)
|
||||
@ -974,6 +975,7 @@ _get_template_split_account(const SchedXaction* sx,
|
||||
Account **split_acct,
|
||||
GList **creation_errors)
|
||||
{
|
||||
gboolean success = TRUE;
|
||||
GncGUID *acct_guid = NULL;
|
||||
qof_instance_get (QOF_INSTANCE (template_split),
|
||||
"sx-account", &acct_guid,
|
||||
@ -987,10 +989,11 @@ _get_template_split_account(const SchedXaction* sx,
|
||||
gchar* err = N_("Unknown account for guid [%s], cancelling SX [%s] creation.");
|
||||
guid_to_string_buff((const GncGUID*)acct_guid, guid_str);
|
||||
REPORT_ERROR(creation_errors, err, guid_str, xaccSchedXactionGetName(sx));
|
||||
return FALSE;
|
||||
success = FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
guid_free (acct_guid);
|
||||
return success;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -386,8 +386,11 @@ gnc_book_get_default_gain_loss_acct (QofBook *book)
|
||||
if (!book) return NULL;
|
||||
|
||||
if (gnc_book_use_book_currency (book))
|
||||
gains_account = xaccAccountLookup
|
||||
(qof_book_get_default_gain_loss_acct_guid (book), book);
|
||||
{
|
||||
GncGUID *guid = qof_book_get_default_gain_loss_acct_guid (book);
|
||||
gains_account = xaccAccountLookup (guid, book);
|
||||
guid_free (guid);
|
||||
}
|
||||
|
||||
if (gains_account &&
|
||||
!xaccAccountGetPlaceholder(gains_account) &&
|
||||
|
@ -380,9 +380,9 @@ gnc_sx_get_sxes_referencing_account(QofBook *book, Account *acct)
|
||||
GncGUID *guid = NULL;
|
||||
qof_instance_get (QOF_INSTANCE (s), "sx-account", &guid, NULL);
|
||||
if (guid_equal(acct_guid, guid))
|
||||
{
|
||||
rtn = g_list_append(rtn, sx);
|
||||
}
|
||||
|
||||
guid_free (guid);
|
||||
}
|
||||
}
|
||||
return rtn;
|
||||
|
@ -495,6 +495,7 @@ xaccSplitGetCapGainsSplit (const Split *split)
|
||||
gains_split = (Split*) qof_collection_lookup_entity (
|
||||
qof_instance_get_collection(split), gains_guid);
|
||||
PINFO ("split=%p has gains-split=%p", split, gains_split);
|
||||
guid_free (gains_guid);
|
||||
return gains_split;
|
||||
}
|
||||
|
||||
@ -517,6 +518,7 @@ xaccSplitGetGainsSourceSplit (const Split *split)
|
||||
source_split = (Split*) qof_collection_lookup_entity(
|
||||
qof_instance_get_collection(split), source_guid);
|
||||
PINFO ("split=%p has source-split=%p", split, source_split);
|
||||
guid_free (source_guid);
|
||||
return source_split;
|
||||
}
|
||||
|
||||
|
@ -637,14 +637,14 @@ gnc_budget_get_default (QofBook *book)
|
||||
{
|
||||
QofCollection *col;
|
||||
GncBudget *bgt = NULL;
|
||||
const GncGUID *default_budget_guid = NULL;
|
||||
GncGUID *default_budget_guid = NULL;
|
||||
|
||||
g_return_val_if_fail(book, NULL);
|
||||
|
||||
qof_instance_get (QOF_INSTANCE (book),
|
||||
"default-budget", &default_budget_guid,
|
||||
NULL);
|
||||
if (default_budget_guid != NULL)
|
||||
if (default_budget_guid)
|
||||
{
|
||||
col = qof_book_get_collection(book, GNC_ID_BUDGET);
|
||||
bgt = (GncBudget *) qof_collection_lookup_entity(col,
|
||||
@ -662,6 +662,7 @@ gnc_budget_get_default (QofBook *book)
|
||||
}
|
||||
}
|
||||
|
||||
guid_free (default_budget_guid);
|
||||
return bgt;
|
||||
}
|
||||
|
||||
|
@ -1250,12 +1250,15 @@ GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot)
|
||||
{
|
||||
GncGUID *guid = NULL;
|
||||
QofBook *book;
|
||||
GncInvoice *invoice = NULL;
|
||||
|
||||
if (!lot) return NULL;
|
||||
|
||||
book = gnc_lot_get_book (lot);
|
||||
qof_instance_get (QOF_INSTANCE (lot), "invoice", &guid, NULL);
|
||||
return gncInvoiceLookup(book, guid);
|
||||
invoice = gncInvoiceLookup(book, guid);
|
||||
guid_free (guid);
|
||||
return invoice;
|
||||
}
|
||||
|
||||
void
|
||||
@ -1279,12 +1282,15 @@ gncInvoiceGetInvoiceFromTxn (const Transaction *txn)
|
||||
{
|
||||
GncGUID *guid = NULL;
|
||||
QofBook *book;
|
||||
GncInvoice *invoice = NULL;
|
||||
|
||||
if (!txn) return NULL;
|
||||
|
||||
book = xaccTransGetBook (txn);
|
||||
qof_instance_get (QOF_INSTANCE (txn), "invoice", &guid, NULL);
|
||||
return gncInvoiceLookup(book, guid);
|
||||
invoice = gncInvoiceLookup(book, guid);
|
||||
guid_free (guid);
|
||||
return invoice;
|
||||
}
|
||||
|
||||
gboolean gncInvoiceAmountPositive (const GncInvoice *invoice)
|
||||
|
@ -641,9 +641,11 @@ gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner)
|
||||
gncOwnerInitJob (owner, gncJobLookup (book, guid));
|
||||
break;
|
||||
default:
|
||||
guid_free (guid);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
guid_free (guid);
|
||||
return (owner->owner.undefined != NULL);
|
||||
}
|
||||
|
||||
|
@ -1004,7 +1004,7 @@ qof_book_get_default_gains_policy (QofBook *book)
|
||||
* valid book-currency, both of which are required, for the 'book-currency'
|
||||
* currency accounting method to apply. Use instead
|
||||
* 'gnc_book_get_default_gain_loss_acct' which does these validations. */
|
||||
const GncGUID *
|
||||
GncGUID *
|
||||
qof_book_get_default_gain_loss_acct_guid (QofBook *book)
|
||||
{
|
||||
GncGUID *guid = NULL;
|
||||
|
@ -282,7 +282,7 @@ const gchar * qof_book_get_default_gains_policy (QofBook *book);
|
||||
* valid book-currency, both of which are required, for the 'book-currency'
|
||||
* currency accounting method to apply. Use instead
|
||||
* 'gnc_book_get_default_gain_loss_acct' which does these validations. */
|
||||
const GncGUID * qof_book_get_default_gain_loss_acct_guid (QofBook *book);
|
||||
GncGUID * qof_book_get_default_gain_loss_acct_guid (QofBook *book);
|
||||
|
||||
/** Returns TRUE if the auto-read-only feature should be used, otherwise
|
||||
* FALSE. This is just a wrapper on qof_book_get_num_days_autoreadonly() == 0. */
|
||||
|
@ -178,6 +178,9 @@ test_account_kvp_properties (Fixture *fixture, gconstpointer pData)
|
||||
g_assert_cmpint (ab_acct_uid, ==, ab_acct_uid_r);
|
||||
g_assert_cmpint (trans_retr.t, ==, trans_retr_r->t);
|
||||
g_assert (!qof_instance_is_dirty (QOF_INSTANCE (fixture->acct)));
|
||||
|
||||
guid_free (ofx_income_acct);
|
||||
guid_free (ofx_income_acct_r);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user