From 4bc450ef5f7544d9918d0f560e7b5f4356ae1b81 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Thu, 7 Jan 2021 06:52:57 +0000 Subject: Properly close file handles in extractors and when handling password-protected files git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1885229 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/ooxml') diff --git a/src/ooxml/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java b/src/ooxml/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java index 2d90b46f20..8cad08609d 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java +++ b/src/ooxml/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java @@ -240,8 +240,6 @@ public final class POIXMLExtractorFactory implements ExtractorProvider { } return null; - } catch (IOException e) { - throw e; } catch (Error | RuntimeException | XmlException | OpenXML4JException e) { // NOSONAR throw new IOException(e); } @@ -271,6 +269,13 @@ public final class POIXMLExtractorFactory implements ExtractorProvider { } try (InputStream is = dec.getDataStream(poifsDir)) { return create(is, password); + } finally { + // we should close the underlying file-system as all information + // is read now and we should make sure that resources are freed + POIFSFileSystem fs = poifsDir.getFileSystem(); + if (fs != null) { + fs.close(); + } } } catch (IOException | RuntimeException e) { throw e; -- cgit v1.2.3