[Spice-devel] [PATCH spice-server 04/10] mjpeg: Reuse realloc instead of implementing it manually
Frediano Ziglio
fziglio at redhat.com
Mon Sep 11 10:15:41 UTC 2017
This potentially can also save the copy if there are enough
space to resize the buffer in place.
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
More information about the Spice-devel
mailing list