From 5259996c44b849fffbe8b9fcdff73ca43d1fb94a Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Sun, 26 Oct 2014 09:40:51 +0300 Subject: [PATCH] [CID-1219446] - Resource leak in ClassicPluginStrategy Resource leak may happen during the search of manifest file. Signed-off-by: Oleg Nenashev --- .../java/hudson/ClassicPluginStrategy.java | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/hudson/ClassicPluginStrategy.java b/core/src/main/java/hudson/ClassicPluginStrategy.java index 2db5c8c1ec..75d1414acc 100644 --- a/core/src/main/java/hudson/ClassicPluginStrategy.java +++ b/core/src/main/java/hudson/ClassicPluginStrategy.java @@ -116,22 +116,32 @@ public class ClassicPluginStrategy implements PluginStrategy { } private static Manifest loadLinkedManifest(File archive) throws IOException { - // resolve the .hpl file to the location of the manifest file - final String firstLine = IOUtils.readFirstLine(new FileInputStream(archive), "UTF-8"); - if (firstLine.startsWith("Manifest-Version:")) { - // this is the manifest already - } else { - // indirection - archive = resolve(archive, firstLine); - } - // then parse manifest - FileInputStream in = new FileInputStream(archive); + // resolve the .hpl file to the location of the manifest file try { - return new Manifest(in); + // Locate the manifest + String firstLine; + FileInputStream manifestHeaderInput = new FileInputStream(archive); + try { + firstLine = IOUtils.readFirstLine(manifestHeaderInput, "UTF-8"); + } finally { + manifestHeaderInput.close(); + } + if (firstLine.startsWith("Manifest-Version:")) { + // this is the manifest already + } else { + // indirection + archive = resolve(archive, firstLine); + } + + // Read the manifest + FileInputStream manifestInput = new FileInputStream(archive); + try { + return new Manifest(manifestInput); + } finally { + manifestInput.close(); + } } catch (IOException e) { throw new IOException("Failed to load " + archive, e); - } finally { - in.close(); } }