fix a small memleak in reorder

if set_input was called more than once, it could leak the arrays

thanks @gczuba!

see https://github.com/jcupitt/libvips/issues/607
This commit is contained in:
John Cupitt 2017-02-23 07:50:35 +00:00
parent 09774740a7
commit f84825a634

View File

@ -114,11 +114,6 @@ vips_reorder_print( VipsReorder *reorder )
static void
vips_reorder_destroy( VipsReorder *reorder )
{
VIPS_FREE( reorder->input );
VIPS_FREE( reorder->score );
VIPS_FREE( reorder->recomp_order );
VIPS_FREE( reorder->source );
VIPS_FREE( reorder->cumulative_margin );
VIPS_FREE( reorder );
}
@ -196,9 +191,9 @@ vips__reorder_set_input( VipsImage *image, VipsImage **in )
for( i = 0; in[i]; i++ )
;
reorder->n_inputs = i;
reorder->input = VIPS_ARRAY( NULL, reorder->n_inputs + 1, VipsImage * );
reorder->score = VIPS_ARRAY( NULL, reorder->n_inputs, int );
reorder->recomp_order = VIPS_ARRAY( NULL, reorder->n_inputs, int );
reorder->input = VIPS_ARRAY( image, reorder->n_inputs + 1, VipsImage * );
reorder->score = VIPS_ARRAY( image, reorder->n_inputs, int );
reorder->recomp_order = VIPS_ARRAY( image, reorder->n_inputs, int );
if( !reorder->input )
return( -1 );
if( reorder->n_inputs &&
@ -225,8 +220,8 @@ vips__reorder_set_input( VipsImage *image, VipsImage **in )
*/
total = VIPS_MAX( 1, total );
reorder->source = VIPS_ARRAY( NULL, total + 1, VipsImage * );
reorder->cumulative_margin = VIPS_ARRAY( NULL, total, int );
reorder->source = VIPS_ARRAY( image, total + 1, VipsImage * );
reorder->cumulative_margin = VIPS_ARRAY( image, total, int );
if( !reorder->source ||
!reorder->cumulative_margin )
return( -1 );