From a6c506a1766a4b21cb954e128063e0a0328f97d9 Mon Sep 17 00:00:00 2001 From: zzz Date: Wed, 25 Jul 2018 12:51:40 +0000 Subject: [PATCH] Utils: Debug code to find double-frees --- core/java/src/net/i2p/util/TryCache.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/core/java/src/net/i2p/util/TryCache.java b/core/java/src/net/i2p/util/TryCache.java index 33f67db4d..c2690eab1 100644 --- a/core/java/src/net/i2p/util/TryCache.java +++ b/core/java/src/net/i2p/util/TryCache.java @@ -15,6 +15,8 @@ import java.util.concurrent.locks.ReentrantLock; */ public class TryCache { + private static final boolean DEBUG_DUP = false; + /** * Something that creates objects of the type cached by this cache * @@ -71,8 +73,21 @@ public class TryCache { public void release(T item) { if (lock.tryLock()) { try { + if (DEBUG_DUP) { + for (int i = 0; i < items.size(); i++) { + // use == not equals() because ByteArray.equals() + if (items.get(i) == item) { + net.i2p.I2PAppContext.getGlobalContext().logManager().getLog(TryCache.class).log(Log.CRIT, + "dup release of " + item.getClass(), new Exception("I did it")); + return; + } + } + } if (items.size() < capacity) { - items.add(item); + if (DEBUG_DUP) + items.add(0, item); + else + items.add(item); } } finally { lock.unlock();