From 27128b3e01a9c97f1d2549ded0d381f469f0aee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Ar=C3=A8s?= Date: Thu, 28 May 2015 14:21:03 -0400 Subject: [PATCH] Fix WindowCursor memory leak. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ObjectReader release method was replaced by close method but WindowCursor was still implementing release method. To prevent the same mistake again, make ObjectReader close method abstract to force sub classes to implement it. Change-Id: I50d0d1d19a26e306fd0dba77b246a95a44fd6584 Signed-off-by: Hugo Arès --- .../org/eclipse/jgit/internal/storage/file/PackFileTest.java | 2 +- .../jgit/internal/storage/file/UnpackedObjectTest.java | 2 +- .../eclipse/jgit/internal/storage/file/PackInputStream.java | 2 +- .../eclipse/jgit/internal/storage/file/UnpackedObject.java | 2 +- .../org/eclipse/jgit/internal/storage/file/WindowCursor.java | 3 ++- org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java | 4 +--- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java index 05055644e..cb80768e5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java @@ -123,7 +123,7 @@ public class PackFileTest extends LocalDiskRepositoryTestCase { @After public void tearDown() throws Exception { if (wc != null) - wc.release(); + wc.close(); new WindowCacheConfig().install(); super.tearDown(); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java index 10d2b6b52..8c8c6c6d0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java @@ -108,7 +108,7 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase { @After public void tearDown() throws Exception { if (wc != null) - wc.release(); + wc.close(); new WindowCacheConfig().install(); super.tearDown(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackInputStream.java index 9cb834957..154809bad 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackInputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackInputStream.java @@ -80,6 +80,6 @@ class PackInputStream extends InputStream { @Override public void close() { - wc.release(); + wc.close(); } } \ No newline at end of file diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java index cb95a7656..cb7d91259 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java @@ -95,7 +95,7 @@ public class UnpackedObject { try { return open(new ByteArrayInputStream(raw), null, id, wc); } finally { - wc.release(); + wc.close(); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java index 3e6cb5835..a555e10d4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java @@ -330,7 +330,8 @@ final class WindowCursor extends ObjectReader implements ObjectReuseAsIs { } /** Release the current window cursor. */ - public void release() { + @Override + public void close() { window = null; baseCache = null; try { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java index 4c9af85fa..77cfb038c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectReader.java @@ -430,7 +430,5 @@ public abstract class ObjectReader implements AutoCloseable { * @since 4.0 */ @Override - public void close() { - // Do nothing. - } + public abstract void close(); }