Commits

Fredrik Lundh committed 359fafd

Fixed memory leak in WebP encoder.

  • Participants
  • Parent commits 3e637b2

Comments (0)

Files changed (1)

File libImaging/WebPEncode.c

 	/* copy image contents to packed buffer and compress it */
 
 	stride = state->xsize * 3;
-
 	buffer = malloc(im->ysize * stride);
-
 	if (!buffer) {
 	    state->errcode = IMAGING_CODEC_MEMORY;
 	    return -1;
 	}
+
 	for (ptr = buffer, y = 0; y < state->ysize; ptr += stride, y++) {
 	    state->shuffle(ptr, (UINT8*) im->image[y + state->yoff] +
 			   state->xoff * im->pixelsize, state->xsize);
 					     stride, quality,
 					     &context->output_data);
 
+	free(buffer);
+
 	if (!context->output_size) {
 	    state->errcode = IMAGING_CODEC_BROKEN;
 	    return -1;
 	free(context->output_buffer);
 	return context->output_size;
     } else {
-	/* fill the buffer */
+	/* not enough space; fill the buffer and try again next time */
 	memcpy(buf, context->output_data, bytes);
 	context->output_data += bytes;
 	context->output_size -= bytes;