From c60cec78bfb5622e0c5b472078f5952606a0cee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Mon, 14 May 2012 15:08:36 +0200 Subject: 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 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/bookmarks') diff --git a/src/bookmarks/ephy-bookmarks-import.c b/src/bookmarks/ephy-bookmarks-import.c index f6ed781cb..5d83f5538 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 -- cgit v1.2.3