Skip to content

Commit

Permalink
Merge pull request #1240 from jtorresfabra/fix_hidden_threapool_leak
Browse files Browse the repository at this point in the history
Fix for hidden leaks in ThreadPool
  • Loading branch information
jcupitt committed Feb 27, 2019
2 parents 793cbee + 8c8affa commit 3324ed8
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions libvips/iofuncs/threadpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,9 @@ vips_thread_free( VipsThread *thr )

VIPS_FREEF( g_object_unref, thr->state );
thr->pool = NULL;
/* Free the thread memory
*/
g_free(thr);
}

static int
Expand Down Expand Up @@ -703,7 +706,7 @@ vips_thread_new( VipsThreadpool *pool )
{
VipsThread *thr;

if( !(thr = VIPS_NEW( pool->im, VipsThread )) )
if( !(thr = VIPS_NEW( NULL, VipsThread )) )
return( NULL );
thr->pool = pool;
thr->state = NULL;
Expand Down Expand Up @@ -738,7 +741,9 @@ vips_threadpool_kill_threads( VipsThreadpool *pool )
vips_thread_free( pool->thr[i] );
pool->thr[i] = NULL;
}

/* Free the thread array
*/
g_free(pool->thr);
pool->thr = NULL;

VIPS_DEBUG_MSG( "vips_threadpool_kill_threads: "
Expand All @@ -758,7 +763,9 @@ vips_threadpool_free( VipsThreadpool *pool )
VIPS_FREEF( vips_g_mutex_free, pool->allocate_lock );
vips_semaphore_destroy( &pool->finish );
vips_semaphore_destroy( &pool->tick );

/* Free pool memory
*/
g_free(pool);
return( 0 );
}

Expand All @@ -779,7 +786,7 @@ vips_threadpool_new( VipsImage *im )

/* Allocate and init new thread block.
*/
if( !(pool = VIPS_NEW( im, VipsThreadpool )) )
if( !(pool = VIPS_NEW( NULL, VipsThreadpool )) )
return( NULL );
pool->im = im;
pool->allocate = NULL;
Expand All @@ -802,11 +809,6 @@ vips_threadpool_new( VipsImage *im )
n_tiles = VIPS_CLIP( 0, n_tiles, MAX_THREADS );
pool->nthr = VIPS_MIN( pool->nthr, n_tiles );

/* Attach tidy-up callback.
*/
g_signal_connect( im, "close",
G_CALLBACK( vips_threadpool_new_cb ), pool );

VIPS_DEBUG_MSG( "vips_threadpool_new: \"%s\" (%p), with %d threads\n",
im->filename, pool, pool->nthr );

Expand All @@ -824,7 +826,7 @@ vips_threadpool_create_threads( VipsThreadpool *pool )

/* Make thread array.
*/
if( !(pool->thr = VIPS_ARRAY( pool->im, pool->nthr, VipsThread * )) )
if( !(pool->thr = VIPS_ARRAY( NULL, pool->nthr, VipsThread * )) )
return( -1 );
for( i = 0; i < pool->nthr; i++ )
pool->thr[i] = NULL;
Expand Down

0 comments on commit 3324ed8

Please sign in to comment.