tmf: Fix potential resource leaks in the GSS
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 27 Apr 2012 17:10:48 +0000 (13:10 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 27 Apr 2012 17:13:25 +0000 (13:13 -0400)
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/stateprovider/StateSystemFullHistoryTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/StateHistorySystem.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/backend/historytree/HistoryTree.java

index 54729edb8af8363d9d63d01844b1019985a4de01..66faffc321dde32319dffdf17cc952c9ae30f956 100644 (file)
@@ -375,6 +375,8 @@ public class StateSystemFullHistoryTest {
 
     @Test
     public void testDebugPrinting() throws FileNotFoundException {
-        shs.debugPrint(new PrintWriter(new File("/dev/null")));
+        PrintWriter pw = new PrintWriter(new File("/dev/null"));
+        shs.debugPrint(pw);
+        pw.close();
     }
 }
index 065225376b1cb40d16b551743bdb2b07c8156600..e4ddadde171906088e545e790dd31625f08cc1dd 100644 (file)
@@ -73,6 +73,7 @@ public class StateHistorySystem extends StateSystem {
             FileInputStream attributeTreeInput = backend.supplyAttributeTreeReader();
             this.attributeTree = new AttributeTree(this, attributeTreeInput);
             transState.setInactive();
+            attributeTreeInput.close();
         }
     }
 
index eb2ff3ba2fe813a96f3c49ba42fc2e2206ede429..608b3bb358e20fe32f3f4be07c80caa12532da78 100644 (file)
@@ -136,12 +136,16 @@ class HistoryTree {
          */
         res = buffer.getInt();
         if (res != HISTORY_FILE_MAGIC_NUMBER) {
+            fc.close();
+            fis.close();
             throw new IOException(
                     "Selected file does not look like a History Tree file"); //$NON-NLS-1$
         }
 
         res = buffer.getInt(); /* Major version number */
         if (res != MAJOR_VERSION) {
+            fc.close();
+            fis.close();
             throw new IOException("Select History Tree file is of an older " //$NON-NLS-1$
                     + "format. Please use a previous version of " //$NON-NLS-1$
                     + "the parser to open it."); //$NON-NLS-1$
@@ -169,6 +173,7 @@ class HistoryTree {
         ts = buffer.getLong();
 
         this.config = new HTConfig(existingStateFile, bs, maxc, ts);
+        fc.close();
         fis.close();
         /*
          * FIXME We close fis here and the TreeIO will then reopen the same
@@ -231,8 +236,14 @@ class HistoryTree {
             /* done writing the file header */
 
         } catch (IOException e) {
-            /* We should have any problems at this point... */
+            /* We should not have any problems at this point... */
             e.printStackTrace();
+        } finally {
+            try {
+                fc.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
         }
         return;
     }
This page took 0.038093 seconds and 5 git commands to generate.