ResolveMerger: Destroy TemporaryBuffer on unchecked exceptions

Previously, we called destroy() to delete the temp file on failure only
when catching an IOException, not a RuntimeException. Use a slightly
different construction with a finally block to ensure it's always
deleted on error (assuming the JVM is still healthy enough).

Change-Id: Ie201f3cfc81099ee1cafed066632da76223cef1f
This commit is contained in:
Dave Borowitz 2019-03-01 12:35:38 -08:00
parent 875dccf33c
commit ea54b6a5a7
1 changed files with 6 additions and 3 deletions

View File

@ -1024,13 +1024,16 @@ private TemporaryBuffer doMerge(MergeResult<RawText> result)
throws IOException {
TemporaryBuffer.LocalFile buf = new TemporaryBuffer.LocalFile(
db != null ? nonNullRepo().getDirectory() : null, inCoreLimit);
boolean success = false;
try {
new MergeFormatter().formatMerge(buf, result,
Arrays.asList(commitNames), UTF_8);
buf.close();
} catch (IOException e) {
buf.destroy();
throw e;
success = true;
} finally {
if (!success) {
buf.destroy();
}
}
return buf;
}