ThreadPool was allocating memory for threads and pools locally to the image object. As that image could not be freed from cache, for each sink operation done for that image the code was creating new pools and threads without freeing the previous one. SO the more number of threads and the more operations the bigger the hidden leak was. The fix just creates the objects not locally to that image, and also free them in its destroy functions

This commit is contained in:
jtorresfabra 2019-02-27 13:01:45 +01:00
parent 1a83605238
commit 8c8affab7f

View File

@ -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
@ -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;
@ -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: "
@ -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 );
}
@ -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;
@ -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 );
@ -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;