[Spice-devel] [PATCH spice-server 04/10] mjpeg: Reuse realloc instead of implementing it manually
Christophe Fergeau
cfergeau at redhat.com
Mon Sep 11 15:45:44 UTC 2017
On Mon, Sep 11, 2017 at 11:15:41AM +0100, Frediano Ziglio wrote:
> This potentially can also save the copy if there are enough
> space to resize the buffer in place.
"if there is"
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
>
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
> server/mjpeg-encoder.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/server/mjpeg-encoder.c b/server/mjpeg-encoder.c
> index 15f5e1f2f..07ca69c20 100644
> --- a/server/mjpeg-encoder.c
> +++ b/server/mjpeg-encoder.c
> @@ -278,15 +278,11 @@ static boolean empty_mem_output_buffer(j_compress_ptr cinfo)
>
> /* Try to allocate new buffer with double size */
> nextsize = dest->bufsize * 2;
> - nextbuffer = malloc(nextsize);
> + nextbuffer = realloc(dest->buffer, nextsize);
>
> if (nextbuffer == NULL)
> ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
>
> - memcpy(nextbuffer, dest->buffer, dest->bufsize);
> -
> - free(dest->buffer);
> -
> dest->pub.next_output_byte = nextbuffer + dest->bufsize;
> dest->pub.free_in_buffer = dest->bufsize;
>
> --
> 2.13.5
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
More information about the Spice-devel
mailing list