aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
diff options
context:
space:
mode:
authorGravatar lberki <lberki@google.com>2017-07-25 15:36:23 +0200
committerGravatar Jakob Buchgraber <buchgr@google.com>2017-07-26 10:34:51 +0200
commit3edde6fe2ecc1471b1611fbe54fe446443a30855 (patch)
treebfa4bd790c19d18f459bc7f2d62b7f1c7ec41dee /src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
parentef5c35b5c015d50226956ebd519144fa873f02d3 (diff)
Close the ZipFileSystem and the underlying ZipFile appropriately after we finished extracting the FDO profile.
Also fix a truly embarrassing infinite recursion bug introduced by Yours Truly in unknown commit . This avoids a failure mode where, when two profiles at the same path are used in two builds close one after the other, the file handle would get erroneously re-used. RELNOTES: None. PiperOrigin-RevId: 163063976
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();
}
}