Fix leak of VirtViewerApp::windows hash table key

The VirtViewerApp::windows hash table owns the memory for both the keys
and values it stores. virt_viewer_app_remove_nth_window() uses
g_hash_table_steal() which does not call the 'free' function neither for
the key nor for the value. This method takes care of releasing the
reference for the value it extracted from the hash table, but not for the
key.
This commit fixes by explicitly taking a reference on the value rather than
stealing the one held by the hash table. We can then replace the use of
g_hash_table_steal() with g_hash_table_remove() which will take care of
freeing the removed key.
This commit is contained in:
Christophe Fergeau 2013-11-20 14:47:00 +01:00
parent 2890749b7d
commit 609b8d4a54

View File

@ -591,7 +591,8 @@ virt_viewer_app_remove_nth_window(VirtViewerApp *self, gint nth)
g_return_val_if_fail(win != NULL, FALSE);
DEBUG_LOG("Remove window %d %p", nth, win);
removed = g_hash_table_steal(self->priv->windows, &nth);
g_object_ref(win);
removed = g_hash_table_remove(self->priv->windows, &nth);
g_warn_if_fail(removed);
virt_viewer_app_update_menu_displays(self);