[scaffold] don't crash on exit

aurelien naldi <[email protected]>
Newsgroups gmane.comp.gnome.devtools
Message-ID <1072006923.1373.7.camel@localhost>
hello,

the attached patch prevents scaffold from crashing on exit and remove an
unused variable.

a xmlDoc was freed too early and its memory reused.

happy hollidays to all :)
-- 
aurelien
scaffold_exit_crash.patch (text/x-patch, 1.5 KB)
Index: scaffold-session.c
===================================================================
RCS file: /cvs/gnome/scaffold/libscaffold/scaffold-session.c,v
retrieving revision 1.3
diff -u -r1.3 scaffold-session.c
--- scaffold-session.c	8 Aug 2003 20:44:19 -0000	1.3
+++ scaffold-session.c	21 Dec 2003 11:35:56 -0000
@@ -39,6 +39,7 @@
 	char *name;
 	GHashTable *properties;
 	GHashTable *groups;
+	xmlDocPtr doc;
 };
 
 static void dispose (GObject *object);
@@ -103,6 +104,7 @@
 			g_free (session->priv->name);
 		g_hash_table_destroy (session->priv->properties);
 		g_hash_table_destroy (session->priv->groups);
+		xmlFreeDoc(session->priv->doc);
 		g_free (session->priv);
 		session->priv = NULL;
 	}
@@ -236,7 +238,8 @@
 			parse_node (session, node);
 	}
 
-	xmlFreeDoc (doc);
+	/* doc shouldn't be freed here but only after the last node is freed */
+	session->priv->doc = doc;
 }
 
 static void
@@ -412,8 +415,6 @@
 scaffold_session_set_group (ScaffoldSession *session,
 			    xmlNodePtr       group)
 {
-	xmlChar *name;
-
 	g_return_if_fail (SCAFFOLD_IS_SESSION (session));
 	g_return_if_fail (group != NULL);
 
@@ -423,11 +424,7 @@
 		return;
 	}
 
-	/* Check if such a group already exists and remove it. */
-	if (g_hash_table_lookup (session->priv->groups, group->name)) {
-		g_hash_table_remove (session->priv->groups, group->name); 
-	}
-
+	/* insert the group,  g_hash_table_insert 'll remove it first if it already exists */
 	g_hash_table_insert (session->priv->groups,
 			     g_strdup (group->name), group);
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.