From 609b8d4a546650bda2881e03a1208aa4ccf618fc Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Wed, 20 Nov 2013 14:47:00 +0100 Subject: [PATCH] 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. --- src/virt-viewer-app.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c index c0d3e42..eddd436 100644 --- a/src/virt-viewer-app.c +++ b/src/virt-viewer-app.c @@ -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);