[Beignet] [PATCH] Return error, don't crash, on allocation failure

Zhigang Gong zhigang.gong at linux.intel.com
Thu Feb 5 21:04:00 PST 2015


The patch LGTM, will push latter, thanks.

On Wed, Feb 04, 2015 at 06:00:37PM +0000, Rebecca N. Palmer wrote:
> As previously noted, when cl_mem_allocate fails, its error handling
> then calls cl_mem_delete on the incompletely-set-up buffer, which
> aborts at assert(mem->ctx).
> 
> This patch appears to fix the problem, but be warned I don't know
> this code well enough to know what else it might break.
> 
> Signed-off-by: Rebecca Palmer <rebecca_palmer at zoho.com>
> 
> diff --git a/src/cl_mem.c b/src/cl_mem.c
> index 2ec89a4..99d8381 100644
> --- a/src/cl_mem.c
> +++ b/src/cl_mem.c
> @@ -1071,16 +1071,19 @@ cl_mem_delete(cl_mem mem)
>    }
> 
>    /* Remove it from the list */
> -  assert(mem->ctx);
> -  pthread_mutex_lock(&mem->ctx->buffer_lock);
> -    if (mem->prev)
> -      mem->prev->next = mem->next;
> -    if (mem->next)
> -      mem->next->prev = mem->prev;
> -    if (mem->ctx->buffers == mem)
> -      mem->ctx->buffers = mem->next;
> -  pthread_mutex_unlock(&mem->ctx->buffer_lock);
> -  cl_context_delete(mem->ctx);
> +  if (mem->ctx) {
> +    pthread_mutex_lock(&mem->ctx->buffer_lock);
> +      if (mem->prev)
> +        mem->prev->next = mem->next;
> +      if (mem->next)
> +        mem->next->prev = mem->prev;
> +      if (mem->ctx->buffers == mem)
> +        mem->ctx->buffers = mem->next;
> +    pthread_mutex_unlock(&mem->ctx->buffer_lock);
> +    cl_context_delete(mem->ctx);
> +  } else {
> +    assert((mem->prev == 0) && (mem->next == 0));
> +  }
> 
>    /* Someone still mapped, unmap */
>    if(mem->map_ref > 0) {
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list