summaryrefslogtreecommitdiffstats
path: root/luni/src/main
diff options
context:
space:
mode:
authorPaul Duffin <paulduffin@google.com>2014-02-28 16:43:15 +0000
committerPaul Duffin <paulduffin@google.com>2014-05-01 16:06:57 +0100
commita6f350c645dbb66d68cc2b03afb8f2eeaa88fbba (patch)
tree3625ee2813edb10bdb706e263408f744a16cccbd /luni/src/main
parent8ccb6f5b798aa991cccf7bba6ddb21ee8affecac (diff)
downloadlibcore-a6f350c645dbb66d68cc2b03afb8f2eeaa88fbba.zip
libcore-a6f350c645dbb66d68cc2b03afb8f2eeaa88fbba.tar.gz
libcore-a6f350c645dbb66d68cc2b03afb8f2eeaa88fbba.tar.bz2
Improve detection of CloseGuard protected resource leakage
* Add CloseGuardMonitor to intercept and collate CloseGuard reports and if necessary throw an exception listing the resource leaks. * Add ResourceLeakageDetector to abstract away the CloseGuardMonitor which will not work on RI. * Add AbstractResourceLeakageDetectorTestCase as a base class for tests that need to detect resource leaks, in future this could be handled by modifications to Cts and Vogar test runners. * Remove CloseGuardTester and its sole usage in ProcessBuilderTest. * Remove CloseGuardGuard from within URLConnectionTest * Change ZipFileTest, ProcessBuilderTest, URLConnectionTest to use new mechanism, fix issues that are identified and do some cleanup/remove duplicated code. Bug: https://code.google.com/p/android/issues/detail?id=66383 Change-Id: Id026dbb6bc66091a15f07329e6371cd0d1f32cf5
Diffstat (limited to 'luni/src/main')
-rw-r--r--luni/src/main/java/java/util/zip/ZipFile.java15
1 files changed, 14 insertions, 1 deletions
diff --git a/luni/src/main/java/java/util/zip/ZipFile.java b/luni/src/main/java/java/util/zip/ZipFile.java
index 4b3e431..43e8567 100644
--- a/luni/src/main/java/java/util/zip/ZipFile.java
+++ b/luni/src/main/java/java/util/zip/ZipFile.java
@@ -33,6 +33,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import libcore.io.BufferIterator;
import libcore.io.HeapBufferIterator;
+import libcore.io.IoUtils;
import libcore.io.Streams;
/**
@@ -199,7 +200,19 @@ public class ZipFile implements Closeable, ZipConstants {
raf = new RandomAccessFile(filename, "r");
- readCentralDir();
+ // Make sure to close the RandomAccessFile if reading the central directory fails.
+ boolean mustCloseFile = true;
+ try {
+ readCentralDir();
+
+ // Read succeeded so do not close the underlying RandomAccessFile.
+ mustCloseFile = false;
+ } finally {
+ if (mustCloseFile) {
+ IoUtils.closeQuietly(raf);
+ }
+ }
+
guard.open("close");
}