gnucash maint: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Sun Sep 9 16:50:43 EDT 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/d069b67d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/3634e8f5 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/3845611f (commit)
	 via  https://github.com/Gnucash/gnucash/commit/4cc61463 (commit)
	from  https://github.com/Gnucash/gnucash/commit/bfa6cd52 (commit)



commit d069b67d48f99ef69d6a31c9dd428da67215b048
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Sun Sep 9 22:49:52 2018 +0200

    Fix memory leak in xaccTransGetReadOnly
    
    In addition implement a cache for this value as suggested in the comments
    as this function is called on every transaction commit.

diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c
index 8887191..36ced18 100644
--- a/gnucash/gnome/gnc-split-reg.c
+++ b/gnucash/gnome/gnc-split-reg.c
@@ -903,7 +903,7 @@ gnc_split_reg_reverse_trans_cb (GtkWidget *w, gpointer data)
 
 
 static gboolean
-is_trans_readonly_and_warn (GtkWindow *parent, const Transaction *trans)
+is_trans_readonly_and_warn (GtkWindow *parent, Transaction *trans)
 {
     GtkWidget *dialog;
     const gchar *reason;
diff --git a/gnucash/register/ledger-core/split-register-model.c b/gnucash/register/ledger-core/split-register-model.c
index d4c28d5..34f887a 100644
--- a/gnucash/register/ledger-core/split-register-model.c
+++ b/gnucash/register/ledger-core/split-register-model.c
@@ -2030,7 +2030,7 @@ gnc_split_register_get_security_io_flags (VirtualLocation virt_loc,
 }
 
 static gboolean
-xaccTransWarnReadOnly (GtkWidget *parent, const Transaction *trans)
+xaccTransWarnReadOnly (GtkWidget *parent, Transaction *trans)
 {
     GtkWidget *dialog;
     const gchar *reason;
diff --git a/libgnucash/engine/Transaction.c b/libgnucash/engine/Transaction.c
index 17e8608..7d7ce25 100644
--- a/libgnucash/engine/Transaction.c
+++ b/libgnucash/engine/Transaction.c
@@ -281,6 +281,8 @@ gnc_transaction_init(Transaction* trans)
     trans->date_posted  = 0;
     trans->marker = 0;
     trans->orig = NULL;
+    trans->readonly_reason = NULL;
+    trans->reason_cache_valid = FALSE;
     LEAVE (" ");
 }
 
@@ -811,12 +813,16 @@ xaccFreeTransaction (Transaction *trans)
     /* free up transaction strings */
     CACHE_REMOVE(trans->num);
     CACHE_REMOVE(trans->description);
+    if (trans->readonly_reason)
+        g_free (trans->readonly_reason);
 
     /* Just in case someone looks up freed memory ... */
     trans->num         = (char *) 1;
     trans->description = NULL;
     trans->date_entered = 0;
     trans->date_posted = 0;
+    trans->readonly_reason = NULL;
+    trans->reason_cache_valid = FALSE;
     if (trans->orig)
     {
         xaccFreeTransaction (trans->orig);
@@ -2069,6 +2075,11 @@ void xaccTransClearReadOnly (Transaction *trans)
         qof_instance_set_kvp (QOF_INSTANCE (trans), NULL, 1, TRANS_READ_ONLY_REASON);
         qof_instance_set_dirty(QOF_INSTANCE(trans));
         xaccTransCommitEdit(trans);
+
+        if (trans->readonly_reason)
+            g_free (trans->readonly_reason);
+        trans->readonly_reason = NULL;
+        trans->reason_cache_valid = TRUE;
     }
 }
 
@@ -2084,6 +2095,11 @@ xaccTransSetReadOnly (Transaction *trans, const char *reason)
         qof_instance_set_kvp (QOF_INSTANCE (trans), &v, 1, TRANS_READ_ONLY_REASON);
         qof_instance_set_dirty(QOF_INSTANCE(trans));
         xaccTransCommitEdit(trans);
+
+        if (trans->readonly_reason)
+            g_free (trans->readonly_reason);
+        trans->readonly_reason = g_strdup (reason);
+        trans->reason_cache_valid = TRUE;
     }
 }
 
@@ -2440,21 +2456,28 @@ xaccTransGetTxnType (const Transaction *trans)
 }
 
 const char *
-xaccTransGetReadOnly (const Transaction *trans)
+xaccTransGetReadOnly (Transaction *trans)
 {
-    /* XXX This flag should be cached in the transaction structure
-     * for performance reasons, since its checked every trans commit.
-     */
-    GValue v = G_VALUE_INIT;
-    const char *s = NULL;
-    if (trans == NULL) return NULL;
-    qof_instance_get_kvp (QOF_INSTANCE(trans), &v, 1, TRANS_READ_ONLY_REASON);
-    if (G_VALUE_HOLDS_STRING (&v))
-         s = g_value_get_string (&v);
-    if (s && strlen (s))
-        return s;
+    if (!trans)
+        return NULL;
 
-    return NULL;
+    if (!trans->reason_cache_valid)
+    {
+        GValue v = G_VALUE_INIT;
+        qof_instance_get_kvp (QOF_INSTANCE(trans), &v, 1, TRANS_READ_ONLY_REASON);
+
+        /* Clear possible old cache value first */
+        if (trans->readonly_reason)
+            g_free (trans->readonly_reason);
+        trans->readonly_reason = NULL;
+
+        /* Then set the new one */
+        if (G_VALUE_HOLDS_STRING (&v))
+            trans->readonly_reason = g_value_dup_string (&v);
+        g_value_unset (&v);
+        trans->reason_cache_valid = TRUE;
+    }
+    return trans->readonly_reason;
 }
 
 static gboolean
diff --git a/libgnucash/engine/Transaction.h b/libgnucash/engine/Transaction.h
index 15aa660..18efbf3 100644
--- a/libgnucash/engine/Transaction.h
+++ b/libgnucash/engine/Transaction.h
@@ -423,7 +423,7 @@ void	      xaccTransClearReadOnly (Transaction *trans);
 
 /** Returns a non-NULL value if this Transaction was marked as read-only with
  * some specific "reason" text. */
-const char *  xaccTransGetReadOnly (const Transaction *trans);
+const char *  xaccTransGetReadOnly (Transaction *trans);
 
 /** Returns TRUE if this Transaction is read-only because its posted-date is
  * older than the "auto-readonly" threshold of this book. See
diff --git a/libgnucash/engine/TransactionP.h b/libgnucash/engine/TransactionP.h
index 7b5bc93..3679fb4 100644
--- a/libgnucash/engine/TransactionP.h
+++ b/libgnucash/engine/TransactionP.h
@@ -110,6 +110,15 @@ struct transaction_s
      * any changes made if/when the edit is abandoned.
      */
     Transaction *orig;
+
+    /* The readonly_reason is a string that indicates why a transaction
+     * is marked as read-only. If NULL, the transaction is read-write.
+     * This value is stored in kvp, but we cache a copy here for
+     * performance reasons. reason_cache_valid indicates whether the
+     * cached value is valid.
+     */
+    char * readonly_reason;
+    gboolean reason_cache_valid;
 };
 
 struct _TransactionClass

commit 3634e8f59d576ce2c3b97fc6a817ada506d47989
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Sun Sep 9 17:43:05 2018 +0200

    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.

diff --git a/gnucash/gnome-utils/gnc-tree-util-split-reg.c b/gnucash/gnome-utils/gnc-tree-util-split-reg.c
index d7d3836..7f01c28 100644
--- a/gnucash/gnome-utils/gnc-tree-util-split-reg.c
+++ b/gnucash/gnome-utils/gnc-tree-util-split-reg.c
@@ -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;
diff --git a/gnucash/gnome/dialog-payment.c b/gnucash/gnome/dialog-payment.c
index ef3a9ea..47f4da3 100644
--- a/gnucash/gnome/dialog-payment.c
+++ b/gnucash/gnome/dialog-payment.c
@@ -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);
diff --git a/gnucash/gnome/dialog-sx-editor.c b/gnucash/gnome/dialog-sx-editor.c
index 4bb2790..c4c667e 100644
--- a/gnucash/gnome/dialog-sx-editor.c
+++ b/gnucash/gnome/dialog-sx-editor.c
@@ -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);
diff --git a/gnucash/gnome/dialog-sx-editor2.c b/gnucash/gnome/dialog-sx-editor2.c
index 7ee3b2c..208773d 100644
--- a/gnucash/gnome/dialog-sx-editor2.c
+++ b/gnucash/gnome/dialog-sx-editor2.c
@@ -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)
                 {
diff --git a/gnucash/gnome/gnc-plugin-page-register2.c b/gnucash/gnome/gnc-plugin-page-register2.c
index 464d856..63cce2d 100644
--- a/gnucash/gnome/gnc-plugin-page-register2.c
+++ b/gnucash/gnome/gnc-plugin-page-register2.c
@@ -3683,6 +3683,7 @@ gnc_plugin_page_register2_cmd_schedule (GtkAction *action,
 		((guid_equal (xaccSchedXactionGetGUID (sx), fromSXId))
 		 ? sx : NULL);
 	}
+	guid_free (fromSXId);
 
 	if (theSX)
 	{
diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c
index a867fb2..8887191 100644
--- a/gnucash/gnome/gnc-split-reg.c
+++ b/gnucash/gnome/gnc-split-reg.c
@@ -1477,6 +1477,7 @@ gsr_default_schedule_handler( GNCSplitReg *gsr, gpointer data )
         ((guid_equal (xaccSchedXactionGetGUID (sx), fromSXId))
          ? sx : NULL);
     }
+    guid_free (fromSXId);
 
     if ( theSX )
     {
diff --git a/gnucash/import-export/ofx/gnc-ofx-import.c b/gnucash/import-export/ofx/gnc-ofx-import.c
index aea382f..101c030 100644
--- a/gnucash/import-export/ofx/gnc-ofx-import.c
+++ b/gnucash/import-export/ofx/gnc-ofx-import.c
@@ -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
diff --git a/libgnucash/app-utils/gnc-sx-instance-model.c b/libgnucash/app-utils/gnc-sx-instance-model.c
index cb8160c..79d7678 100644
--- a/libgnucash/app-utils/gnc-sx-instance-model.c
+++ b/libgnucash/app-utils/gnc-sx-instance-model.c
@@ -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
diff --git a/libgnucash/app-utils/gnc-ui-util.c b/libgnucash/app-utils/gnc-ui-util.c
index 7b9b8cb..8936fa4 100644
--- a/libgnucash/app-utils/gnc-ui-util.c
+++ b/libgnucash/app-utils/gnc-ui-util.c
@@ -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) &&
diff --git a/libgnucash/engine/SX-book.c b/libgnucash/engine/SX-book.c
index 612e97b..b546599 100644
--- a/libgnucash/engine/SX-book.c
+++ b/libgnucash/engine/SX-book.c
@@ -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;
diff --git a/libgnucash/engine/cap-gains.c b/libgnucash/engine/cap-gains.c
index f32f154..32122c0 100644
--- a/libgnucash/engine/cap-gains.c
+++ b/libgnucash/engine/cap-gains.c
@@ -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;
 }
 
diff --git a/libgnucash/engine/gnc-budget.c b/libgnucash/engine/gnc-budget.c
index a82f299..9619dbc 100644
--- a/libgnucash/engine/gnc-budget.c
+++ b/libgnucash/engine/gnc-budget.c
@@ -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;
 }
 
diff --git a/libgnucash/engine/gncInvoice.c b/libgnucash/engine/gncInvoice.c
index 670242c..3d5aae1 100644
--- a/libgnucash/engine/gncInvoice.c
+++ b/libgnucash/engine/gncInvoice.c
@@ -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)
diff --git a/libgnucash/engine/gncOwner.c b/libgnucash/engine/gncOwner.c
index a409b79..23578bf 100644
--- a/libgnucash/engine/gncOwner.c
+++ b/libgnucash/engine/gncOwner.c
@@ -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);
 }
 
diff --git a/libgnucash/engine/qofbook.cpp b/libgnucash/engine/qofbook.cpp
index 15f3a7f..c1fb7b0 100644
--- a/libgnucash/engine/qofbook.cpp
+++ b/libgnucash/engine/qofbook.cpp
@@ -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;
diff --git a/libgnucash/engine/qofbook.h b/libgnucash/engine/qofbook.h
index f2b4ae4..272ec93 100644
--- a/libgnucash/engine/qofbook.h
+++ b/libgnucash/engine/qofbook.h
@@ -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. */
diff --git a/libgnucash/engine/test/test-engine-kvp-properties.c b/libgnucash/engine/test/test-engine-kvp-properties.c
index baddd35..7a11dfd 100644
--- a/libgnucash/engine/test/test-engine-kvp-properties.c
+++ b/libgnucash/engine/test/test-engine-kvp-properties.c
@@ -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

commit 3845611f30848d6aca9b4764e24c050e801e0803
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Sun Sep 9 12:35:56 2018 +0200

    Plug memory leak in register code
    
    The table storing cell dimensions was never freed. The size of this table is
    directly proportional to the number of cells in the register. So the more
    transactions/splits in a register, the more memory was leaked - each time
    a register was opened and closed. With my huge test book I saw leaks of
    4Mb-10Mb per page that was opened/closed.

diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c
index d42e518..a867fb2 100644
--- a/gnucash/gnome/gnc-split-reg.c
+++ b/gnucash/gnome/gnc-split-reg.c
@@ -159,7 +159,6 @@ void gnc_split_reg_sort_action_cb (GtkWidget *w, gpointer data);
 void gnc_split_reg_sort_notes_cb (GtkWidget *w, gpointer data);
 
 
-void gnc_split_reg_destroy_cb(GtkWidget *widget, gpointer data);
 void gnc_split_reg_size_allocate( GtkWidget *widget,
                                   GtkAllocation *allocation,
                                   gpointer user_data );
@@ -168,6 +167,7 @@ void gnc_split_reg_size_allocate( GtkWidget *widget,
 static void gnc_split_reg_class_init( GNCSplitRegClass *klass );
 static void gnc_split_reg_init( GNCSplitReg *gsr );
 static void gnc_split_reg_init2( GNCSplitReg *gsr );
+void gnc_split_reg_dispose(GObject *obj);
 
 FROM_STRING_FUNC(SortType, ENUM_LIST_SORTTYPE)
 AS_STRING_FUNC(SortType, ENUM_LIST_SORTTYPE)
@@ -314,6 +314,8 @@ gnc_split_reg_class_init( GNCSplitRegClass *klass )
     klass->help_changed_cb = NULL;
     klass->show_popup_menu_cb = NULL;
     klass->include_date_cb = NULL;
+
+    object_class->dispose = gnc_split_reg_dispose;
 }
 
 GtkWidget*
@@ -354,9 +356,6 @@ gnc_split_reg_init( GNCSplitReg *gsr )
     gsr->height = -1;
     gsr->numRows = 10;
     gsr->read_only = FALSE;
-
-    g_signal_connect( gsr, "destroy",
-                      G_CALLBACK (gnc_split_reg_destroy_cb), gsr );
 }
 
 static void
@@ -444,12 +443,18 @@ gsr_setup_status_widgets( GNCSplitReg *gsr )
 }
 
 void
-gnc_split_reg_destroy_cb(GtkWidget *widget, gpointer data)
+gnc_split_reg_dispose(GObject *obj)
 {
-    GNCSplitReg *gsr = data;
+    GNCSplitReg *gsr = GNC_SPLIT_REG(obj);
 
     if (gsr->filter_text)
         g_free (gsr->filter_text);
+    gsr->filter_text = NULL;
+
+    if (gsr->reg)
+        g_signal_handlers_disconnect_by_data (gsr->reg, gsr);
+        gtk_widget_destroy (GTK_WIDGET (gsr->reg));
+    gsr->reg = NULL;
 }
 
 /**
@@ -710,7 +715,9 @@ gnc_split_reg_ld_destroy( GNCLedgerDisplay *ledger )
     }
     g_free (state_section);
     g_free (acct_fullname);
+
     gnc_ledger_display_set_user_data (ledger, NULL);
+    g_object_unref (gsr);
 }
 
 void
diff --git a/gnucash/register/register-gnome/gnucash-sheet.c b/gnucash/register/register-gnome/gnucash-sheet.c
index ab916c2..e94a9bc 100644
--- a/gnucash/register/register-gnome/gnucash-sheet.c
+++ b/gnucash/register/register-gnome/gnucash-sheet.c
@@ -763,6 +763,7 @@ gnucash_sheet_finalize (GObject *object)
 
     sheet = GNUCASH_SHEET (object);
 
+    g_table_resize (sheet->blocks, 0, 0);
     g_table_destroy (sheet->blocks);
     sheet->blocks = NULL;
 
@@ -2214,7 +2215,7 @@ gnucash_sheet_block_set_from_table (GnucashSheet *sheet,
 
     if (block->style && (block->style != style))
     {
-        gnucash_style_unref (block->style);
+        gnucash_sheet_style_unref (sheet, block->style);
         block->style = NULL;
     }
 
@@ -2223,7 +2224,7 @@ gnucash_sheet_block_set_from_table (GnucashSheet *sheet,
     if (block->style == NULL)
     {
         block->style = style;
-        gnucash_style_ref(block->style);
+        gnucash_sheet_style_ref(sheet, block->style);
         return TRUE;
     }
 
@@ -2323,14 +2324,15 @@ static void
 gnucash_sheet_block_destroy (gpointer _block, gpointer user_data)
 {
     SheetBlock *block = _block;
+    GnucashSheet *sheet = GNUCASH_SHEET(user_data);
 
     if (block == NULL)
         return;
 
     if (block->style)
     {
-        gnucash_style_unref (block->style);
-        block->style = NULL;
+        gnucash_sheet_style_unref (sheet, block->style);
+        /* Don't free the block itself here. It's managed by the block table */
     }
 }
 
@@ -2588,7 +2590,7 @@ gnucash_sheet_init (GnucashSheet *sheet)
 
     sheet->blocks = g_table_new (sizeof (SheetBlock),
                                  gnucash_sheet_block_construct,
-                                 gnucash_sheet_block_destroy, NULL);
+                                 gnucash_sheet_block_destroy, sheet);
 
     gtk_widget_add_events(GTK_WIDGET(sheet), (GDK_EXPOSURE_MASK
     | GDK_BUTTON_PRESS_MASK
@@ -2723,7 +2725,7 @@ gnucash_sheet_new (Table *table)
     /* some register data */
     sheet->dimensions_hash_table = g_hash_table_new_full (g_int_hash,
                                    g_int_equal,
-                                   g_free, NULL);
+                                   g_free, g_free);
 
     /* add tooltips to sheet */
     gtk_widget_set_has_tooltip (GTK_WIDGET(sheet), TRUE);
diff --git a/gnucash/register/register-gnome/gnucash-style.c b/gnucash/register/register-gnome/gnucash-style.c
index f62d2ee..cecbda0 100644
--- a/gnucash/register/register-gnome/gnucash-style.c
+++ b/gnucash/register/register-gnome/gnucash-style.c
@@ -99,10 +99,15 @@ style_dimensions_destroy (BlockDimensions *dimensions)
     if (dimensions == NULL)
         return;
 
-    g_table_destroy (dimensions->cell_dimensions);
-    dimensions->cell_dimensions = NULL;
+    dimensions->refcount--;
 
-    g_free(dimensions);
+    if (dimensions->refcount == 0)
+    {
+        g_table_destroy (dimensions->cell_dimensions);
+        dimensions->cell_dimensions = NULL;
+
+        g_free(dimensions);
+    }
 }
 
 
@@ -644,7 +649,7 @@ destroy_style_helper (gpointer key, gpointer value, gpointer user_data)
     SheetBlockStyle *style = value;
     GnucashSheet *sheet = user_data;
 
-    gnucash_sheet_style_destroy (sheet, style);
+    gnucash_sheet_style_unref (sheet, style);
     g_free (cursor_name);
 }
 
@@ -674,10 +679,12 @@ gnucash_sheet_create_styles (GnucashSheet *sheet)
     for (node = cursors; node; node = node->next)
     {
         CellBlock *cursor = node->data;
+        SheetBlockStyle *style = gnucash_sheet_style_new (sheet, cursor);
 
+        gnucash_sheet_style_ref (sheet, style);
         g_hash_table_insert (sheet->cursor_styles,
                              g_strdup (cursor->cursor_name),
-                             gnucash_sheet_style_new (sheet, cursor));
+                             style);
     }
 }
 
@@ -798,7 +805,7 @@ gnucash_sheet_get_style_from_cursor (GnucashSheet *sheet,
  */
 
 void
-gnucash_style_ref (SheetBlockStyle *style)
+gnucash_sheet_style_ref (GnucashSheet *sheet, SheetBlockStyle *style)
 {
     g_return_if_fail (style != NULL);
 
@@ -807,14 +814,14 @@ gnucash_style_ref (SheetBlockStyle *style)
 
 
 void
-gnucash_style_unref (SheetBlockStyle *style)
+gnucash_sheet_style_unref (GnucashSheet *sheet, SheetBlockStyle *style)
 {
     g_return_if_fail (style != NULL);
 
     style->refcount--;
 
-    if (style->refcount < 0)
-        g_warning ("Unbalanced Style ref/unref");
+    if (style->refcount == 0)
+        gnucash_sheet_style_destroy (sheet, style);
 }
 
 typedef struct
diff --git a/gnucash/register/register-gnome/gnucash-style.h b/gnucash/register/register-gnome/gnucash-style.h
index 8b143c2..22de583 100644
--- a/gnucash/register/register-gnome/gnucash-style.h
+++ b/gnucash/register/register-gnome/gnucash-style.h
@@ -109,8 +109,8 @@ void gnucash_sheet_style_get_cell_pixel_rel_coords (SheetBlockStyle *style,
         gint *x, gint *y,
         gint *w, gint *h);
 
-void gnucash_style_ref   (SheetBlockStyle *style);
-void gnucash_style_unref (SheetBlockStyle *style);
+void gnucash_sheet_style_ref   (GnucashSheet *sheet, SheetBlockStyle *style);
+void gnucash_sheet_style_unref (GnucashSheet *sheet, SheetBlockStyle *style);
 
 void gnucash_sheet_get_borders (GnucashSheet *sheet, VirtualLocation virt_loc,
                                 PhysicalCellBorders *borders);

commit 4cc61463abd60848e14543ec22adb8364b5a6cda
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Sun Sep 9 12:32:04 2018 +0200

    Remove unused variable

diff --git a/libgnucash/core-utils/gnc-environment.c b/libgnucash/core-utils/gnc-environment.c
index 69be489..8d0e102 100644
--- a/libgnucash/core-utils/gnc-environment.c
+++ b/libgnucash/core-utils/gnc-environment.c
@@ -100,13 +100,12 @@ static void
 gnc_environment_parse_one (const gchar *env_path)
 {
     GKeyFile    *keyfile = g_key_file_new();
-    GError      *error = NULL;
     gchar **env_vars;
     gsize param_count;
     gint i;
     gboolean got_keyfile;
 
-    got_keyfile = g_key_file_load_from_file (keyfile, env_path, G_KEY_FILE_NONE, &error);
+    got_keyfile = g_key_file_load_from_file (keyfile, env_path, G_KEY_FILE_NONE, NULL);
     if ( !got_keyfile )
     {
         g_key_file_free(keyfile);
@@ -114,7 +113,7 @@ gnc_environment_parse_one (const gchar *env_path)
     }
 
     /* Read the environment overrides and apply them */
-    env_vars = g_key_file_get_keys(keyfile, "Variables", &param_count, &error);
+    env_vars = g_key_file_get_keys(keyfile, "Variables", &param_count, NULL);
     for ( i = 0; i < param_count; i++ )
     {
         gchar **val_list;
@@ -125,7 +124,7 @@ gnc_environment_parse_one (const gchar *env_path)
         /* For each variable, read its new value, optionally expand it and set/unset it */
         val_list = g_key_file_get_string_list (keyfile, "Variables",
                                                env_vars[i], &val_count,
-                                               &error );
+                                               NULL);
         if ( val_count == 0 )
             g_unsetenv (env_vars[i]);
         else



Summary of changes:
 gnucash/gnome-utils/gnc-tree-util-split-reg.c      |  1 +
 gnucash/gnome/dialog-payment.c                     |  1 +
 gnucash/gnome/dialog-sx-editor.c                   |  1 +
 gnucash/gnome/dialog-sx-editor2.c                  |  1 +
 gnucash/gnome/gnc-plugin-page-register2.c          |  1 +
 gnucash/gnome/gnc-split-reg.c                      | 22 ++++++----
 gnucash/import-export/ofx/gnc-ofx-import.c         | 13 +++---
 .../register/ledger-core/split-register-model.c    |  2 +-
 gnucash/register/register-gnome/gnucash-sheet.c    | 14 ++++---
 gnucash/register/register-gnome/gnucash-style.c    | 25 +++++++----
 gnucash/register/register-gnome/gnucash-style.h    |  4 +-
 libgnucash/app-utils/gnc-sx-instance-model.c       |  7 +++-
 libgnucash/app-utils/gnc-ui-util.c                 |  7 +++-
 libgnucash/core-utils/gnc-environment.c            |  7 ++--
 libgnucash/engine/SX-book.c                        |  4 +-
 libgnucash/engine/Transaction.c                    | 49 ++++++++++++++++------
 libgnucash/engine/Transaction.h                    |  2 +-
 libgnucash/engine/TransactionP.h                   |  9 ++++
 libgnucash/engine/cap-gains.c                      |  2 +
 libgnucash/engine/gnc-budget.c                     |  5 ++-
 libgnucash/engine/gncInvoice.c                     | 10 ++++-
 libgnucash/engine/gncOwner.c                       |  2 +
 libgnucash/engine/qofbook.cpp                      |  2 +-
 libgnucash/engine/qofbook.h                        |  2 +-
 .../engine/test/test-engine-kvp-properties.c       |  3 ++
 25 files changed, 136 insertions(+), 60 deletions(-)



More information about the gnucash-changes mailing list