]> WPIA git - gigi.git/commitdiff
Fix: more coverity resource leak
authorFelix Dörre <felix@dogcraft.de>
Thu, 19 Feb 2015 23:06:53 +0000 (00:06 +0100)
committerFelix Dörre <felix@dogcraft.de>
Thu, 19 Feb 2015 23:06:53 +0000 (00:06 +0100)
tests/org/cacert/gigi/testUtils/ConfiguredTest.java
tests/org/cacert/gigi/testUtils/IOUtils.java
tests/org/cacert/gigi/util/TestPublicSuffixes.java

index 207aa006e2cc3f85b77d30eccb0d32a7545680a4..f8098ed8f0da886944600f118fd7e1551e1ee55e 100644 (file)
@@ -42,7 +42,9 @@ public abstract class ConfiguredTest {
             return;
         }
         envInited = true;
-        testProps.load(new FileInputStream("config/test.properties"));
+        try (FileInputStream inStream = new FileInputStream("config/test.properties")) {
+            testProps.load(inStream);
+        }
         if ( !DatabaseConnection.isInited()) {
             DatabaseConnection.init(testProps);
         }
index 9a01a542d056ee1577cfc9eefd59c4b75b351ad8..3e91d7ed2ea4f4d7b04a30286f03682acde5ef19 100644 (file)
@@ -38,6 +38,7 @@ public class IOUtils {
             while ((len = in.read(buffer)) > 0) {
                 caw.write(buffer, 0, len);
             }
+            in.close();
             return new String(caw.toCharArray());
         } catch (IOException e) {
             throw new Error(e);
@@ -53,6 +54,7 @@ public class IOUtils {
             while ((len = in.read(buffer)) > 0) {
                 baos.write(buffer, 0, len);
             }
+            in.close();
             return baos.toByteArray();
         } catch (IOException e) {
             throw new Error(e);
index dba88303a827296b1593d93ff2477d92d623624d..950224154004a111a326092bf02d9d1179a245ac 100644 (file)
@@ -24,29 +24,35 @@ public class TestPublicSuffixes {
      */
     @Parameters(name = "publicSuffix({0}) = {1}")
     public static Iterable<String[]> genParams() throws IOException {
-        BufferedReader br = new BufferedReader(new InputStreamReader(TestPublicSuffixes.class.getResourceAsStream("TestPublicSuffixes.txt"), "UTF-8"));
-        ArrayList<String[]> result = new ArrayList<>();
-        String line;
-        while ((line = br.readLine()) != null) {
-            if (line.startsWith("//") || line.isEmpty()) {
-                continue;
-            }
-            String parseSuffix = "checkPublicSuffix(";
-            if (line.startsWith(parseSuffix)) {
-                String data = line.substring(parseSuffix.length(), line.length() - 2);
-                String[] parts = data.split(", ");
-                if (parts.length != 2) {
-                    throw new Error("Syntax error in public suffix test data file: " + line);
+        BufferedReader br = null;
+        try {
+            br = new BufferedReader(new InputStreamReader(TestPublicSuffixes.class.getResourceAsStream("TestPublicSuffixes.txt"), "UTF-8"));
+            ArrayList<String[]> result = new ArrayList<>();
+            String line;
+            while ((line = br.readLine()) != null) {
+                if (line.startsWith("//") || line.isEmpty()) {
+                    continue;
+                }
+                String parseSuffix = "checkPublicSuffix(";
+                if (line.startsWith(parseSuffix)) {
+                    String data = line.substring(parseSuffix.length(), line.length() - 2);
+                    String[] parts = data.split(", ");
+                    if (parts.length != 2) {
+                        throw new Error("Syntax error in public suffix test data file: " + line);
+                    }
+                    result.add(new String[] {
+                            parse(parts[0]), parse(parts[1])
+                    });
+                } else {
+                    throw new Error("Unparsable line: " + line);
                 }
-                result.add(new String[] {
-                        parse(parts[0]), parse(parts[1])
-                });
-            } else {
-                throw new Error("Unparsable line: " + line);
+            }
+            return result;
+        } finally {
+            if (br != null) {
+                br.close();
             }
         }
-
-        return result;
     }
 
     private static String parse(String data) {