From eb3c1611807e4461a5fc1a2880f1533dbdbe7167 Mon Sep 17 00:00:00 2001 From: Score_Under Date: Sat, 25 Feb 2012 17:39:54 +0000 Subject: [Bleeding] Fixed file handle leak in /timings command. Addresses BUKKIT-853 --- .../java/org/bukkit/command/defaults/TimingsCommand.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/command/defaults/TimingsCommand.java b/src/main/java/org/bukkit/command/defaults/TimingsCommand.java index f4da879b..9e5b6769 100644 --- a/src/main/java/org/bukkit/command/defaults/TimingsCommand.java +++ b/src/main/java/org/bukkit/command/defaults/TimingsCommand.java @@ -53,9 +53,10 @@ public class TimingsCommand extends Command { File timings = new File(timingFolder, "timings.txt"); File names = null; while (timings.exists()) timings = new File(timingFolder, "timings" + (++index) + ".txt"); + PrintStream fileTimings = null; + PrintStream fileNames = null; try { - PrintStream fileTimings = new PrintStream(timings); - PrintStream fileNames = null; + fileTimings = new PrintStream(timings); if (separate) { names = new File(timingFolder, "names" + index + ".txt"); fileNames = new PrintStream(names); @@ -87,6 +88,13 @@ public class TimingsCommand extends Command { sender.sendMessage("Timings written to " + timings.getPath()); if (separate) sender.sendMessage("Names written to " + names.getPath()); } catch (IOException e) { + } finally { + if (fileTimings != null) { + fileTimings.close(); + } + if (fileNames != null) { + fileNames.close(); + } } } return true; -- cgit v1.2.3