From 707a9ae51ba44f7c25139c511f817c3213c394a2 Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Thu, 2 Jun 2016 14:31:11 -0700 Subject: [PATCH] Fix resource leaks in the testing framework Reviewed By: peterogithub Differential Revision: D3381503 fbshipit-source-id: 6513ebd --- infer/tests/build_systems/expected_outputs/buck_report.json | 5 ----- infer/tests/utils/matchers/DotFilesEqual.java | 5 ++++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/infer/tests/build_systems/expected_outputs/buck_report.json b/infer/tests/build_systems/expected_outputs/buck_report.json index fb40efc16..e78ddf12d 100644 --- a/infer/tests/build_systems/expected_outputs/buck_report.json +++ b/infer/tests/build_systems/expected_outputs/buck_report.json @@ -494,11 +494,6 @@ "file": "infer/tests/codetoanalyze/java/infer/CursorLeaks.java", "procedure": "void CursorLeaks.loadPrefsFromContentProviderNotClosed()" }, - { - "bug_type": "RESOURCE_LEAK", - "file": "infer/tests/utils/matchers/DotFilesEqual.java", - "procedure": "boolean DotFilesEqual.matches(Object)" - }, { "bug_type": "RESOURCE_LEAK", "file": "infer/tests/codetoanalyze/java/infer/ResourceLeaks.java", diff --git a/infer/tests/utils/matchers/DotFilesEqual.java b/infer/tests/utils/matchers/DotFilesEqual.java index 63f8f9bc8..c9031650c 100644 --- a/infer/tests/utils/matchers/DotFilesEqual.java +++ b/infer/tests/utils/matchers/DotFilesEqual.java @@ -38,8 +38,9 @@ public class DotFilesEqual extends BaseMatcher { } else { diffCommand = "diff -u " + dotFile + " " + newDotFile.getAbsolutePath(); } + Process diff_process = null; try { - Process diff_process = Runtime.getRuntime().exec(diffCommand); + diff_process = Runtime.getRuntime().exec(diffCommand); try (BufferedReader inputReader = new BufferedReader(new InputStreamReader(diff_process.getInputStream())); BufferedReader errorReader = @@ -64,6 +65,8 @@ public class DotFilesEqual extends BaseMatcher { } catch (Exception e) { e.printStackTrace(); return false; + } finally { + if (diff_process != null) diff_process.destroy(); } }