From 9feb0aeec024ac5a4d1ba17cd7e6d63bd92ac41d Mon Sep 17 00:00:00 2001 From: Aaron Ogburn Date: Thu, 9 May 2024 14:33:40 -0400 Subject: [PATCH] [UNDERTOW-2385] Use synchronized WeakHashMap in DefaultByteBufferPool to avoid leak for released threads Signed-off-by: Flavia Rainone --- .../main/java/io/undertow/server/DefaultByteBufferPool.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/undertow/server/DefaultByteBufferPool.java b/core/src/main/java/io/undertow/server/DefaultByteBufferPool.java index debc92efef..16379bdc27 100644 --- a/core/src/main/java/io/undertow/server/DefaultByteBufferPool.java +++ b/core/src/main/java/io/undertow/server/DefaultByteBufferPool.java @@ -26,6 +26,7 @@ import java.nio.ByteBuffer; import java.util.ArrayDeque; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.WeakHashMap; @@ -334,7 +335,7 @@ protected void finalize() throws Throwable { // class can be called by a different thread than the one that initialized the data. private static class ThreadLocalCache { - Map localsByThread = new WeakHashMap<>(); + Map localsByThread = Collections.synchronizedMap(new WeakHashMap<>()); ThreadLocalData get() { return localsByThread.get(Thread.currentThread());