[gnome-remote-desktop] clipboard-rdp: Don't leak memory when session ends



commit 982b4db3cc06d86138cb49322d55ebc990671410
Author: Pascal Nowack <Pascal Nowack gmx de>
Date:   Fri Aug 6 08:56:43 2021 +0200

    clipboard-rdp: Don't leak memory when session ends
    
    When the remote desktop session ends, but there is still a list of
    pending mime type tables for the server, then these tables are leaked.
    While it is in reality very unlikely that this situation happens, it is
    theoretically not impossible that this situation happens.
    
    So, save the FormatListUpdateContext, like the FormatDataRequestContext
    on the clipboard_rdp struct to allow freeing the memory, when the
    associated server_format_list_update_id is cleared.

 src/grd-clipboard-rdp.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
---
diff --git a/src/grd-clipboard-rdp.c b/src/grd-clipboard-rdp.c
index 44bea3d..040c632 100644
--- a/src/grd-clipboard-rdp.c
+++ b/src/grd-clipboard-rdp.c
@@ -32,7 +32,6 @@
 
 typedef struct _ServerFormatListUpdateContext
 {
-  GrdClipboardRdp *clipboard_rdp;
   GList *mime_type_tables;
 } ServerFormatListUpdateContext;
 
@@ -83,6 +82,8 @@ struct _GrdClipboardRdp
   gboolean server_file_contents_requests_allowed;
   uint16_t format_list_response_msg_flags;
 
+  ServerFormatListUpdateContext *format_list_update_context;
+
   GHashTable *serial_entry_table;
   GHashTable *clip_data_table;
   struct
@@ -1088,16 +1089,19 @@ cliprdr_temp_directory (CliprdrServerContext         *cliprdr_context,
 static gboolean
 update_server_format_list (gpointer user_data)
 {
-  ServerFormatListUpdateContext *update_context = user_data;
-  GrdClipboardRdp *clipboard_rdp = update_context->clipboard_rdp;
-  GrdClipboard *clipboard = GRD_CLIPBOARD (update_context->clipboard_rdp);
+  GrdClipboardRdp *clipboard_rdp = user_data;
+  GrdClipboard *clipboard = GRD_CLIPBOARD (clipboard_rdp);
   GrdRdpFuseClipboard *rdp_fuse_clipboard = clipboard_rdp->rdp_fuse_clipboard;
   CliprdrServerContext *cliprdr_context = clipboard_rdp->cliprdr_context;
+  ServerFormatListUpdateContext *update_context;
   CLIPRDR_FORMAT_LIST_RESPONSE format_list_response = {0};
-  GList *mime_type_tables = update_context->mime_type_tables;
+  GList *mime_type_tables;
   GrdMimeTypeTable *mime_type_table;
   GList *l;
 
+  update_context = g_steal_pointer (&clipboard_rdp->format_list_update_context);
+  mime_type_tables = update_context->mime_type_tables;
+
   for (l = mime_type_tables; l; l = l->next)
     {
       mime_type_table = l->data;
@@ -1299,11 +1303,13 @@ cliprdr_client_format_list (CliprdrServerContext      *cliprdr_context,
 
   ResetEvent (clipboard_rdp->completed_format_list_event);
   update_context = g_malloc0 (sizeof (ServerFormatListUpdateContext));
-  update_context->clipboard_rdp = clipboard_rdp;
   update_context->mime_type_tables = mime_type_tables;
 
+  g_assert (!clipboard_rdp->format_list_update_context);
+  clipboard_rdp->format_list_update_context = update_context;
+
   clipboard_rdp->server_format_list_update_id =
-    g_idle_add (update_server_format_list, update_context);
+    g_idle_add (update_server_format_list, clipboard_rdp);
   SetEvent (clipboard_rdp->format_list_received_event);
 
   return CHANNEL_RC_OK;
@@ -2038,6 +2044,7 @@ grd_clipboard_rdp_dispose (GObject *object)
     g_clear_pointer (&clipboard_rdp->clipboard_retrieval_context.entry, g_free);
 
   g_clear_pointer (&clipboard_rdp->format_data_request_context, g_free);
+  g_clear_pointer (&clipboard_rdp->format_list_update_context, g_free);
   g_clear_pointer (&clipboard_rdp->queued_server_formats, g_list_free);
   g_clear_pointer (&clipboard_rdp->pending_server_formats, g_list_free);
   g_hash_table_foreach_remove (clipboard_rdp->format_data_cache,


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