This is an automated email from the ASF dual-hosted git repository. ffang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/karaf.git
The following commit(s) were added to refs/heads/master by this push: new 02ba614 [KARAF-6476]ClassLoader and Memory leak 02ba614 is described below commit 02ba6142666e92e9505285c4af90653dfaa3f5df Author: Freeman Fang <freeman.f...@gmail.com> AuthorDate: Wed Oct 23 20:22:43 2019 -0400 [KARAF-6476]ClassLoader and Memory leak --- .../osgi/secured/SecuredSessionFactoryImpl.java | 25 ++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredSessionFactoryImpl.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredSessionFactoryImpl.java index b6b0c99..93efef4 100644 --- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredSessionFactoryImpl.java +++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredSessionFactoryImpl.java @@ -26,10 +26,11 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Dictionary; import java.util.HashMap; -import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.WeakHashMap; import javax.security.auth.Subject; @@ -69,6 +70,7 @@ public class SecuredSessionFactoryImpl extends SessionFactoryImpl implements Con private SingleServiceTracker<ConfigurationAdmin> configAdminTracker; private ServiceRegistration<ConfigurationListener> registration; private ThreadLocal<Map<Object, Boolean>> serviceVisibleMap = new ThreadLocal<>(); + private Map<Thread, Map<Object, Boolean>> serviceVisibleMapForAllThreads = new WeakHashMap<>(); public SecuredSessionFactoryImpl(BundleContext bundleContext, ThreadIO threadIO) throws InvalidSyntaxException { super(threadIO); @@ -105,6 +107,8 @@ public class SecuredSessionFactoryImpl extends SessionFactoryImpl implements Con protected boolean isVisible(Object service) { if (this.serviceVisibleMap.get() == null) { this.serviceVisibleMap.set(new HashMap<>()); + Thread cur = Thread.currentThread(); + this.serviceVisibleMapForAllThreads.put(cur, this.serviceVisibleMap.get()); } if (this.serviceVisibleMap.get().get(service) != null) { return this.serviceVisibleMap.get().get(service); @@ -167,7 +171,6 @@ public class SecuredSessionFactoryImpl extends SessionFactoryImpl implements Con private AliasCommand findAlias(String scope, String name) { if (session != null) { Set<String> vars = ((Set<String>) session.get(null)); - Set<String> aliases = new HashSet<>(); String aliasScope = null; String aliasName = null; for (String var : vars) { @@ -319,6 +322,24 @@ public class SecuredSessionFactoryImpl extends SessionFactoryImpl implements Con LOGGER.error("Problem processing Configuration Event {}", event, e); } } + + @Override + public void unregister(Object service) { + synchronized (services) { + super.unregister(service); + removeUnregisteredSeriveForAllShell(service); + } + } + + private void removeUnregisteredSeriveForAllShell(Object service) { + synchronized (this.serviceVisibleMapForAllThreads) { + for (final Iterator<Map<Object, Boolean>> iterator = this.serviceVisibleMapForAllThreads.values().iterator(); + iterator.hasNext();) { + Map<Object, Boolean> serviceMap = iterator.next(); + serviceMap.remove(service); + } + } + } private void addScopeConfig(Configuration config) { if (!config.getPid().startsWith(PROXY_COMMAND_ACL_PID_PREFIX)) {