Bookmark menu icons show error icons when sidebar is closed

When the sidebar/shortcuts pane is closed, bookmark icons in the Bookmarks menu display as error icons (red X). When the sidebar is open, all icons render correctly.

Version information

Checked the latest source: thunar 4.21.5-dev-320888a6 (Xfce 4.20), Fedora 43 (Xfce spin)

Reproduction

Additional information

I have a working fix; I can create an MR. Note that the code was written by AI (Claude 4.6). Here is his explanation for the bug:

Root cause: Use-after-free in thunar_window_menu_add_bookmarks(). The icon name returned by thunar_file_get_icon_name() is a const char* pointing to the ThunarFile object's internal field. The file is unref'd immediately after, but the icon name is used later when creating the menu item. Since the file cache uses GWeakRef, when no other component holds a strong reference (i.e. sidebar is closed), the unref destroys the object, and the icon name becomes a dangling pointer.

// thunar/thunar-window.c, thunar_window_menu_add_bookmarks()

thunar_file = thunar_file_get (bookmark->g_file, NULL);
// ...
icon_name = thunar_file_get_icon_name (thunar_file, ...);  // points to file->icon_name

if (thunar_file != NULL)
    g_object_unref (thunar_file);  // file destroyed if sidebar not holding a ref
                                   // icon_name is now dangling

// ...
// icon_name used here — reads freed memory
xfce_gtk_image_menu_item_new_from_icon_name (..., icon_name, view_menu);

Fix: Move the g_object_unref() to after the icon name has been consumed by xfce_gtk_image_menu_item_new_from_icon_name().