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

Guo, Yejun yejun.guo at intel.com
Fri Feb 6 06:59:46 PST 2015


Nice catch, LGTM, thanks.

-----Original Message-----
From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of Zhigang Gong
Sent: Friday, February 06, 2015 5:53 PM
To: beignet at lists.freedesktop.org
Cc: Gong, Zhigang
Subject: [Beignet] [PATCH] runtime: don't free the host_ptr for a subbuffer.

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

_______________________________________________
Beignet mailing list
Beignet at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list