Allocate from temporary image pool to avoid leaking mem mgr

This commit is contained in:
Kornel Lesiński
2016-05-06 15:39:30 +01:00
parent dbbf6185a9
commit 5ff20ca303
3 changed files with 24 additions and 7 deletions

View File

@@ -518,7 +518,7 @@ prepare_for_pass (j_compress_ptr cinfo)
master->saved_dest = cinfo->dest; master->saved_dest = cinfo->dest;
cinfo->dest = NULL; cinfo->dest = NULL;
master->scan_size[master->scan_number] = 0; master->scan_size[master->scan_number] = 0;
jpeg_mem_dest(cinfo, &master->scan_buffer[master->scan_number], &master->scan_size[master->scan_number]); jpeg_mem_dest_internal(cinfo, &master->scan_buffer[master->scan_number], &master->scan_size[master->scan_number], JPOOL_IMAGE);
(*cinfo->dest->init_destination)(cinfo); (*cinfo->dest->init_destination)(cinfo);
} }
(*cinfo->entropy->start_pass) (cinfo, FALSE); (*cinfo->entropy->start_pass) (cinfo, FALSE);

View File

@@ -208,9 +208,9 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE *outfile)
{ {
my_dest_ptr dest; my_dest_ptr dest;
/* The destination object is made permanent so that multiple JPEG images /* The destination object is made permanent so that multiple JPEG images
* can be written to the same file without re-executing jpeg_stdio_dest. * can be written to the same file without re-executing jpeg_stdio_dest.
*/ */
if (cinfo->dest == NULL) { /* first time for this JPEG object? */ if (cinfo->dest == NULL) { /* first time for this JPEG object? */
cinfo->dest = (struct jpeg_destination_mgr *) cinfo->dest = (struct jpeg_destination_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
@@ -249,8 +249,8 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE *outfile)
*/ */
GLOBAL(void) GLOBAL(void)
jpeg_mem_dest (j_compress_ptr cinfo, jpeg_mem_dest_internal (j_compress_ptr cinfo,
unsigned char **outbuffer, unsigned long *outsize) unsigned char **outbuffer, unsigned long *outsize, int pool_id)
{ {
my_mem_dest_ptr dest; my_mem_dest_ptr dest;
@@ -262,7 +262,7 @@ jpeg_mem_dest (j_compress_ptr cinfo,
*/ */
if (cinfo->dest == NULL) { /* first time for this JPEG object? */ if (cinfo->dest == NULL) { /* first time for this JPEG object? */
cinfo->dest = (struct jpeg_destination_mgr *) cinfo->dest = (struct jpeg_destination_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, pool_id,
sizeof(my_mem_destination_mgr)); sizeof(my_mem_destination_mgr));
} else if (cinfo->dest->init_destination != init_mem_destination) { } else if (cinfo->dest->init_destination != init_mem_destination) {
/* It is unsafe to reuse the existing destination manager unless it was /* It is unsafe to reuse the existing destination manager unless it was
@@ -290,4 +290,15 @@ jpeg_mem_dest (j_compress_ptr cinfo,
dest->pub.next_output_byte = dest->buffer = *outbuffer; dest->pub.next_output_byte = dest->buffer = *outbuffer;
dest->pub.free_in_buffer = dest->bufsize = *outsize; dest->pub.free_in_buffer = dest->bufsize = *outsize;
} }
GLOBAL(void)
jpeg_mem_dest (j_compress_ptr cinfo,
unsigned char **outbuffer, unsigned long *outsize)
{
/* The destination object is made permanent so that multiple JPEG images
* can be written to the same file without re-executing jpeg_stdio_dest.
*/
jpeg_mem_dest_internal(cinfo, outbuffer, outsize, JPOOL_PERMANENT);
}
#endif #endif

View File

@@ -402,6 +402,12 @@ EXTERN(void) jinit_merged_upsampler (j_decompress_ptr cinfo);
/* Memory manager initialization */ /* Memory manager initialization */
EXTERN(void) jinit_memory_mgr (j_common_ptr cinfo); EXTERN(void) jinit_memory_mgr (j_common_ptr cinfo);
#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)
EXTERN(void)
jpeg_mem_dest_internal (j_compress_ptr cinfo,
unsigned char **outbuffer, unsigned long *outsize, int pool_id);
#endif
/* Utility routines in jutils.c */ /* Utility routines in jutils.c */
EXTERN(long) jdiv_round_up (long a, long b); EXTERN(long) jdiv_round_up (long a, long b);
EXTERN(long) jround_up (long a, long b); EXTERN(long) jround_up (long a, long b);