[Spice-devel] [PATCH GTK] cursor: don't leak uncached cursors

Christophe Fergeau cfergeau at redhat.com
Mon Jul 4 08:18:59 PDT 2011


When the cursor channel creates a new cursor, if the message
indicates not to cache it, the cursor is leaked after being used.
This commit fixes that, though I'm not really satisfied with it.

==22568== 378,432 bytes in 162 blocks are definitely lost in loss record 7,699 of 7,699
==22568==    at 0x4A0649D: malloc (vg_replace_malloc.c:236)
==22568==    by 0x4E624CF: spice_malloc (mem.c:88)
==22568==    by 0x4E4F1C4: set_cursor (channel-cursor.c:323)
==22568==    by 0x4E4FA29: cursor_handle_set (channel-cursor.c:469)
==22568==    by 0x4E4FD19: spice_cursor_handle_msg (channel-cursor.c:548)
==22568==    by 0x4E30292: spice_channel_recv_msg (spice-channel.c:1641)
==22568==    by 0x4E3062A: spice_channel_iterate_read (spice-channel.c:1776)
==22568==    by 0x4E307F9: spice_channel_iterate (spice-channel.c:1820)
==22568==    by 0x4E30EE4: spice_channel_coroutine (spice-channel.c:1968)
==22568==    by 0x4EE48A2: coroutine_thread (coroutine_gthread.c:77)
==22568==    by 0x302E4683A5: g_thread_create_proxy (gthread.c:1955)
==22568==    by 0x302C807AF0: start_thread (pthread_create.c:305)

---
 gtk/channel-cursor.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/gtk/channel-cursor.c b/gtk/channel-cursor.c
index b39027f..e50ecb2 100644
--- a/gtk/channel-cursor.c
+++ b/gtk/channel-cursor.c
@@ -46,6 +46,7 @@ typedef struct display_cursor display_cursor;
 struct display_cursor {
     SpiceCursorHeader           hdr;
     gboolean                    default_cursor;
+    gboolean                    cached;
     guint32                     data[];
 };
 
@@ -323,6 +324,7 @@ static display_cursor *set_cursor(SpiceChannel *channel, SpiceCursor *scursor)
     cursor = spice_malloc(sizeof(*cursor) + size);
     cursor->hdr = *hdr;
     cursor->default_cursor = FALSE;
+    cursor->cached = FALSE;
     data = scursor->data;
 
     switch (hdr->type) {
@@ -388,6 +390,7 @@ cache_add:
     if (cursor && (scursor->flags & SPICE_CURSOR_FLAGS_CACHE_ME)) {
         item = cache_add(&c->cursors, hdr->unique);
         item->ptr = cursor;
+        cursor->cached = TRUE;
     }
 
     return cursor;
@@ -423,6 +426,9 @@ static void emit_cursor_set(SpiceChannel *channel, display_cursor *cursor)
                       cursor->hdr.width, cursor->hdr.height,
                       cursor->hdr.hot_spot_x, cursor->hdr.hot_spot_y,
                       cursor->default_cursor ? NULL : cursor->data);
+    if (!cursor->cached) {
+        g_free(cursor);
+    }
 }
 
 /* coroutine context */
-- 
1.7.5.4



More information about the Spice-devel mailing list