[Spice-devel] [PATCH v4 2/7] MainChannel: remove another init_send_data arg

Jonathon Jongsma jjongsma at redhat.com
Tue Dec 20 15:59:46 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 | 8 +++++---
 server/red-pipe-item.c       | 6 ++++++
 server/red-pipe-item.h       | 4 ++++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/server/main-channel-client.c b/server/main-channel-client.c
index 7e55b24..a06eb48 100644
--- a/server/main-channel-client.c
+++ b/server/main-channel-client.c
@@ -837,8 +837,10 @@ 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_unref_pipe_item, item);
 }
 
 static void main_channel_marshall_migrate_data_item(RedChannelClient *rcc,
@@ -846,7 +848,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);
 }
diff --git a/server/red-pipe-item.c b/server/red-pipe-item.c
index d899610..2cb5847 100644
--- a/server/red-pipe-item.c
+++ b/server/red-pipe-item.c
@@ -46,3 +46,9 @@ void red_pipe_item_init_full(RedPipeItem *item,
     item->refcount = 1;
     item->free_func = free_func ? free_func : (red_pipe_item_free_t *)free;
 }
+
+void marshaller_unref_pipe_item(uint8_t *data G_GNUC_UNUSED, void *opaque)
+{
+    RedPipeItem *item = opaque;
+    red_pipe_item_unref(item);
+}
diff --git a/server/red-pipe-item.h b/server/red-pipe-item.h
index a589c68..90cc817 100644
--- a/server/red-pipe-item.h
+++ b/server/red-pipe-item.h
@@ -42,4 +42,8 @@ static inline void red_pipe_item_init(RedPipeItem *item, int type)
 {
     red_pipe_item_init_full(item, type, NULL);
 }
+
+/* a convenience function for unreffing a pipe item after it has been sent */
+void marshaller_unref_pipe_item(uint8_t *data, void *opaque);
+
 #endif
-- 
2.7.4



More information about the Spice-devel mailing list