aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
index f763749b95..180d687f87 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
@@ -354,20 +354,24 @@ public class FdoSupport {
FileSystemUtils.ensureSymbolicLink(
execRoot.getRelative(getAutoProfilePath(fdoProfile, fdoRootExecPath)), fdoProfile);
} else {
- Path zipFilePath = new ZipFileSystem(fdoProfile).getRootDirectory();
- String outputSymlinkName = productName + "-out";
- if (!zipFilePath.getRelative(outputSymlinkName).isDirectory()) {
- throw new ZipException(
- "FDO zip files must be zipped directly above '"
- + outputSymlinkName
- + "' for the compiler to find the profile");
+ // Path objects referring to inside the zip file are only valid within this try block.
+ // FdoZipContents doesn't reference any of them, so we are fine.
+ try (ZipFileSystem zipFileSystem = new ZipFileSystem(fdoProfile)) {
+ Path zipFilePath = zipFileSystem.getRootDirectory();
+ String outputSymlinkName = productName + "-out";
+ if (!zipFilePath.getRelative(outputSymlinkName).isDirectory()) {
+ throw new ZipException(
+ "FDO zip files must be zipped directly above '"
+ + outputSymlinkName
+ + "' for the compiler to find the profile");
+ }
+ ImmutableSet.Builder<PathFragment> gcdaFilesBuilder = ImmutableSet.builder();
+ ImmutableMultimap.Builder<PathFragment, PathFragment> importsBuilder =
+ ImmutableMultimap.builder();
+ extractFdoZipDirectory(zipFilePath, fdoDirPath, gcdaFilesBuilder, importsBuilder);
+ gcdaFiles = gcdaFilesBuilder.build();
+ imports = importsBuilder.build();
}
- ImmutableSet.Builder<PathFragment> gcdaFilesBuilder = ImmutableSet.builder();
- ImmutableMultimap.Builder<PathFragment, PathFragment> importsBuilder =
- ImmutableMultimap.builder();
- extractFdoZipDirectory(zipFilePath, fdoDirPath, gcdaFilesBuilder, importsBuilder);
- gcdaFiles = gcdaFilesBuilder.build();
- imports = importsBuilder.build();
}
}