Skip to content

Commit

Permalink
[SYCL][ClangLinkerWrapper] Fix read of invalid memory (#15472)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
sarnex authored Sep 25, 2024
1 parent 68e03e8 commit 30578ba
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1471,8 +1471,12 @@ Error extractBundledObjects(StringRef Filename, const ArgList &Args,
llvm::MemoryBuffer::getFileOrSTDIN(*UnbundledFile, /*isText=*/true);
if (std::error_code EC = ObjList.getError())
return createFileError(*UnbundledFile, EC);
(*ObjList)->getBuffer().split(ObjectFilePaths, '\n', /*MaxSplit=*/-1,
/*KeepEmpty=*/false);
// Create a copy of the list we can reference even after we close
// the file.
StringRef UnbundledArchiveList =
Args.MakeArgString((*ObjList)->getBuffer());
UnbundledArchiveList.split(ObjectFilePaths, '\n', /*MaxSplit=*/-1,
/*KeepEmpty=*/false);
} else {
ObjectFilePaths.push_back(*UnbundledFile);
}
Expand Down

0 comments on commit 30578ba

Please sign in to comment.