[virt-tools-list] [PATCH virt-viewer] Avoid potential memory leak in spice session

Jonathon Jongsma jjongsma at redhat.com
Mon Dec 3 21:38:30 UTC 2018


If j == -1, the memory allocated for rect will leak. So move the
allocation after the test.

Signed-off-by: Jonathon Jongsma <jjongsma at redhat.com>
---
 src/virt-viewer-session-spice.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/virt-viewer-session-spice.c b/src/virt-viewer-session-spice.c
index cb06af2..8223881 100644
--- a/src/virt-viewer-session-spice.c
+++ b/src/virt-viewer-session-spice.c
@@ -1067,11 +1067,11 @@ virt_viewer_session_spice_fullscreen_auto_conf(VirtViewerSessionSpice *self)
     displays = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
 
     for (l = initial_displays; l != NULL; l = l->next) {
-        GdkRectangle* rect = g_new0(GdkRectangle, 1);;
         gint j = virt_viewer_app_get_initial_monitor_for_display(app, GPOINTER_TO_INT(l->data));
         if (j == -1)
             continue;
 
+        GdkRectangle* rect = g_new0(GdkRectangle, 1);;
         gdk_screen_get_monitor_geometry(screen, j, rect);
         g_hash_table_insert(displays, l->data, rect);
     }
-- 
2.17.2




More information about the virt-tools-list mailing list