[glade3] * plugins/gtk+/glade-gtk.c, plugins/gtk+/glade-column-types.[ch]: Added glade_column_type_new()



commit 703263f792c951a28654382524dcf6b7e7c8fc01
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Mon Dec 20 16:51:41 2010 +0900

    	* plugins/gtk+/glade-gtk.c, plugins/gtk+/glade-column-types.[ch]: Added
    	  glade_column_type_new() to create a GladeColumnType struct properly using
    	  g_slice_new0(). An occurance of allocating the struct with g_new0 was causing
    	  Glade to crash when freeing the block with g_slice_free (bug 637563). Many
    	  big thanks to Benjamin Otte for tracking down the problem.

 ChangeLog                         |    8 ++++++++
 plugins/gtk+/glade-column-types.c |   24 ++++++++++++++++--------
 plugins/gtk+/glade-column-types.h |    2 ++
 plugins/gtk+/glade-gtk.c          |    4 +++-
 4 files changed, 29 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a8e44eb..4b6e888 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-12-20  Tristan Van Berkom <tristanvb openismus com>
+
+	* plugins/gtk+/glade-gtk.c, plugins/gtk+/glade-column-types.[ch]: Added
+	  glade_column_type_new() to create a GladeColumnType struct properly using
+	  g_slice_new0(). An occurance of allocating the struct with g_new0 was causing
+	  Glade to crash when freeing the block with g_slice_free (bug 637563). Many
+	  big thanks to Benjamin Otte for tracking down the problem.
+
 2010-12-19  Tristan Van Berkom <tristanvb openismus com>
 
 	* plugins/gtk+/glade-gtk.c: Fix alpha_sort_box_children() to give a consistent
diff --git a/plugins/gtk+/glade-column-types.c b/plugins/gtk+/glade-column-types.c
index 8b3b72b..91fffe1 100644
--- a/plugins/gtk+/glade-column-types.c
+++ b/plugins/gtk+/glade-column-types.c
@@ -145,18 +145,28 @@ glade_column_list_copy (GList *list)
 	
 	for (l = list; l; l = g_list_next (l))
 	{
-		GladeColumnType *new_data = g_slice_new0 (GladeColumnType);
 		GladeColumnType *data = l->data;
-		
-		new_data->type_name = g_strdup (data->type_name);
-		new_data->column_name = g_strdup (data->column_name);
-		
+		GladeColumnType *new_data = 
+			glade_column_type_new (data->type_name, data->column_name);
+
 		retval = g_list_prepend (retval, new_data);
 	}
 	
 	return g_list_reverse (retval);
 }
 
+GladeColumnType *
+glade_column_type_new (const gchar *type_name,
+		       const gchar *column_name)
+{
+	GladeColumnType *column = g_slice_new0 (GladeColumnType);
+
+	column->type_name   = g_strdup (type_name);
+	column->column_name = g_strdup (column_name);
+
+	return column;
+}
+
 void
 glade_column_type_free (GladeColumnType *column)
 {
@@ -323,9 +333,7 @@ eprop_column_append (GladeEditorProperty *eprop,
 	if (columns)
 		columns = glade_column_list_copy (columns);
 
-	data = g_slice_new0 (GladeColumnType);
-	data->column_name = g_strdup (column_name);
-	data->type_name   = g_strdup (type_name);
+	data = glade_column_type_new (type_name, column_name);
 
 	columns = g_list_append (columns, data);
 
diff --git a/plugins/gtk+/glade-column-types.h b/plugins/gtk+/glade-column-types.h
index f2c3fbc..1f818fe 100644
--- a/plugins/gtk+/glade-column-types.h
+++ b/plugins/gtk+/glade-column-types.h
@@ -41,6 +41,8 @@ GType        glade_eprop_column_types_get_type    (void) G_GNUC_CONST;
 void         glade_column_list_free               (GList *list);
 GList       *glade_column_list_copy               (GList *list);
 
+GladeColumnType *glade_column_type_new            (const gchar *type_name,
+						   const gchar *column_name);
 void             glade_column_type_free           (GladeColumnType *column);
 GladeColumnType *glade_column_list_find_column    (GList *list, const gchar *column_name);
 
diff --git a/plugins/gtk+/glade-gtk.c b/plugins/gtk+/glade-gtk.c
index 54636e0..55625b2 100644
--- a/plugins/gtk+/glade-gtk.c
+++ b/plugins/gtk+/glade-gtk.c
@@ -10516,7 +10516,7 @@ glade_gtk_store_read_columns (GladeWidget *widget, GladeXmlNode *node)
 	for (prop = glade_xml_node_get_children_with_comments (columns_node); prop;
 	     prop = glade_xml_node_next_with_comments (prop))
 	{
-		GladeColumnType *data = g_new0 (GladeColumnType, 1);
+		GladeColumnType *data;
 		gchar *type, *comment_str, buffer[256];
 
 		if (!glade_xml_node_verify_silent (prop, GLADE_TAG_COLUMN) &&
@@ -10533,6 +10533,8 @@ glade_gtk_store_read_columns (GladeWidget *widget, GladeXmlNode *node)
 		}
 
 		type = glade_xml_get_property_string_required (prop, GLADE_TAG_TYPE, NULL);
+
+		data              = glade_column_type_new (type, NULL);
 		data->type_name   = g_strdup (type);
 		data->column_name = column_name[0] ? g_strdup (column_name) : g_ascii_strdown (type, -1);
 



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