@@ -4300,12 +4300,12 @@ pi_result piProgramBuild(pi_program Program, pi_uint32 NumDevices,
4300
4300
ZE_CALL_NOCHECK (zeModuleCreate, (ZeContext, ZeDevice, &ZeModuleDesc,
4301
4301
&ZeModule, &Program->ZeBuildLog ));
4302
4302
if (ZeResult != ZE_RESULT_SUCCESS) {
4303
- // We need to clear Program state to avoid double destroy of zeModule in
4304
- // case where SYCL RT calls piProgramRelease().
4305
- // We should not return with an error code here due to the comments below.
4303
+ // We adjust pi_program below to avoid attempting to release zeModule when
4304
+ // RT calls piProgramRelease().
4306
4305
Program->ZeModule = nullptr ;
4307
4306
Program->Code .reset ();
4308
4307
Program->State = _pi_program::Invalid;
4308
+ return mapError (ZeResult);
4309
4309
}
4310
4310
// The call to zeModuleCreate does not report an error if there are
4311
4311
// unresolved symbols because it thinks these could be resolved later via a
@@ -4314,9 +4314,9 @@ pi_result piProgramBuild(pi_program Program, pi_uint32 NumDevices,
4314
4314
// check now for unresolved symbols.
4315
4315
ZeResult = checkUnresolvedSymbols (ZeModule, &Program->ZeBuildLog );
4316
4316
if (ZeResult != ZE_RESULT_SUCCESS) {
4317
- // remove ZeModule that is associated with the failed program
4318
- ZE_CALL (zeModuleDestroy, (ZeModule));
4319
-
4317
+ // Note that the ZeModule is still allocated and will be released when
4318
+ // the user catch the exception that RT throws.
4319
+ // Otherwise, the user program crashes and memory leak is not a concern.
4320
4320
if (ZeResult == ZE_RESULT_ERROR_MODULE_LINK_FAILURE)
4321
4321
return PI_BUILD_PROGRAM_FAILURE;
4322
4322
return mapError (ZeResult);
0 commit comments