From a5135bab78e20f0313232559540039f45bad5ca9 Mon Sep 17 00:00:00 2001 From: dirk Date: Sun, 19 Jun 2016 12:33:28 +0200 Subject: [PATCH] Fixed memory leak in CopyMagickCLCacheInfo and made the method more asynchronous. --- MagickCore/opencl.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/MagickCore/opencl.c b/MagickCore/opencl.c index 195948aaf..197b87b80 100644 --- a/MagickCore/opencl.c +++ b/MagickCore/opencl.c @@ -1417,17 +1417,25 @@ MagickPrivate MagickCLCacheInfo CopyMagickCLCacheInfo(MagickCLCacheInfo info) cl_command_queue queue; + cl_event + event; + Quantum *pixels; - if (info == (MagickCLCacheInfo) NULL || info->event_count == 0) + if (info == (MagickCLCacheInfo) NULL) return((MagickCLCacheInfo) NULL); - queue=AcquireOpenCLCommandQueue(info->device); - pixels=openCL_library->clEnqueueMapBuffer(queue,info->buffer,CL_TRUE, - CL_MAP_READ | CL_MAP_WRITE,0,info->length,info->event_count,info->events, - NULL,NULL); - assert(pixels == info->pixels); - RelinquishOpenCLCommandQueue(info->device,queue); + if (info->event_count > 0) + { + queue=AcquireOpenCLCommandQueue(info->device); + pixels=openCL_library->clEnqueueMapBuffer(queue,info->buffer,CL_FALSE, + CL_MAP_READ | CL_MAP_WRITE,0,info->length,info->event_count, + info->events,&event,(cl_int *) NULL); + assert(pixels == info->pixels); + RelinquishOpenCLCommandQueue(info->device,queue); + openCL_library->clWaitForEvents(1,&event); + openCL_library->clReleaseEvent(event); + } return(RelinquishMagickCLCacheInfo(info,MagickFalse)); } -- 2.40.0