--- src/channel-usbredir.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c index 2a7282c..f09b0bf 100644 --- a/src/channel-usbredir.c +++ b/src/channel-usbredir.c @@ -642,20 +642,15 @@ static void usbredir_free_write_cb_data(uint8_t *data, void *user_data) } #ifdef USE_LZ4 -static void usbredir_free_write_cb_compressed_data(uint8_t *data, void *user_data) -{ - SpiceUsbredirChannel *channel = user_data; - SpiceUsbredirChannelPrivate *priv = channel->priv; - - usbredirhost_free_write_buffer(priv->host, - (uint8_t*)SPICE_CONTAINEROF(data, SpiceMsgCompressedData, compressed_data)); -} - static int try_write_compress_LZ4(SpiceUsbredirChannel *channel, uint8_t *data, int count) { SpiceChannelPrivate *c; SpiceMsgOut *msg_out_compressed; int bound, compressed_data_count; - SpiceMsgCompressedData *compressed_data_msg; + uint8_t *compressed_buf; + SpiceMsgCompressedData compressed_data_msg = { + .type = SPICE_DATA_COMPRESSION_TYPE_LZ4, + .uncompressed_size = count + }; c = SPICE_CHANNEL(channel)->priv; if (g_socket_get_family(c->sock) == G_SOCKET_FAMILY_UNIX) { @@ -676,29 +671,28 @@ static int try_write_compress_LZ4(SpiceUsbredirChannel *channel, uint8_t *data, /* Invalid bound - data will not be compressed */ return FALSE; } - compressed_data_msg = (SpiceMsgCompressedData*)spice_malloc(sizeof(SpiceMsgCompressedData) + bound); - compressed_data_msg->uncompressed_size = count; - compressed_data_msg->type = SPICE_DATA_COMPRESSION_TYPE_LZ4; + + compressed_buf = (uint8_t*)spice_malloc(bound); compressed_data_count = LZ4_compress_default((char*)data, - (char*)compressed_data_msg->compressed_data, + (char*)compressed_buf, count, bound); if (compressed_data_count > 0) { - compressed_data_msg->compressed_size = compressed_data_count; + compressed_data_msg.compressed_data = compressed_buf; msg_out_compressed = spice_msg_out_new(SPICE_CHANNEL(channel), SPICE_MSGC_SPICEVMC_COMPRESSED_DATA); msg_out_compressed->marshallers->msg_SpiceMsgCompressedData(msg_out_compressed->marshaller, - compressed_data_msg); + &compressed_data_msg); spice_marshaller_add_ref_full(msg_out_compressed->marshaller, - compressed_data_msg->compressed_data, + compressed_data_msg.compressed_data, compressed_data_count, - usbredir_free_write_cb_compressed_data, + usbredir_free_write_cb_data, channel); spice_msg_out_send(msg_out_compressed); return TRUE; } /* if not - free & fallback to sending the message uncompressed */ - free(compressed_data_msg); + free(compressed_buf); return FALSE; } #endif -- 2.5.5 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel