]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Prevent leakage of OSGI service references 49/4449/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 10 Sep 2020 21:06:58 +0000 (00:06 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 10 Sep 2020 21:06:58 +0000 (00:06 +0300)
gitlab #95

Change-Id: I7dfa5f7f21664e248be73f60927b8e2b6eee294f

org.simantics.district.maps/src/org/simantics/maps/eclipse/EclipseProxyUtil.java

index 601a82f7942c3899e1484f2a11faccd336282146..9e58c69ddc340a648f84411f38e76084da2fafe8 100644 (file)
@@ -42,13 +42,17 @@ public class EclipseProxyUtil implements IProxyUtil {
             return null;
 
         IProxyService service = bc.getService(ref);
-        if (service != null && service.isProxiesEnabled()) {
-            IProxyData proxyData = service.getProxyData(IProxyData.HTTP_PROXY_TYPE);
-            if (proxyData != null && proxyData.getHost() != null) {
-                return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyData.getHost(), proxyData.getPort()));
+        try {
+            if (service != null && service.isProxiesEnabled()) {
+                IProxyData proxyData = service.getProxyData(IProxyData.HTTP_PROXY_TYPE);
+                if (proxyData != null && proxyData.getHost() != null) {
+                    return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyData.getHost(), proxyData.getPort()));
+                }
             }
+            return null;
+        } finally {
+            bc.ungetService(ref);
         }
-        return null;
     }
 
 }