Skip to content

Commit

Permalink
Memory leak with PathCache.cache growing due the map was not synchron…
Browse files Browse the repository at this point in the history
…ized

closes keycloak#19096
  • Loading branch information
mposolda authored and pedroigor committed May 24, 2023
1 parent 8279435 commit 1f5d322
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.keycloak.adapters.authorization;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -53,12 +54,12 @@ public class PathCache {
*/
PathCache(final int maxEntries, long maxAge,
Map<String, PathConfig> paths) {
cache = new LinkedHashMap<String, CacheEntry>(16, DEFAULT_LOAD_FACTOR, true) {
cache = Collections.synchronizedMap(new LinkedHashMap<String, CacheEntry>(16, DEFAULT_LOAD_FACTOR, true) {
@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
return cache.size() > maxEntries;
}
};
});
this.maxAge = maxAge;
this.enabled = ! (maxAge < -1 || (maxAge > -1 && maxAge <= 0));
this.paths = paths;
Expand Down

0 comments on commit 1f5d322

Please sign in to comment.