Commit 6f9b058f authored by John Sullivan's avatar John Sullivan
Browse files

Fixed a couple of bookmark-related memory leaks.

parent 7797ae9f
2000-01-03 John Sullivan <sullivan@eazel.com>
Fixed memory leaks in bookmarks stuff
* src/nautilus-bookmarklist.c: (nautilus_bookmarklist_delete_item_at):
Destroy the bookmark when removing it from list.
* src/nautilus-bookmarks-menu.c:
(nautilus_bookmarks_menu_repopulate):
Store an index rather than a bookmark in the menu item, since the
item will be destroyed if the menu is reordered.
(bookmark_activated_cb): Find bookmark from the index stored in item.
2000-01-03 John Sullivan <sullivan@eazel.com>
Started new file for file-related utilities in Nautilus.
......
......@@ -237,8 +237,12 @@ nautilus_bookmarklist_delete_item_at (NautilusBookmarklist *bookmarks,
g_return_if_fail(index < g_list_length(bookmarks->list));
doomed = g_list_nth (bookmarks->list, index);
/* FIXME: free the bookmark here */
bookmarks->list = g_list_remove_link (bookmarks->list, doomed);
g_assert(NAUTILUS_IS_BOOKMARK(doomed->data));
gtk_object_destroy(GTK_OBJECT(doomed->data));
g_list_free(doomed);
nautilus_bookmarklist_contents_changed(bookmarks);
}
......@@ -342,7 +346,7 @@ nautilus_bookmarklist_load_file (NautilusBookmarklist *bookmarks)
{
if (strcmp(node->name, "bookmark") == 0)
{
/* FIXME: should only accept bookmarks with both a name and uri? */
/* Maybe should only accept bookmarks with both a name and uri? */
bookmarks->list = g_list_append(
bookmarks->list,
nautilus_bookmark_new(
......@@ -358,8 +362,7 @@ nautilus_bookmarklist_load_file (NautilusBookmarklist *bookmarks)
/**
* nautilus_bookmarklist_new:
*
* Create a new bookmarklist, initially empty.
* FIXME: needs to read initial contents from disk
* Create a new bookmarklist, with contents read from disk.
*
* Return value: A pointer to the new widget.
**/
......
......@@ -150,20 +150,21 @@ add_bookmark_cb(GtkMenuItem* item, gpointer func_data)
static void
bookmark_activated_cb(GtkMenuItem* item, gpointer func_data)
{
NautilusBookmarksMenu *menu;
NautilusBookmark *bookmark;
NautilusBookmarksMenu *menu;
guint item_index;
g_return_if_fail(NAUTILUS_IS_BOOKMARKS_MENU(gtk_object_get_data(GTK_OBJECT(item), OWNING_MENU)));
g_return_if_fail(NAUTILUS_IS_BOOKMARK (func_data));
menu = NAUTILUS_BOOKMARKS_MENU(gtk_object_get_data(GTK_OBJECT(item), OWNING_MENU));
bookmark = NAUTILUS_BOOKMARK(func_data);
item_index = GPOINTER_TO_UINT(func_data);
/* FIXME: should check whether we know this to be an invalid uri.
* If so, don't try to go there, and put up an alert asking user if
* they want to edit bookmarks (or maybe remove this one).
*/
nautilus_window_goto_uri(menu->window, nautilus_bookmark_get_uri(bookmark));
nautilus_window_goto_uri(menu->window,
nautilus_bookmark_get_uri(
nautilus_bookmarklist_item_at(bookmarks, item_index)));
/* FIXME: bookmark created for this signal is never destroyed. */
}
......@@ -312,7 +313,7 @@ static void
nautilus_bookmarks_menu_repopulate (NautilusBookmarksMenu *menu)
{
guint bookmark_count;
gint index;
guint index;
g_return_if_fail(NAUTILUS_IS_BOOKMARKS_MENU(menu));
......@@ -323,22 +324,25 @@ nautilus_bookmarks_menu_repopulate (NautilusBookmarksMenu *menu)
bookmark_count = nautilus_bookmarklist_length(bookmarks);
for (index = 0; index < bookmark_count; ++index)
{
const NautilusBookmark *bookmark;
GtkWidget *item;
bookmark = nautilus_bookmarklist_item_at(bookmarks, index);
item = gtk_menu_item_new_with_label(
nautilus_bookmark_get_name(bookmark));
/* remember the menu this item is attached to */
nautilus_bookmark_get_name(
nautilus_bookmarklist_item_at(bookmarks, index)));
/* The signal will need to know both the menu that this item is
* attached to (to get at the window), and the bookmark
* that this item represents. The menu is stored as the item
* data. The bookmark is passed as an index. This assumes
* that the signal will not be called on this item if the
* menu is reordered (which is true since the menu is
* repopulated from scratch at that time) */
gtk_object_set_data(GTK_OBJECT(item),
OWNING_MENU,
menu);
gtk_signal_connect(GTK_OBJECT (item), "activate",
GTK_SIGNAL_FUNC (bookmark_activated_cb),
nautilus_bookmark_new(
nautilus_bookmark_get_name(bookmark),
nautilus_bookmark_get_uri(bookmark)));
GUINT_TO_POINTER(index));
nautilus_bookmarks_menu_append(menu, item);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment