[gtkhtml] Memory leaks

Chris Heath <[email protected]>
Newsgroups gmane.comp.gnome.evolution.patches
Message-ID <[email protected]>
Here is a patch for memory leaks I found in gtkhtml.  Please review and
apply.


Index: src/ChangeLog
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/ChangeLog,v
retrieving revision 1.2173
diff -u -p -r1.2173 ChangeLog
--- src/ChangeLog	25 Mar 2006 17:47:41 -0000	1.2173
+++ src/ChangeLog	27 Mar 2006 12:48:36 -0000
@@ -1,3 +1,12 @@
+2006-03-26  Chris Heath  <[email protected]>
+
+	* htmlengine.c (element_parse_object), (element_parse_cell),
+	(set_object_data): Fix memory leaks
+	* htmlcursor.c (html_cursor_beginning_of_paragraph),
+	(html_cursor_end_of_paragraph): ditto
+	* gtkhtml.c (button_press_event): ditto
+	* htmlstyle.c (html_style_free): ditto
+
 2006-03-25  Andreas Köhler  <[email protected]>
 
 	* htmlprinter.c: fix typo to enable printing of embedded objects
Index: src/gtkhtml.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/gtkhtml.c,v
retrieving revision 1.617
diff -u -p -r1.617 gtkhtml.c
--- src/gtkhtml.c	1 Mar 2006 06:04:01 -0000	1.617
+++ src/gtkhtml.c	27 Mar 2006 12:48:38 -0000
@@ -1743,13 +1743,15 @@ button_press_event (GtkWidget *widget,
 				HTMLObject *obj;
 				HTMLEngine *orig_e;
 				gint offset;
+				gchar *url = NULL;
 
 				orig_e = GTK_HTML (orig_widget)->engine;
 				obj = html_engine_get_object_at (engine, x, y, &offset, FALSE);
 				if (obj && ((HTML_IS_IMAGE (obj) && HTML_IMAGE (obj)->url && *HTML_IMAGE (obj)->url)
-					    || (HTML_IS_TEXT (obj) && html_object_get_complete_url (obj, offset))))
+					    || (HTML_IS_TEXT (obj) && (url = html_object_get_complete_url (obj, offset))))) {
+					g_free (url);
 					html_engine_set_focus_object (orig_e, obj, offset);
-				else {
+				} else {
 					html_engine_set_focus_object (orig_e, NULL, 0);
 					if (orig_e->caret_mode || engine->caret_mode)
 						html_engine_jump_at (engine, x, y);
Index: src/htmlcursor.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlcursor.c,v
retrieving revision 1.77
diff -u -p -r1.77 htmlcursor.c
--- src/htmlcursor.c	28 Feb 2006 20:51:54 -0000	1.77
+++ src/htmlcursor.c	27 Mar 2006 12:48:39 -0000
@@ -733,7 +733,7 @@ html_cursor_get_prev_char (const HTMLCur
 gboolean
 html_cursor_beginning_of_paragraph (HTMLCursor *cursor, HTMLEngine *engine)
 {
-	HTMLCursor *copy;
+	HTMLCursor copy;
 	HTMLObject *flow;
 	gboolean rv = FALSE;
 	gint level, new_level;
@@ -748,15 +748,14 @@ html_cursor_beginning_of_paragraph (HTML
 
 	while (1) {
 		if (!cursor->offset) {
-			copy = html_cursor_dup (cursor);
+			html_cursor_copy (&copy, cursor);
 			if (backward (cursor)) {
 				new_level = html_object_get_parent_level (cursor->object);
 				if (new_level < level
 				    || (new_level == level && flow != cursor->object->parent)) {
-					html_cursor_copy (cursor, copy);
+					html_cursor_copy (cursor, &copy);
 					break;
 				}
-				html_cursor_destroy (copy);
 			} else
 				break;
 		}
@@ -772,7 +771,7 @@ html_cursor_beginning_of_paragraph (HTML
 gboolean
 html_cursor_end_of_paragraph (HTMLCursor *cursor, HTMLEngine *engine)
 {
-	HTMLCursor *copy;
+	HTMLCursor copy;
 	HTMLObject *flow;
 	gboolean rv = FALSE;
 	gint level, new_level;
@@ -787,15 +786,14 @@ html_cursor_end_of_paragraph (HTMLCursor
 
 	while (1) {
 		if (cursor->offset == html_object_get_length (cursor->object)) {
-			copy = html_cursor_dup (cursor);
+			html_cursor_copy (&copy, cursor);
 			if (forward (cursor)) {
 				new_level = html_object_get_parent_level (cursor->object);
 				if (new_level < level
 				    || (new_level == level && flow != cursor->object->parent)) {
-					html_cursor_copy (cursor, copy);
+					html_cursor_copy (cursor, &copy);
 					break;
 				}
-				html_cursor_destroy (copy);
 			} else
 				break;
 		}
Index: src/htmlengine.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlengine.c,v
retrieving revision 1.645
diff -u -p -r1.645 htmlengine.c
--- src/htmlengine.c	22 Mar 2006 02:10:35 -0000	1.645
+++ src/htmlengine.c	27 Mar 2006 12:48:41 -0000
@@ -1521,6 +1521,7 @@ element_parse_object (HTMLEngine *e, HTM
 	if (element->style->height)
 		height = element->style->height->val;
 
+	html_element_free (element);
 	eb = (GtkHTMLEmbedded *) gtk_html_embedded_new (classid, name, type, data, 
 							width, height);
 
@@ -3364,8 +3365,10 @@ element_parse_cell (HTMLEngine *e, HTMLO
 
 	html_element_parse_coreattrs (element);
 
-	if (!table)
+	if (!table) {
+		html_element_free (element);
 		return;
+	}
 	
 	cell = HTML_TABLE_CELL (html_table_cell_new (rowSpan, colSpan, table->padding));
 
@@ -6076,7 +6079,7 @@ static void
 set_object_data (gpointer key, gpointer value, gpointer data)
 {
 	/* printf ("set %s\n", (const gchar *) key); */
-	html_object_set_data (HTML_OBJECT (data), g_strdup ((const gchar *) key), g_strdup ((const gchar *) value));
+	html_object_set_data (HTML_OBJECT (data), (const gchar *) key, (const gchar *) value);
 }
 
 static void
Index: src/htmlstyle.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmlstyle.c,v
retrieving revision 1.24
diff -u -p -r1.24 htmlstyle.c
--- src/htmlstyle.c	11 Sep 2005 04:05:25 -0000	1.24
+++ src/htmlstyle.c	27 Mar 2006 12:48:41 -0000
@@ -129,6 +129,9 @@ html_style_free (HTMLStyle *style)
 	if (style->bg_color)
 		html_color_unref (style->bg_color);
 
+	if (style->border_color)
+		html_color_unref (style->border_color);
+
 	g_free (style);
 }
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.