Skip to content

Commit 30578ba

Browse files
authored
[SYCL][ClangLinkerWrapper] Fix read of invalid memory (#15472)
The problem was the buffer gets freed when we go out of the `if` because the `unique_ptr` is created there, so just make a copy that will stay alive as long as we need it. Confirmed fix with valgrind. This is already tested by `sycl/test-e2e/NewOffloadDriver/multisource.cpp` and it fails sporadically which led me to this fix. Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
1 parent 68e03e8 commit 30578ba

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,8 +1471,12 @@ Error extractBundledObjects(StringRef Filename, const ArgList &Args,
14711471
llvm::MemoryBuffer::getFileOrSTDIN(*UnbundledFile, /*isText=*/true);
14721472
if (std::error_code EC = ObjList.getError())
14731473
return createFileError(*UnbundledFile, EC);
1474-
(*ObjList)->getBuffer().split(ObjectFilePaths, '\n', /*MaxSplit=*/-1,
1475-
/*KeepEmpty=*/false);
1474+
// Create a copy of the list we can reference even after we close
1475+
// the file.
1476+
StringRef UnbundledArchiveList =
1477+
Args.MakeArgString((*ObjList)->getBuffer());
1478+
UnbundledArchiveList.split(ObjectFilePaths, '\n', /*MaxSplit=*/-1,
1479+
/*KeepEmpty=*/false);
14761480
} else {
14771481
ObjectFilePaths.push_back(*UnbundledFile);
14781482
}

0 commit comments

Comments
 (0)