]> source.dussan.org Git - poi.git/commitdiff
bug 59893: close open resources to prevent leaks
authorJaven O'Neal <onealj@apache.org>
Fri, 17 Feb 2017 09:53:49 +0000 (09:53 +0000)
committerJaven O'Neal <onealj@apache.org>
Fri, 17 Feb 2017 09:53:49 +0000 (09:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1783362 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/poifs/crypt/TestDecryptor.java
src/ooxml/testcases/org/apache/poi/poifs/crypt/TestEncryptor.java
src/testcases/org/apache/poi/poifs/filesystem/ReaderWriter.java

index 4ccd0b1aeb01818798df06893ad02b485b8408bc..c6c8f959e778ec79c7790598da1966d05b7df96f 100644 (file)
@@ -165,11 +165,14 @@ public class TestDecryptor {
 
     @Test
     public void test58616() throws IOException, GeneralSecurityException {
-        POIFSFileSystem pfs = new POIFSFileSystem(new FileInputStream(XSSFTestDataSamples.getSampleFile("58616.xlsx")));                
+        FileInputStream fis = new FileInputStream(XSSFTestDataSamples.getSampleFile("58616.xlsx"));                
+        POIFSFileSystem pfs = new POIFSFileSystem(fis);                
         EncryptionInfo info = new EncryptionInfo(pfs);             
         Decryptor dec = Decryptor.getInstance(info);   
         //dec.verifyPassword(null);
         dec.getDataStream(pfs);
+        pfs.close();
+        fis.close();
     }
 
     @Test
index d31a58a334b7dcad358d8bcbfde396a0af11e7ac..2e95fa59d3a987a06ebde63ca7c9f7f5746a1cef 100644 (file)
@@ -151,7 +151,8 @@ public class TestEncryptor {
 
         ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
         fs.writeFilesystem(bos);
-        
+        fs.close();
+
         nfs = new NPOIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()));
         infoActual = new EncryptionInfo(nfs.getRoot());
         Decryptor decActual = Decryptor.getInstance(infoActual);
@@ -297,11 +298,13 @@ public class TestEncryptor {
         enc.confirmPassword("password");
         OutputStream os = enc.getDataStream(fs);
         pkg.save(os);
+        os.close();
         pkg.revert();
         
         // Save the resulting OLE2 document, and re-open it
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         fs.writeFilesystem(baos);
+        fs.close();
         
         ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
         NPOIFSFileSystem inpFS = new NPOIFSFileSystem(bais);
@@ -318,6 +321,9 @@ public class TestEncryptor {
         assertNotNull(inpPkg.getPackageProperties());
         assertNotNull(inpPkg.getPackageProperties().getLanguageProperty());
         assertNull(inpPkg.getPackageProperties().getLanguageProperty().getValue());
+
+        inpPkg.close();
+        inpFS.close();
     }
     
     @Test
@@ -340,7 +346,8 @@ public class TestEncryptor {
         assertTrue(b);
 
         // do some strange things with it ;)
-        XWPFDocument docx = new XWPFDocument(d.getDataStream(fs));
+        InputStream docIS = d.getDataStream(fs);
+        XWPFDocument docx = new XWPFDocument(docIS);
         docx.getParagraphArray(0).insertNewRun(0).setText("POI was here! All your base are belong to us!");
         docx.getParagraphArray(0).insertNewRun(1).addBreak();
 
@@ -348,6 +355,8 @@ public class TestEncryptor {
         Encryptor e = encInfo.getEncryptor();
         e.confirmPassword("AYBABTU");
         docx.write(e.getDataStream(fs));
+        docx.close();
+        docIS.close();
         
         docx.close();
         fs.close();
index b3a328c9efeeff8a901a3d704790c9ad337021dc..2aae3729dc6c4032281a9350f2ff7d6986ada216 100644 (file)
@@ -44,7 +44,7 @@ public class ReaderWriter
     private final DirectoryEntry  root;
 
     // keys are DocumentDescriptors, values are byte[]s
-    private final Map<DocumentDescriptor, byte[]>             dataMap;
+    private final Map<DocumentDescriptor, byte[]> dataMap;
 
     /**
      * Constructor ReaderWriter
@@ -93,6 +93,8 @@ public class ReaderWriter
 
             filesystem.writeFilesystem(ostream);
             ostream.close();
+
+            filesystem.close();
         }
     }