From f02bf908424a72e62ac4cd37fe1b37104854ae70 Mon Sep 17 00:00:00 2001 From: Steven Post Date: Mon, 18 Mar 2013 15:22:15 +0100 Subject: [PATCH] Close stream on exception --- core/src/main/java/hudson/Main.java | 49 ++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/hudson/Main.java b/core/src/main/java/hudson/Main.java index 45067f932b..a3dc3b00cb 100644 --- a/core/src/main/java/hudson/Main.java +++ b/core/src/main/java/hudson/Main.java @@ -138,23 +138,33 @@ public class Main { FileOutputStream os = new FileOutputStream(tmpFile); Writer w = new OutputStreamWriter(os,"UTF-8"); - w.write(""); - w.write(""); - w.flush(); + int ret; + try { + w.write(""); + w.write(""); + w.flush(); - // run the command - long start = System.currentTimeMillis(); + // run the command + long start = System.currentTimeMillis(); - List cmd = new ArrayList(); - for( int i=1; i cmd = new ArrayList(); + for( int i=1; i"+ret+""+(System.currentTimeMillis()-start)+""); - w.close(); + w.write(""+ret+""+(System.currentTimeMillis()-start)+""); + } + finally { + try { + w.close(); + } + catch (IOException ioe) { + // swallow exception + } + } String location = home+"job/"+projectNameEnc+"/postBuildResult"; while(true) { @@ -171,8 +181,17 @@ public class Main { con.connect(); // send the data FileInputStream in = new FileInputStream(tmpFile); - Util.copyStream(in,con.getOutputStream()); - in.close(); + try { + Util.copyStream(in,con.getOutputStream()); + } + finally { + try { + in.close(); + } + catch (IOException ioe) { + // swallow exception + } + } if(con.getResponseCode()!=200) { Util.copyStream(con.getErrorStream(),System.err);