[Spice-devel] [PATCH spice-gtk 01/10] spice-channel: Fix a possible race triggered by spice_channel_iterate_write

Christophe Fergeau cfergeau at redhat.com
Wed Aug 17 06:42:56 PDT 2011


Hi,

On Fri, Aug 12, 2011 at 04:50:28PM +0200, Hans de Goede wrote:
> -    if (c->xmit_buffer_size) {
> -        spice_channel_write(channel, c->xmit_buffer, c->xmit_buffer_size);
> +    if (c->xmit_buffer) {
> +        /*
> +         * Take ownership of the buffer, so that if spice_channel_write calls
> +         * g_io_wait and thus yields to the main context, and that then calls
> +         * spice_channel_buffered_write it does not mess with the buffer
> +         * being written out.
> +         */
> +        guint8 *buffer = c->xmit_buffer;
> +        int size = c->xmit_buffer_size;
> +
> +        c->xmit_buffer = NULL;
>          c->xmit_buffer_size = 0;
> +        c->xmit_buffer_capacity = 0;
> +
> +        spice_channel_write(channel, buffer, size);
> +        g_free(buffer);

I don't know if you're planning to emit a lot of messages per second with
the USB channel, having something like
if (c->xmit_buffer == NULL)
    c->xmit_buffer = buffer;
    c->xmit_buffer_capacity = ...;
    c->xmit_buffer_size = 0;
} else {
    g_free (buffer)
}

would save some allocations later on.

I'm ACKing either version.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20110817/d79b80d0/attachment.pgp>


More information about the Spice-devel mailing list