Fix a memory leak (FELIX-2283).
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@934141 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework.security/pom.xml b/framework.security/pom.xml
index 2dd4125..37e3b2c 100644
--- a/framework.security/pom.xml
+++ b/framework.security/pom.xml
@@ -40,7 +40,7 @@
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>org.apache.felix.framework</artifactId>
- <version>2.1.0-SNAPSHOT</version>
+ <version>2.0.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
diff --git a/framework.security/src/main/java/org/apache/felix/framework/security/util/Permissions.java b/framework.security/src/main/java/org/apache/felix/framework/security/util/Permissions.java
index 5d885cf..651b2cd 100644
--- a/framework.security/src/main/java/org/apache/felix/framework/security/util/Permissions.java
+++ b/framework.security/src/main/java/org/apache/felix/framework/security/util/Permissions.java
@@ -28,6 +28,7 @@
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.PrivilegedAction;
+import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
@@ -121,11 +122,16 @@
Permissions result = null;
synchronized (m_permissions)
{
- result = (Permissions) m_permissions.get(permissionInfos);
+ result = (Permissions) m_permissions.get(new Entry(permissionInfos));
}
if (result == null)
{
- result = new Permissions(permissionInfos, m_context, m_action);
+ //permissionInfos may not be referenced by the new Permissions, as
+ //otherwise the reference in m_permissions prevents the key from
+ //being garbage collectable.
+ PermissionInfo[] permissionInfosClone = new PermissionInfo[permissionInfos.length];
+ System.arraycopy(permissionInfos, 0, permissionInfosClone, 0, permissionInfos.length);
+ result = new Permissions(permissionInfosClone, m_context, m_action);
synchronized (m_permissions)
{
m_permissions.put(
@@ -175,13 +181,26 @@
Object entry = super.get();
- if (entry == null)
- {
- return false;
- }
-
if (o instanceof Entry)
{
+
+ Object otherEntry = ((Entry) o).get();
+ if (entry == null)
+ {
+ return otherEntry == null;
+ }
+ if (otherEntry == null)
+ {
+ return false;
+ }
+ if (!entry.getClass().equals(otherEntry.getClass()))
+ {
+ return false;
+ }
+ if (entry instanceof Object[])
+ {
+ return Arrays.equals((Object[])entry, (Object[])otherEntry);
+ }
return entry.equals(((Entry) o).get());
}
else