From ea54b6a5a7305a9b68fd7bbca45f919ba978a934 Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Fri, 1 Mar 2019 12:35:38 -0800 Subject: [PATCH] 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 --- .../src/org/eclipse/jgit/merge/ResolveMerger.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java index 412d9bba73..9ea1868ebb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java @@ -1024,13 +1024,16 @@ public class ResolveMerger extends ThreeWayMerger { 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; } -- 2.39.5