tiny cleanup

make the code for error during jpeg buffer write a little cleaner --
rather than calling the jpeg term method ourselves, have a separate
destroy function for the write buffer
This commit is contained in:
John Cupitt 2017-12-19 08:56:51 +00:00
parent ce2ec4cf01
commit eea8b61f3f
2 changed files with 26 additions and 8 deletions

View File

@ -2,8 +2,9 @@
- stop window new/free cycling .. faster zoom out on large images in nip2
- fix some compiler warnings
- remove the 64-image limit on bandary operations
- better version date, thanks bmwiedemann
- bump wrapper script version, thanks bgilbert
- better version date [bmwiedemann]
- bump wrapper script version [bgilbert]
- fix a memleak with an error during jpeg buffer write [lovell]
15/4/17 started 8.6.0
- supports fits images with leading non-image HDUs, thanks benepo

View File

@ -84,6 +84,8 @@
* - move exif handling out to exif.c
* 27/2/17
* - use dbuf for memory output
* 19/12/17 Lovell
* - fix a leak with an error during buffer output
*/
/*
@ -618,6 +620,8 @@ write_vips( Write *write, int qfac, const char *profile,
if( setjmp( write->eman.jmp ) )
return( -1 );
/* This should obly be called on a successful write.
*/
jpeg_finish_compress( &write->cinfo );
return( 0 );
@ -725,7 +729,21 @@ init_destination( j_compress_ptr cinfo )
empty_output_buffer( cinfo );
}
/* Cleanup. Copy the set of blocks out as a big lump.
/* Free the buffer writer.
*/
static void
buf_destroy( j_compress_ptr cinfo )
{
if( cinfo->dest ) {
OutputBuffer *buf = (OutputBuffer *) cinfo->dest;
vips_dbuf_destroy( &buf->dbuf );
}
}
/* Cleanup. Copy the set of blocks out as a big lump. This is only called by
* libjpeg on successful write --- you must call buf_destroy() explicitly to
* release resources.
*/
METHODDEF(void)
term_destination( j_compress_ptr cinfo )
@ -798,7 +816,7 @@ vips__jpeg_write_buffer( VipsImage *in,
/* Make jpeg compression object.
*/
if( setjmp( write->eman.jmp ) ) {
/* Here for longjmp() from new_error_exit().
/* Here for longjmp() from new_error_exit() during setup.
*/
write_destroy( write );
@ -810,19 +828,18 @@ vips__jpeg_write_buffer( VipsImage *in,
*/
buf_dest( &write->cinfo, obuf, olen );
/* Convert!
/* Convert! Write errors come back here as an error return.
*/
if( write_vips( write,
Q, profile, optimize_coding, progressive, strip, no_subsample,
trellis_quant, overshoot_deringing, optimize_scans,
quant_table ) ) {
term_destination( &write->cinfo );
VIPS_FREE( *obuf );
*olen = 0;
buf_destroy( &write->cinfo );
write_destroy( write );
return( -1 );
}
buf_destroy( &write->cinfo );
write_destroy( write );
return( 0 );