Skip to content

[UR][L0] Possible memory leak in ur_buffer::getBufferZeHandle #18265

Open
@AlexeySachkov

Description

@AlexeySachkov

There are many other places in the function which have the same issue, but I will use the following snippet to illustrate it:

ur_ze_event_list_t waitlist;
waitlist.ZeEventList = nullptr;
waitlist.Length = 0;
uint32_t EventListIndex = 0;
for (unsigned i = 0; i < numWaitEvents; ++i) {
if (phWaitEvents[i]->HostVisibleEvent) {
ZE2UR_CALL(zeEventHostSynchronize,
(phWaitEvents[i]->ZeEvent, UINT64_MAX));
} else {
// Generate the waitlist for the Copy calls based on the passed in
// dependencies, if they exist for device only.
if (waitlist.ZeEventList == nullptr) {
waitlist.ZeEventList = new ze_event_handle_t[numWaitEvents];
}
waitlist.ZeEventList[EventListIndex] = phWaitEvents[i]->ZeEvent;
waitlist.Length++;
EventListIndex++;
}
}
if (waitlist.Length > 0) {
ZE2UR_CALL(zeCommandListAppendWaitOnEvents,
(UrContext->ZeCommandListInit, waitlist.Length,
waitlist.ZeEventList));
}

The problem is that every time we do ZE2UR_CALL, it may do plain return from the function if error is encountered. If that happens, memory allocated in waitlist.ZeEventList is not deallocated.

This issue was discovered by the Coverity, its CID is 520798

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglevel-zeroIssues related to the Level Zero backendunified-runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions