summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Beaulieu <patrick.beaulieu@avigilon.com>2017-06-15 23:15:15 +0000
committerYang Rong <rong.r.yang@intel.com>2017-06-16 19:12:18 +0800
commit4775abfe1c4d0614cf06be02707b9f2f4eabbc2f (patch)
tree8da6d049e68659d09a19ca47417b6def9fe9d4bf
parent21af2ef495dd51924a238d3fce1bd7e8eb09c491 (diff)
Fix context leak with internal kernels
Account for internal program ctx references in cl_context_delete Signed-off-by: Patrick Beaulieu <patrick.beaulieu@avigilon.com> Reviewed-by: Yang Rong <rong.r.yang@intel.com>
-rw-r--r--src/cl_context.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/cl_context.c b/src/cl_context.c
index 4b8281c1..c5f36781 100644
--- a/src/cl_context.c
+++ b/src/cl_context.c
@@ -359,10 +359,28 @@ cl_context_delete(cl_context ctx)
if (UNLIKELY(ctx == NULL))
return;
+ int internal_ctx_refs = 1;
+ // determine how many ctx refs are held by internal_prgs and built_in_prgs
+ for (i = CL_INTERNAL_KERNEL_MIN; i < CL_INTERNAL_KERNEL_MAX; i++) {
+ if (ctx->internal_kernels[i] && ctx->internal_prgs[i])
+ ++internal_ctx_refs;
+ }
+
+ if (ctx->built_in_prgs)
+ ++internal_ctx_refs;
+
+ if (ctx->image_queue)
+ ++internal_ctx_refs;
+
/* We are not done yet */
- if (CL_OBJECT_DEC_REF(ctx) > 1)
+ if (CL_OBJECT_DEC_REF(ctx) > internal_ctx_refs)
return;
+ // create a temporary extra ref here so cl_program_delete doesn't
+ // attempt a recursive full cl_context_delete when cleaning up
+ // our internal programs
+ CL_OBJECT_INC_REF(ctx);
+
if (ctx->image_queue) {
clReleaseCommandQueue(ctx->image_queue);
ctx->image_queue = NULL;
@@ -388,6 +406,8 @@ cl_context_delete(cl_context ctx)
cl_program_delete(ctx->built_in_prgs);
ctx->built_in_prgs = NULL;
+ CL_OBJECT_DEC_REF(ctx);
+
cl_free(ctx->prop_user);
cl_free(ctx->devices);
cl_driver_delete(ctx->drv);