diff options
author | James Moger <james.moger@gitblit.com> | 2013-05-15 15:49:58 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2013-05-15 15:49:58 -0400 |
commit | df550007fe30a0f9ac0a650b8587932848e70d33 (patch) | |
tree | 05e4b38a29d231f832fc233c8ca5b1e8b5792929 /src | |
parent | d8aa8d69ba21d7846a72d51810a9f89f032a5ecb (diff) | |
download | gitblit-df550007fe30a0f9ac0a650b8587932848e70d33.tar.gz gitblit-df550007fe30a0f9ac0a650b8587932848e70d33.zip |
Close file descriptor leak (issue-199)
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/gitblit/GitBlit.java | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java index 93293d85..f017d218 100644 --- a/src/main/java/com/gitblit/GitBlit.java +++ b/src/main/java/com/gitblit/GitBlit.java @@ -3509,6 +3509,8 @@ public class GitBlit implements ServletContextListener { // extract the resource to the directory if it does not exist
File f = new File(toDir, resource.substring(path.length()));
if (!f.exists()) {
+ InputStream is = null; + OutputStream os = null; try {
if (resource.charAt(resource.length() - 1) == '/') {
// directory
@@ -3517,20 +3519,33 @@ public class GitBlit implements ServletContextListener { } else {
// file
f.getParentFile().mkdirs();
- InputStream is = context.getResourceAsStream(resource);
- OutputStream os = new FileOutputStream(f);
+ is = context.getResourceAsStream(resource); + os = new FileOutputStream(f); byte [] buffer = new byte[4096];
int len = 0;
while ((len = is.read(buffer)) > -1) {
os.write(buffer, 0, len);
}
- is.close();
- os.close();
}
} catch (FileNotFoundException e) {
logger.error("Failed to find resource \"" + resource + "\"", e);
} catch (IOException e) {
logger.error("Failed to copy resource \"" + resource + "\" to " + f, e);
+ } finally { + if (is != null) { + try { + is.close(); + } catch (IOException e) { + // ignore + } + } + if (os != null) { + try { + os.close(); + } catch (IOException e) { + // ignore + } + } }
}
}
|