File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -4371,8 +4371,21 @@ pi_result piEventRelease(pi_event Event) {
4371
4371
die (" piEventRelease: called on a destroyed event" );
4372
4372
}
4373
4373
4374
+ // The event is no longer needed upstream, but we have to wait for its
4375
+ // completion in order to do proper cleanup. Otherwise refcount may still be
4376
+ // non-zero in the check below and we will get event leak.
4377
+ //
4378
+ // TODO: in case this potentially "early" wait causes performance problems,
4379
+ // e.g. due to closing a batch too early, or blocking the host for no good
4380
+ // reason, then we should look into moving the wait down to queue release
4381
+ // (will need to remember all events in the queue for that).
4382
+ //
4383
+ if (!Event->CleanedUp )
4384
+ PI_CALL (piEventsWait (1 , &Event));
4385
+
4374
4386
if (--(Event->RefCount ) == 0 ) {
4375
- cleanupAfterEvent (Event);
4387
+ if (!Event->CleanedUp )
4388
+ cleanupAfterEvent (Event);
4376
4389
4377
4390
if (Event->CommandType == PI_COMMAND_TYPE_MEM_BUFFER_UNMAP &&
4378
4391
Event->CommandData ) {
You can’t perform that action at this time.
0 commit comments