[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] [virt-viewer 1/2] Fix memory leak on remote-viewer exit



When exiting remote-viewer, VirtViewepApp::dispose() calls
virt_viewer_app_set_connect_info() with NULL parameters to free all
internal fields. However, _set_connect_info() calls
virt_viewer_app_update_pretty_address() which will always allocate
a new string even if the fields it's using to fill the string are NULL.
This commit fixes the leak by checking if the fields have non-NULL
values before creating the newly-allocated string.

==24180== 14 bytes in 1 blocks are definitely lost in loss record 540 of 8,671
==24180==    at 0x4A0887C: malloc (vg_replace_malloc.c:270)
==24180==    by 0x32D2B0A187: __vasprintf_chk (vasprintf_chk.c:80)
==24180==    by 0x32D52845AA: g_vasprintf (stdio2.h:210)
==24180==    by 0x32D52640DC: g_strdup_vprintf (gstrfuncs.c:517)
==24180==    by 0x32D526417B: g_strdup_printf (gstrfuncs.c:543)
==24180==    by 0x4136E6: virt_viewer_app_update_pretty_address (virt-viewer-app.c:1681)
==24180==    by 0x414100: virt_viewer_app_set_connect_info (virt-viewer-app.c:1902)
==24180==    by 0x4141D0: virt_viewer_app_free_connect_info (virt-viewer-app.c:1910)
==24180==    by 0x4127C6: virt_viewer_app_dispose (virt-viewer-app.c:1353)
==24180==    by 0x425488: remote_viewer_dispose (remote-viewer.c:131)
==24180==    by 0x32D5E14787: g_object_unref (gobject.c:2986)
==24180==    by 0x4280AF: main (remote-viewer-main.c:323)
---
 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 3fd7613..fac87f6 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -1673,11 +1673,12 @@ virt_viewer_app_update_pretty_address(VirtViewerApp *self)
 
     priv = self->priv;
     g_free(priv->pretty_address);
+    priv->pretty_address = NULL;
     if (priv->guri)
         priv->pretty_address = g_strdup(priv->guri);
     else if (priv->gport)
         priv->pretty_address = g_strdup_printf("%s:%s", priv->ghost, priv->gport);
-    else
+    else if (priv->host && priv->unixsock)
         priv->pretty_address = g_strdup_printf("%s:%s", priv->host, priv->unixsock);
 }
 
-- 
1.8.1.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]