[Beignet] [PATCH] runtime: don't free the host_ptr for a subbuffer.

Zhigang Gong zhigang.gong at intel.com
Fri Feb 6 01:52:46 PST 2015


When the buffer has CL_MEM_ALLOC_HOST_PTR, the runtime
need to free the host_ptr at destructor. But if the buffer
is a subbuffer, then its host ptr is not allocated by itself,
we should not free it here. Otherwise, it may cause
some weird errors such as:
"corrupted double-linked list..".

Signed-off-by: Zhigang Gong <zhigang.gong at intel.com>
---
 src/cl_mem.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/cl_mem.c b/src/cl_mem.c
index 36ef2ce..9e57df4 100644
--- a/src/cl_mem.c
+++ b/src/cl_mem.c
@@ -1124,7 +1124,9 @@ cl_mem_delete(cl_mem mem)
     cl_buffer_unreference(mem->bo);
   }
 
-  if (mem->is_userptr && (mem->flags & CL_MEM_ALLOC_HOST_PTR))
+  if (mem->is_userptr &&
+      (mem->flags & CL_MEM_ALLOC_HOST_PTR) &&
+      (mem->type != CL_MEM_SUBBUFFER_TYPE))
     cl_free(mem->host_ptr);
 
   cl_free(mem);
-- 
1.8.3.2



More information about the Beignet mailing list