Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for hidden leaks in ThreadPool #1240

Merged
merged 1 commit into from
Feb 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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