[Spice-commits] 2 commits - server/mjpeg_encoder.c server/mjpeg_encoder.h

Yonit Halperin yhalperi at kemper.freedesktop.org
Mon May 14 00:26:47 PDT 2012


 server/mjpeg_encoder.c |   13 ++++---------
 server/mjpeg_encoder.h |    5 +++++
 2 files changed, 9 insertions(+), 9 deletions(-)

New commits:
commit c211774422455802299545b19ffdffd9496fdc31
Author: Yonit Halperin <yhalperi at redhat.com>
Date:   Thu May 10 14:01:39 2012 +0300

    server/mjpeg_encoder: fix wrong size assigned to dest_len
    
    It should have been the allocated size and not the occupied one.
    This led to a lot of unnecessary allocations and deallocations.

diff --git a/server/mjpeg_encoder.c b/server/mjpeg_encoder.c
index 3c2fc31..6bb2f69 100644
--- a/server/mjpeg_encoder.c
+++ b/server/mjpeg_encoder.c
@@ -140,7 +140,7 @@ static void term_mem_destination(j_compress_ptr cinfo)
   mem_destination_mgr *dest = (mem_destination_mgr *) cinfo->dest;
 
   *dest->outbuffer = dest->buffer;
-  *dest->outsize = dest->bufsize - dest->pub.free_in_buffer;
+  *dest->outsize = dest->bufsize;
 }
 
 /*
commit fecc1e3d4d3d93ade71a318ad655e85974638162
Author: Yonit Halperin <yhalperi at redhat.com>
Date:   Thu May 10 12:26:01 2012 +0300

    server/mjpeg_encoder: Fix memory leak for the inital output buffer given for each frame

diff --git a/server/mjpeg_encoder.c b/server/mjpeg_encoder.c
index 9c3d079..3c2fc31 100644
--- a/server/mjpeg_encoder.c
+++ b/server/mjpeg_encoder.c
@@ -101,7 +101,6 @@ typedef struct {
 
   unsigned char ** outbuffer;	/* target buffer */
   size_t * outsize;
-  unsigned char * newbuffer;	/* newly allocated buffer */
   uint8_t * buffer;		/* start of buffer */
   size_t bufsize;
 } mem_destination_mgr;
@@ -125,9 +124,7 @@ static boolean empty_mem_output_buffer(j_compress_ptr cinfo)
 
   memcpy(nextbuffer, dest->buffer, dest->bufsize);
 
-  free(dest->newbuffer);
-
-  dest->newbuffer = nextbuffer;
+  free(dest->buffer);
 
   dest->pub.next_output_byte = nextbuffer + dest->bufsize;
   dest->pub.free_in_buffer = dest->bufsize;
@@ -180,12 +177,10 @@ spice_jpeg_mem_dest(j_compress_ptr cinfo,
   dest->pub.term_destination = term_mem_destination;
   dest->outbuffer = outbuffer;
   dest->outsize = outsize;
-  dest->newbuffer = NULL;
-
   if (*outbuffer == NULL || *outsize == 0) {
     /* Allocate initial buffer */
-    dest->newbuffer = *outbuffer = malloc(OUTPUT_BUF_SIZE);
-    if (dest->newbuffer == NULL)
+    *outbuffer = malloc(OUTPUT_BUF_SIZE);
+    if (*outbuffer == NULL)
       ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
     *outsize = OUTPUT_BUF_SIZE;
   }
diff --git a/server/mjpeg_encoder.h b/server/mjpeg_encoder.h
index 91297d0..b9a2ed7 100644
--- a/server/mjpeg_encoder.h
+++ b/server/mjpeg_encoder.h
@@ -27,6 +27,11 @@ MJpegEncoder *mjpeg_encoder_new(void);
 void mjpeg_encoder_destroy(MJpegEncoder *encoder);
 
 uint8_t mjpeg_encoder_get_bytes_per_pixel(MJpegEncoder *encoder);
+
+/*
+ * *dest must be either NULL or allocated by malloc, since it might be freed
+ * during the encoding, if its size is too small.
+ */
 int mjpeg_encoder_start_frame(MJpegEncoder *encoder, SpiceBitmapFmt format,
                               int width, int height,
                               uint8_t **dest, size_t *dest_len);


More information about the Spice-commits mailing list