[Spice-devel] [PATCH v2 4/9] MainChannel: remove another init_send_data arg

Jonathon Jongsma jjongsma at redhat.com
Thu Dec 15 19:19:19 UTC 2016


Use spice_marshaller_add_by_ref_full() instead of _add_by_ref() to
handle the referenced data properly rather than passing the pipe item to
red_channel_client_init_send_data() to keep the pipe item alive
indirectly.
---
 server/main-channel-client.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/server/main-channel-client.c b/server/main-channel-client.c
index 7e55b24..4a64a40 100644
--- a/server/main-channel-client.c
+++ b/server/main-channel-client.c
@@ -833,12 +833,20 @@ static void main_channel_marshall_tokens(RedChannelClient *rcc,
     spice_marshall_msg_main_agent_token(m, &tokens);
 }
 
+static void marshaller_free_pipe_item(uint8_t *data, void *opaque)
+{
+    RedPipeItem *pipe_item = opaque;
+    red_pipe_item_unref(pipe_item);
+}
+
 static void main_channel_marshall_agent_data(RedChannelClient *rcc,
                                              SpiceMarshaller *m,
                                              RedAgentDataPipeItem *item)
 {
-    red_channel_client_init_send_data(rcc, SPICE_MSG_MAIN_AGENT_DATA, &item->base);
-    spice_marshaller_add_by_ref(m, item->data, item->len);
+    red_channel_client_init_send_data(rcc, SPICE_MSG_MAIN_AGENT_DATA, NULL);
+    /* since pipe item owns the data, keep it alive until it's sent */
+    red_pipe_item_ref(&item->base);
+    spice_marshaller_add_by_ref_full(m, item->data, item->len, marshaller_free_pipe_item, item);
 }
 
 static void main_channel_marshall_migrate_data_item(RedChannelClient *rcc,
@@ -846,7 +854,7 @@ static void main_channel_marshall_migrate_data_item(RedChannelClient *rcc,
                                                     RedPipeItem *item)
 {
     RedChannel *channel = red_channel_client_get_channel(rcc);
-    red_channel_client_init_send_data(rcc, SPICE_MSG_MIGRATE_DATA, item);
+    red_channel_client_init_send_data(rcc, SPICE_MSG_MIGRATE_DATA, NULL);
     // TODO: from reds split. ugly separation.
     reds_marshall_migrate_data(red_channel_get_server(channel), m);
 }
-- 
2.7.4



More information about the Spice-devel mailing list