[epiphany] Always close bookmarks file



commit c60cec78bfb5622e0c5b472078f5952606a0cee4
Author: LubomÃr SedlÃÅ <lubomir sedlar gmail com>
Date:   Mon May 14 15:08:36 2012 +0200

    Always close bookmarks file
    
    During error handling it was possible to return from function without
    closing bookmarks file and freeing two string, causing memory and
    descriptor leaks.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=675888

 src/bookmarks/ephy-bookmarks-import.c |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)
---
diff --git a/src/bookmarks/ephy-bookmarks-import.c b/src/bookmarks/ephy-bookmarks-import.c
index f6ed781..5d83f55 100644
--- a/src/bookmarks/ephy-bookmarks-import.c
+++ b/src/bookmarks/ephy-bookmarks-import.c
@@ -712,20 +712,20 @@ ephy_bookmarks_import_mozilla (EphyBookmarks *bookmarks,
 	GString *name, *url;
 	char *parsedname;
 	GList *folders = NULL;
+	gboolean retval = TRUE;
 
 	if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
 				    EPHY_PREFS_LOCKDOWN_BOOKMARK_EDITING))
 		return FALSE;
 
-	name = g_string_new (NULL);
-	url = g_string_new (NULL);
-
-
 	if (!(bf = fopen (filename, "r"))) {
 		g_warning ("Failed to open file: %s\n", filename);
 		return FALSE;
 	}
 
+	name = g_string_new (NULL);
+	url = g_string_new (NULL);
+
 	while (!feof (bf)) {
 		EphyNode *node;
 		NSItemType t;
@@ -753,10 +753,13 @@ ephy_bookmarks_import_mozilla (EphyBookmarks *bookmarks,
 			if (node == NULL)
 			{
 				node = ephy_bookmarks_find_bookmark (bookmarks, url->str);
+				if (node == NULL) {
+					g_warning ("%s: `node' is NULL", G_STRFUNC);
+					retval = FALSE;
+					goto out;
+				}
 			}
 
-			g_return_val_if_fail (node != NULL, FALSE);
-
 			if (folders != NULL)
 			{
 				EphyNode *keyword;
@@ -781,11 +784,12 @@ ephy_bookmarks_import_mozilla (EphyBookmarks *bookmarks,
 			break;
 		}
 	}
+out:
 	fclose (bf);
 	g_string_free (name, TRUE);
 	g_string_free (url, TRUE);
 
-	return TRUE;
+	return retval;
 }
 
 gboolean



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