Fix three minor memleaks

This commit is contained in:
John Cupitt 2013-07-15 22:01:00 +01:00
parent 6b3dc259d1
commit 6167d4d97c
7 changed files with 51 additions and 13 deletions

View File

@ -33,7 +33,8 @@ Checkout the latest sources with:
Then for a debug build: Then for a debug build:
$ ./bootstrap.sh $ ./bootstrap.sh
$ CFLAGS="-g -Wall" CXXFLAGS="-g -Wall" ./configure --prefix=/home/john/vips --enable-gtk-doc $ CFLAGS="-g -Wall" CXXFLAGS="-g -Wall" \
./configure --prefix=/home/john/vips --enable-gtk-doc
$ make $ make
$ make install $ make install
@ -41,6 +42,14 @@ Static analysis with:
$ cppcheck --force --enable=style . &> cppcheck.log $ cppcheck --force --enable=style . &> cppcheck.log
Leak check:
$ export G_DEBUG=gc-friendly
$ export G_SLICE=always-malloc
$ valgrind --suppressions=/home/john/nip2.supp \
--leak-check=yes \
vips ... > vips-vg.log 2>&1
# Dependencies # Dependencies
libvips has to have gettext, glib-2.x and libxml-2.0. The build system needs libvips has to have gettext, glib-2.x and libxml-2.0. The build system needs

View File

@ -135,8 +135,8 @@ vips_linear_build( VipsObject *object )
/* Make up-banded versions of our constants. /* Make up-banded versions of our constants.
*/ */
linear->a_ready = g_new( double, linear->n ); linear->a_ready = VIPS_ARRAY( linear, linear->n, double );
linear->b_ready = g_new( double, linear->n ); linear->b_ready = VIPS_ARRAY( linear, linear->n, double );
for( i = 0; i < linear->n; i++ ) { for( i = 0; i < linear->n; i++ ) {
if( linear->a ) { if( linear->a ) {

View File

@ -164,9 +164,6 @@ readjpeg_free( ReadJpeg *jpeg )
result = 0; result = 0;
if( setjmp( jpeg->eman.jmp ) )
return( -1 );
if( jpeg->eman.pub.num_warnings != 0 ) { if( jpeg->eman.pub.num_warnings != 0 ) {
if( jpeg->fail ) { if( jpeg->fail ) {
vips_error( "VipsJpeg", "%s", vips_error_buffer() ); vips_error( "VipsJpeg", "%s", vips_error_buffer() );
@ -185,13 +182,20 @@ readjpeg_free( ReadJpeg *jpeg )
} }
if( jpeg->decompressing ) { if( jpeg->decompressing ) {
jpeg_finish_decompress( &jpeg->cinfo ); /* jpeg_finish_decompress() can fail ... catch any errors.
*/
if( !setjmp( jpeg->eman.jmp ) )
jpeg_finish_decompress( &jpeg->cinfo );
jpeg->decompressing = FALSE; jpeg->decompressing = FALSE;
} }
VIPS_FREEF( fclose, jpeg->eman.fp ); VIPS_FREEF( fclose, jpeg->eman.fp );
VIPS_FREE( jpeg->filename ); VIPS_FREE( jpeg->filename );
jpeg->eman.fp = NULL; jpeg->eman.fp = NULL;
/* I don't think this can fail.
*/
jpeg_destroy_decompress( &jpeg->cinfo ); jpeg_destroy_decompress( &jpeg->cinfo );
return( result ); return( result );
@ -210,6 +214,7 @@ readjpeg_new( VipsImage *out, int shrink, gboolean fail )
if( !(jpeg = VIPS_NEW( out, ReadJpeg )) ) if( !(jpeg = VIPS_NEW( out, ReadJpeg )) )
return( NULL ); return( NULL );
jpeg->out = out; jpeg->out = out;
jpeg->shrink = shrink; jpeg->shrink = shrink;
jpeg->fail = fail; jpeg->fail = fail;

View File

@ -237,8 +237,8 @@ vips_foreign_save_jpeg_buffer_build( VipsObject *object )
return( -1 ); return( -1 );
area = vips_area_new_blob( (VipsCallbackFn) vips_free, obuf, olen ); area = vips_area_new_blob( (VipsCallbackFn) vips_free, obuf, olen );
g_object_set( file, "buffer", area, NULL ); g_object_set( file, "buffer", area, NULL );
vips_area_unref( area );
return( 0 ); return( 0 );
} }

View File

@ -90,6 +90,8 @@ extern gboolean vips__cache_trace;
void vips__cache_init( void ); void vips__cache_init( void );
void vips__type_leak( void );
typedef int (*im__fftproc_fn)( VipsImage *, VipsImage *, VipsImage * ); typedef int (*im__fftproc_fn)( VipsImage *, VipsImage *, VipsImage * );
/* iofuncs /* iofuncs

View File

@ -327,6 +327,8 @@ vips_leak( void )
vips_buf_appends( &buf, "\n" ); vips_buf_appends( &buf, "\n" );
fprintf( stderr, "%s", vips_buf_all( &buf ) ); fprintf( stderr, "%s", vips_buf_all( &buf ) );
vips__type_leak();
} }
/** /**

View File

@ -142,7 +142,7 @@ vips_thing_get_type( void )
*/ */
#ifdef DEBUG #ifdef DEBUG
static int vips_area_number = 0; static GSList *vips_area_all = NULL;
#endif /*DEBUG*/ #endif /*DEBUG*/
VipsArea * VipsArea *
@ -174,6 +174,7 @@ vips_area_unref( VipsArea *area )
#ifdef DEBUG #ifdef DEBUG
printf( "vips_area_unref: %p count = %d\n", area, area->count ); printf( "vips_area_unref: %p count = %d\n", area, area->count );
g_assert( g_slist_find( vips_area_all, area ) );
#endif /*DEBUG*/ #endif /*DEBUG*/
if( area->count == 0 ) { if( area->count == 0 ) {
@ -190,9 +191,9 @@ vips_area_unref( VipsArea *area )
g_free( area ); g_free( area );
#ifdef DEBUG #ifdef DEBUG
vips_area_number -= 1; vips_area_all = g_slist_remove( vips_area_all, area );
printf( "vips_area_unref: free .. total = %d\n", printf( "vips_area_unref: free .. total = %d\n",
vips_area_number ); g_slist_length( vips_area_all ) );
#endif /*DEBUG*/ #endif /*DEBUG*/
} }
else else
@ -226,14 +227,33 @@ vips_area_new( VipsCallbackFn free_fn, void *data )
area->sizeof_type = 0; area->sizeof_type = 0;
#ifdef DEBUG #ifdef DEBUG
vips_area_number += 1; vips_area_all = g_slist_prepend( vips_area_all, area );
printf( "vips_area_new: %p count = %d (%d in total)\n", printf( "vips_area_new: %p count = %d (%d in total)\n",
area, area->count, vips_area_number ); area, area->count,
g_slist_length( vips_area_all ) );
#endif /*DEBUG*/ #endif /*DEBUG*/
return( area ); return( area );
} }
void
vips__type_leak( void )
{
#ifdef DEBUG
if( vips_area_all ) {
GSList *p;
printf( "VipsArea leaks:\n" );
for( p = vips_area_all; p; p = p->next ) {
VipsArea *area = (VipsArea *) p->data;
printf( "\t%p count = %d\n", area, area->count );
}
printf( "%d in total\n", g_slist_length( vips_area_all ) );
}
#endif /*DEBUG*/
}
/** /**
* vips_area_new_blob: * vips_area_new_blob:
* @free_fn: (scope async): @data will be freed with this function * @free_fn: (scope async): @data will be freed with this function