[Beignet] [PATCH] runtime: Fix a dangling pointer issue
Ruiling Song
ruiling.song at intel.com
Thu Oct 31 04:01:21 CET 2013
ctx->events points to the head of 'event list' under the ctx.
When deleting an event from the list, we should also update
the head pointer besides updating its neighbour's next & prev,
Signed-off-by: Ruiling Song <ruiling.song at intel.com>
---
src/cl_event.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/cl_event.c b/src/cl_event.c
index 212f1ee..1dc02ae 100644
--- a/src/cl_event.c
+++ b/src/cl_event.c
@@ -124,12 +124,15 @@ void cl_event_delete(cl_event event)
/* Remove it from the list */
assert(event->ctx);
pthread_mutex_lock(&event->ctx->event_lock);
- if (event->prev)
- event->prev->next = event->next;
- if (event->next)
- event->next->prev = event->prev;
- if (event->prev == NULL && event->next == NULL)
- event->ctx->events = NULL;
+
+ if (event->prev)
+ event->prev->next = event->next;
+ if (event->next)
+ event->next->prev = event->prev;
+ /* if this is the head, update head pointer ctx->events */
+ if (event->ctx->events == event)
+ event->ctx->events = event->next;
+
pthread_mutex_unlock(&event->ctx->event_lock);
cl_context_delete(event->ctx);
--
1.7.9.5
More information about the Beignet
mailing list