Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
Ensure file input stream are closed in both normal and error cases.
luccioman0806de8fdcb9
diff --git a/htroot/DictionaryLoader_p.java b/htroot/DictionaryLoader_p.javaindex 9b455abaf..3d1b3bfb8 100644--- a/htroot/DictionaryLoader_p.java+++ b/htroot/DictionaryLoader_p.java@@ -303,10 +303,20 @@ public class DictionaryLoader_p {}if (post.containsKey("syn0Activate")) {+ FileInputStream inStream = null;try {- FileUtils.copy(new FileInputStream(synonym_de_default), synonym_de_production);+ inStream = new FileInputStream(synonym_de_default);+ FileUtils.copy(inStream, synonym_de_production);} catch (IOException e) {ConcurrentLog.logException(e);+ } finally {+ if(inStream != null) {+ try {+ inStream.close();+ } catch (IOException ignored) {+ ConcurrentLog.warn("DictionaryLoader", "Could not close file " + synonym_de_default.getName());+ }+ }}SynonymLibrary.init(synonyms_path);}diff --git a/source/net/yacy/http/servlets/YaCyDefaultServlet.java b/source/net/yacy/http/servlets/YaCyDefaultServlet.javaindex 16eab41a4..cf2aa2b39 100644--- a/source/net/yacy/http/servlets/YaCyDefaultServlet.java+++ b/source/net/yacy/http/servlets/YaCyDefaultServlet.java@@ -1105,11 +1105,25 @@ public class YaCyDefaultServlet extends HttpServlet {response.setContentType(mimeType);response.setStatus(HttpServletResponse.SC_OK);ByteArrayOutputStream bas = new ByteArrayOutputStream(4096);- // apply templates- TemplateEngine.writeTemplate(targetFile.getName(), fis, bas, templatePatterns);- fis.close();- // handle SSI- parseSSI (bas.toByteArray(),request,response);+ try {+ // apply templates+ TemplateEngine.writeTemplate(targetFile.getName(), fis, bas, templatePatterns);++ // handle SSI+ parseSSI (bas.toByteArray(),request,response);+ } finally {+ try {+ fis.close();+ } catch(IOException ignored) {+ ConcurrentLog.warn("FILEHANDLER", "YaCyDefaultServlet: could not close target file " + targetFile.getName());+ }++ try {+ bas.close();+ } catch(IOException ignored) {+ /* Should never happen with a ByteArrayOutputStream */+ }+ }}}}