[gnumeric] Border: improve cleanup.



commit 523657fb7a85740968e55122403422c64c350b4f
Author: Morten Welinder <terra gnome org>
Date:   Sat Mar 15 15:22:43 2014 -0400

    Border: improve cleanup.

 ChangeLog          |    4 +++-
 src/mstyle.c       |    1 -
 src/style-border.c |   39 +++++++++++++++++++++++++--------------
 src/style-color.c  |    8 --------
 4 files changed, 28 insertions(+), 24 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index de8e2fd..e397208 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,9 @@
 2014-03-15  Morten Welinder  <terra gnome org>
 
        * src/style-border.c (gnm_border_shutdown): New function to help
-       debug leaks.
+       debug leaks.  Shutdown border_none here.
+
+       * src/style-color.c (gnm_color_shutdown): Not here.
 
 2014-03-15  Jean Brefort  <jean brefort normalesup org>
 
diff --git a/src/mstyle.c b/src/mstyle.c
index c7b5484..4809609 100644
--- a/src/mstyle.c
+++ b/src/mstyle.c
@@ -1291,7 +1291,6 @@ gnm_style_set_border (GnmStyle *style, GnmStyleElement elem,
                g_warning ("Not a border element");
                break;
        }
-
 }
 
 GnmBorder *
diff --git a/src/style-border.c b/src/style-border.c
index 1a5eb5b..a19ca9f 100644
--- a/src/style-border.c
+++ b/src/style-border.c
@@ -105,6 +105,7 @@ struct {
 };
 
 static GHashTable *border_hash = NULL;
+static GnmBorder *border_none = NULL;
 
 static gint
 style_border_equal (gconstpointer v1, gconstpointer v2)
@@ -138,18 +139,18 @@ style_border_hash (gconstpointer v)
 GnmBorder *
 gnm_style_border_none (void)
 {
-       static GnmBorder * none = NULL;
-       if (none == NULL) {
-               none = g_new0 (GnmBorder, 1);
-               none->line_type = GNM_STYLE_BORDER_NONE;
-               none->color = style_color_grid ();
-               none->begin_margin = none->end_margin = none->width = 0;
-               none->ref_count = 1;
+       if (border_none == NULL) {
+               border_none = g_new0 (GnmBorder, 1);
+               border_none->line_type = GNM_STYLE_BORDER_NONE;
+               border_none->color = style_color_grid ();
+               border_none->begin_margin = border_none->end_margin = border_none->width = 0;
+               border_none->ref_count = 1;
+               /* Note: not in the hash.  */
        }
 
-       g_return_val_if_fail (none != NULL, NULL);
+       g_return_val_if_fail (border_none != NULL, NULL);
 
-       return none;
+       return border_none;
 }
 
 /**
@@ -283,8 +284,10 @@ GnmBorder *
 gnm_style_border_ref (GnmBorder *border)
 {
        /* NULL is ok */
-       if (border != NULL)
+       if (border != NULL) {
                ++border->ref_count;
+               if (0) g_printerr ("style border ref: %p\n", border);
+       }
        return border;
 }
 
@@ -296,15 +299,17 @@ gnm_style_border_unref (GnmBorder *border)
 
        g_return_if_fail (border->ref_count > 0);
 
+       if (0) g_printerr ("style border unref: %p\n", border);
+
        border->ref_count--;
        if (border->ref_count != 0)
                return;
 
-       /* Just to be on the safe side.
-        * We are allowed to deref the border_none,
-        * but not to free it.
+       /*
+        * We are allowed to deref  border_none, but not to free it.
+        * It is not in the hash.
         */
-       g_return_if_fail (border != gnm_style_border_none ());
+       g_return_if_fail (border != border_none);
 
        /* Remove here, before we mess with the hashed fields.  */
        g_hash_table_remove (border_hash, border);
@@ -331,6 +336,12 @@ cb_border_leak (gpointer key, gpointer value, gpointer user_data)
 void
 gnm_border_shutdown (void)
 {
+       if (border_none) {
+               style_color_unref (border_none->color);
+               g_free (border_none);
+               border_none = NULL;
+       }
+
        if (border_hash) {
                g_hash_table_foreach (border_hash, cb_border_leak, NULL);
                g_hash_table_destroy (border_hash);
diff --git a/src/style-color.c b/src/style-color.c
index 0821173..2701bb4 100644
--- a/src/style-color.c
+++ b/src/style-color.c
@@ -242,14 +242,6 @@ cb_color_leak (gpointer key, gpointer value, gpointer user_data)
 void
 gnm_color_shutdown (void)
 {
-       /*
-        * FIXME: this doesn't really belong here, but style-border.c isn't
-        * able to clean itself up yet.
-        */
-       GnmBorder *none = gnm_style_border_none ();
-       style_color_unref (none->color);
-       none->color = NULL;
-
        if (sc_black) {
                style_color_unref (sc_black);
                sc_black = NULL;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]