From a5e5e694570cda71ff13a3908a1cb8ffa59bd9cf Mon Sep 17 00:00:00 2001 From: Yang Rong Date: Wed, 18 Sep 2013 17:09:29 +0800 Subject: [PATCH] Unmap the cl_mem in driver when application map a cl_mem and release without unmap. Signed-off-by: Yang Rong Reviewed-by: Zhigang Gong --- src/cl_mem.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cl_mem.c b/src/cl_mem.c index d901f9f..769e1cb 100644 --- a/src/cl_mem.c +++ b/src/cl_mem.c @@ -536,6 +536,7 @@ cl_mem_new_image(cl_context context, LOCAL void cl_mem_delete(cl_mem mem) { + cl_int i; if (UNLIKELY(mem == NULL)) return; if (atomic_dec(&mem->ref_n) > 1) @@ -560,8 +561,17 @@ cl_mem_delete(cl_mem mem) pthread_mutex_unlock(&mem->ctx->buffer_lock); cl_context_delete(mem->ctx); - /* Someone still mapped? */ - assert(!mem->map_ref); + /* Someone still mapped, unmap */ + if(mem->map_ref > 0) { + assert(mem->mapped_ptr); + for(i=0; imapped_ptr_sz; i++) { + if(mem->mapped_ptr[i].ptr != NULL) { + mem->map_ref--; + cl_mem_unmap_gtt(mem); + } + } + assert(mem->map_ref == 0); + } if (mem->mapped_ptr) free(mem->mapped_ptr); -- 2.7.4