Fix a few memory leaks in some error conditions during image manipulation.

This commit is contained in:
Justin Maggard 2014-04-29 10:44:34 -07:00
parent 61bb91ecc9
commit 820b5857a5

View File

@ -84,7 +84,6 @@ my_dst_mgr_init(j_compress_ptr cinfo)
dst->jdst.free_in_buffer = dst->sz;
return;
}
static boolean
@ -100,7 +99,6 @@ my_dst_mgr_empty(j_compress_ptr cinfo)
dst->jdst.free_in_buffer = dst->sz - dst->used;
return TRUE;
}
static void
@ -112,7 +110,6 @@ my_dst_mgr_term(j_compress_ptr cinfo)
dst->off = dst->buf + dst->used;
return;
}
static void
@ -124,7 +121,6 @@ jpeg_memory_dest(j_compress_ptr cinfo, struct my_dst_mgr *dst)
cinfo->dest = (void *)dst;
return;
}
/* Source manager to read data from a buffer */
@ -182,10 +178,8 @@ jpeg_memory_src(j_decompress_ptr cinfo, const unsigned char * buffer, size_t buf
{
struct my_src_mgr *src;
if (! cinfo->src)
{
if (!cinfo->src)
cinfo->src = (*cinfo->mem->alloc_small)((void *)cinfo, JPOOL_PERMANENT, sizeof(struct my_src_mgr));;
}
src = (void *)cinfo->src;
src->pub.init_source = init_source;
src->pub.fill_input_buffer = fill_input_buffer;
@ -488,6 +482,7 @@ image_new_from_jpeg(const char *path, int is_file, const uint8_t *buf, int size,
if(cinfo.rec_outbuf_height > 16)
{
DPRINTF(E_WARN, L_METADATA, "ERROR image_from_jpeg : (image_from_jpeg.c) JPEG uses line buffers > 16. Cannot load.\n");
jpeg_destroy_decompress(&cinfo);
image_free(vimage);
if( is_file )
fclose(file);
@ -501,6 +496,7 @@ image_new_from_jpeg(const char *path, int is_file, const uint8_t *buf, int size,
if((ptr = malloc(w * 3 * cinfo.rec_outbuf_height + 16)) == NULL)
{
DPRINTF(E_WARN, L_METADATA, "malloc failed\n");
jpeg_destroy_decompress(&cinfo);
image_free(vimage);
if( is_file )
fclose(file);
@ -815,6 +811,8 @@ image_save_to_jpeg_buf(image_s * pimage, int * size)
if((data = malloc(row_stride)) == NULL)
{
DPRINTF(E_WARN, L_METADATA, "malloc failed\n");
free(dst.buf);
jpeg_destroy_compress(&cinfo);
return NULL;
}
i = 0;