From 22f94c4b6787a56cffea3cc71633124ab9ab4199 Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Mon, 18 Mar 2024 12:51:46 -0500 Subject: [PATCH] Avoid memory leak when thread is reused This leak can happen if multiple copies of `smallrye-config` are loaded by different class loaders, like in Quarkus dev mode. --- .../config/SmallRyeConfigSourceInterceptorContext.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigSourceInterceptorContext.java b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigSourceInterceptorContext.java index 95bae8da1..6643fa804 100644 --- a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigSourceInterceptorContext.java +++ b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigSourceInterceptorContext.java @@ -32,7 +32,10 @@ public ConfigValue restart(final String name) { try { return config.interceptorChain().proceed(name); } finally { - rc.decrement(); + if (rc.decrement()) { + // avoid leaking if the thread is cached + rcHolder.remove(); + } } } @@ -52,8 +55,8 @@ void increment() { count = old + 1; } - void decrement() { - count--; + boolean decrement() { + return --count == 0; } } }