[virt-tools-list] [PATCHv2 1/2] session: Only create a hashtable if apply_monitor_geometry vfunc exists

Fabiano Fidêncio fidencio at redhat.com
Wed Oct 21 14:08:57 UTC 2015


Creating the monitors hashtable only after checking for the existence of
apply_monitor_geometry vfunc avoids leaking the hashtable in the case
where the vfunc doesn't exist.

Related: rhbz#1267184
---
Changes since v1:
- s/class/vfunc
- add a mention the memory leak fixed by this commit
---
 src/virt-viewer-session.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/virt-viewer-session.c b/src/virt-viewer-session.c
index 2699f41..92ffd3f 100644
--- a/src/virt-viewer-session.c
+++ b/src/virt-viewer-session.c
@@ -405,13 +405,15 @@ virt_viewer_session_on_monitor_geometry_changed(VirtViewerSession* self,
     VirtViewerSessionClass *klass;
     gboolean all_fullscreen = TRUE;
     /* GHashTable<gint, GdkRectangle*> */
-    GHashTable *monitors = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
+    GHashTable *monitors;
     GList *l;
 
     klass = VIRT_VIEWER_SESSION_GET_CLASS(self);
     if (!klass->apply_monitor_geometry)
         return;
 
+    monitors = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
+
     for (l = self->priv->displays; l; l = l->next) {
         VirtViewerDisplay *d = VIRT_VIEWER_DISPLAY(l->data);
         guint nth = 0;
-- 
2.4.3




More information about the virt-tools-list mailing list