[1/3] Runtime: fix a recurrent release context error.

Submitted by Yang, Rong R on June 20, 2017, 11:07 a.m.

Details

Message ID 1497956867-27364-1-git-send-email-rong.r.yang@intel.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Beignet

Not browsing as part of any series.

Commit Message

Yang, Rong R June 20, 2017, 11:07 a.m.
Before release internal resources, must set them to null, otherwize,
when delete these resources, will call release context again.
The ctx->built_in_prgs should be release by application.

Signed-off-by: Yang Rong <rong.r.yang@intel.com>
---
 src/cl_context.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/cl_context.c b/src/cl_context.c
index c5f3678..f3dd421 100644
--- a/src/cl_context.c
+++ b/src/cl_context.c
@@ -366,9 +366,6 @@  cl_context_delete(cl_context ctx)
       ++internal_ctx_refs;
   }
 
-  if (ctx->built_in_prgs)
-    ++internal_ctx_refs;
-
   if (ctx->image_queue)
     ++internal_ctx_refs;
 
@@ -382,30 +379,31 @@  cl_context_delete(cl_context ctx)
   CL_OBJECT_INC_REF(ctx);
 
   if (ctx->image_queue) {
-    clReleaseCommandQueue(ctx->image_queue);
+    cl_command_queue q = ctx->image_queue;
     ctx->image_queue = NULL;
+    clReleaseCommandQueue(q);
   }
 
   /* delete the internal programs. */
   for (i = CL_INTERNAL_KERNEL_MIN; i < CL_INTERNAL_KERNEL_MAX; i++) {
     if (ctx->internal_kernels[i]) {
-      cl_kernel_delete(ctx->internal_kernels[i]);
+      cl_kernel k = ctx->internal_kernels[i];
       ctx->internal_kernels[i] = NULL;
+      cl_kernel_delete(k);
 
       assert(ctx->internal_prgs[i]);
-      cl_program_delete(ctx->internal_prgs[i]);
+      cl_program p = ctx->internal_prgs[i];
       ctx->internal_prgs[i] = NULL;
+      cl_program_delete(p);
     }
 
     if (ctx->built_in_kernels[i]) {
-      cl_kernel_delete(ctx->built_in_kernels[i]);
+      cl_kernel k = ctx->built_in_kernels[i];
       ctx->built_in_kernels[i] = NULL;
+      cl_kernel_delete(k);
     }
   }
 
-  cl_program_delete(ctx->built_in_prgs);
-  ctx->built_in_prgs = NULL;
-
   CL_OBJECT_DEC_REF(ctx);
 
   cl_free(ctx->prop_user);

Comments

> -----Original Message-----

> From: Beignet [mailto:beignet-bounces@lists.freedesktop.org] On Behalf Of

> Yang Rong

> Sent: Tuesday, June 20, 2017 7:08 PM

> To: beignet@lists.freedesktop.org

> Cc: Yang, Rong R <rong.r.yang@intel.com>

> Subject: [Beignet] [PATCH 1/3] Runtime: fix a recurrent release context error.

> 

> Before release internal resources, must set them to null, otherwize,

> when delete these resources, will call release context again.

> The ctx->built_in_prgs should be release by application.

> 

> Signed-off-by: Yang Rong <rong.r.yang@intel.com>

> ---

>  src/cl_context.c | 18 ++++++++----------

>  1 file changed, 8 insertions(+), 10 deletions(-)


I am OK with the patchset.

Thanks!
Ruiling
This patchset is OK for me.

On Tue, Jun 20, 2017 at 07:07:45PM +0800, Yang Rong wrote:
> Date: Tue, 20 Jun 2017 19:07:45 +0800
> From: Yang Rong <rong.r.yang@intel.com>
> To: beignet@lists.freedesktop.org
> Cc: Yang Rong <rong.r.yang@intel.com>
> Subject: [Beignet] [PATCH 1/3] Runtime: fix a recurrent release context
>  error.
> X-Mailer: git-send-email 2.1.4
> 
> Before release internal resources, must set them to null, otherwize,
> when delete these resources, will call release context again.
> The ctx->built_in_prgs should be release by application.
> 
> Signed-off-by: Yang Rong <rong.r.yang@intel.com>
> ---
>  src/cl_context.c | 18 ++++++++----------
>  1 file changed, 8 insertions(+), 10 deletions(-)
> 
> diff --git a/src/cl_context.c b/src/cl_context.c
> index c5f3678..f3dd421 100644
> --- a/src/cl_context.c
> +++ b/src/cl_context.c
> @@ -366,9 +366,6 @@ cl_context_delete(cl_context ctx)
>        ++internal_ctx_refs;
>    }
>  
> -  if (ctx->built_in_prgs)
> -    ++internal_ctx_refs;
> -
>    if (ctx->image_queue)
>      ++internal_ctx_refs;
>  
> @@ -382,30 +379,31 @@ cl_context_delete(cl_context ctx)
>    CL_OBJECT_INC_REF(ctx);
>  
>    if (ctx->image_queue) {
> -    clReleaseCommandQueue(ctx->image_queue);
> +    cl_command_queue q = ctx->image_queue;
>      ctx->image_queue = NULL;
> +    clReleaseCommandQueue(q);
>    }
>  
>    /* delete the internal programs. */
>    for (i = CL_INTERNAL_KERNEL_MIN; i < CL_INTERNAL_KERNEL_MAX; i++) {
>      if (ctx->internal_kernels[i]) {
> -      cl_kernel_delete(ctx->internal_kernels[i]);
> +      cl_kernel k = ctx->internal_kernels[i];
>        ctx->internal_kernels[i] = NULL;
> +      cl_kernel_delete(k);
>  
>        assert(ctx->internal_prgs[i]);
> -      cl_program_delete(ctx->internal_prgs[i]);
> +      cl_program p = ctx->internal_prgs[i];
>        ctx->internal_prgs[i] = NULL;
> +      cl_program_delete(p);
>      }
>  
>      if (ctx->built_in_kernels[i]) {
> -      cl_kernel_delete(ctx->built_in_kernels[i]);
> +      cl_kernel k = ctx->built_in_kernels[i];
>        ctx->built_in_kernels[i] = NULL;
> +      cl_kernel_delete(k);
>      }
>    }
>  
> -  cl_program_delete(ctx->built_in_prgs);
> -  ctx->built_in_prgs = NULL;
> -
>    CL_OBJECT_DEC_REF(ctx);
>  
>    cl_free(ctx->prop_user);
> -- 
> 2.1.4
> 
> _______________________________________________
> Beignet mailing list
> Beignet@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/beignet