Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.apache.taverna.scufl2.ucfpackage.impl.odfdom.pkg.OdfPackage.java is leaking resources #6

Open
yasushiSap opened this issue May 20, 2021 · 0 comments

Comments

@yasushiSap
Copy link

method private void initialize(File odfFile) is not close ZipHelper mZipFile (is ZipHelper).
mZipFile.close (); should be called before the method exits.

// Initialize using temporary directory on hard disc
private void initialize(File odfFile) throws Exception {
	mBaseURI = getBaseURIFromFile(odfFile);

	if (mTempDirParent == null) {
		/*
		 * getParentFile() returns already java.io.tmpdir when package is an
		 * odfStream
		 */
		mTempDirParent = odfFile.getAbsoluteFile().getParentFile();
		if (!mTempDirParent.canWrite())
			mTempDirParent = null; // java.io.tmpdir will be used implicitly
	}

	try {
		mZipFile = new ZipHelper(new ZipFile(odfFile));
	} catch (Exception e) {
		if (odfFile.length() < 3)
			throw new IllegalArgumentException("The empty file '"
					+ odfFile.getPath() + "' is no ODF package!", e);
		throw new IllegalArgumentException("Could not unzip the file "
				+ odfFile.getPath(), e);
	}
	Enumeration<? extends ZipEntry> entries = mZipFile.entries();

	while (entries.hasMoreElements()) {
		ZipEntry zipEntry = entries.nextElement();
		mZipEntries.put(zipEntry.getName(), zipEntry);
		/*
		 * TODO: think about if the additional list mPackageEntries is
		 * necessary - shouldn't everything be part of one of the other
		 * lists? maybe keep this as "master", rename it?
		 */
		mPackageEntries.add(zipEntry.getName());
		if (zipEntry.getName().equals(
				OdfPackage.OdfFile.MEDIA_TYPE.getPath())) {
			ByteArrayOutputStream out = new ByteArrayOutputStream();
			StreamHelper.stream(mZipFile.getInputStream(zipEntry), out);
			try {
				mMediaType = new String(out.toByteArray(), 0, out.size(),
						"UTF-8");
			} catch (UnsupportedEncodingException ex) {
				mLog.log(Level.SEVERE, null, ex);
			}
		}
	}
	mZipFile.close();// <-- add this line
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant