CoverityFix-CID:1395104 Resource leak on an exceptional path 66/20466/2
Nimish Kapoor [Tue, 21 Aug 2018 08:39:30 +0000 (13:39 +0530)]
Change-Id: I50e9e908bca9984ae2574ac4db0418a72805fd6c

scilab/modules/helptools/src/java/org/scilab/modules/helptools/source/ScilabSourceBrowser.java

index 8a320b4..f9b40cb 100644 (file)
@@ -62,21 +62,27 @@ public class ScilabSourceBrowser extends HTMLScilabCodeHandler {
     public void generateSource() {
         new FirstPass().getMacroUsage();
         for (String file : files) {
+            Reader input = null;
             try {
                 File f = new File(file);
                 System.out.println(f);
-                Reader input = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
+                input = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
                 currentCommand = f.getName().split("\\.")[0];
                 buffer = new OutputStreamWriter(new FileOutputStream(outputDirectory + File.separator + currentCommand + ".html"), "UTF-8");
                 buffer.append(entete);
                 buffer.append("<div style=\"code\"><pre>");
                 scilabLexer.convert(this, input, false);
                 buffer.append("</pre></div>\n</body>\n</html>");
-                ((Writer) buffer).flush();
-                ((Writer) buffer).close();
-                input.close();
             } catch (IOException e) {
                 e.printStackTrace();
+            } finally {
+                try {
+                    ((Writer) buffer).flush();
+                    ((Writer) buffer).close();
+                    input.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
             }
         }
     }