diff options
author | David Boreham <dboreham@redhat.com> | 2005-05-16 23:07:56 +0000 |
---|---|---|
committer | David Boreham <dboreham@redhat.com> | 2005-05-16 23:07:56 +0000 |
commit | 5c12d869ad9183491c5f9ef2d9b1f13b6dfb0342 (patch) | |
tree | c58d120214d56f9e34cb067c53ea00f77d4d1c9e | |
parent | 499758194052323a2b97f15665312aca98f5dcdc (diff) | |
download | ds-5c12d869ad9183491c5f9ef2d9b1f13b6dfb0342.tar.gz ds-5c12d869ad9183491c5f9ef2d9b1f13b6dfb0342.tar.xz ds-5c12d869ad9183491c5f9ef2d9b1f13b6dfb0342.zip |
Memory Leak Fixes for Apache DS
-rw-r--r-- | ldap/servers/ntds/apacheds/noleak.diff | 120 | ||||
-rw-r--r-- | ldap/servers/ntds/apacheds/org/apache/ldap/server/NetAPIPartition.java | 28 | ||||
-rw-r--r-- | ldap/servers/ntds/apacheds/readme.txt | 2 |
3 files changed, 139 insertions, 11 deletions
diff --git a/ldap/servers/ntds/apacheds/noleak.diff b/ldap/servers/ntds/apacheds/noleak.diff new file mode 100644 index 00000000..9648237c --- /dev/null +++ b/ldap/servers/ntds/apacheds/noleak.diff @@ -0,0 +1,120 @@ +Index: trunk/src/java/org/apache/mina/common/ByteBuffer.java +=================================================================== +--- trunk/src/java/org/apache/mina/common/ByteBuffer.java (revision 168349) ++++ trunk/src/java/org/apache/mina/common/ByteBuffer.java (working copy) +@@ -114,29 +114,14 @@ + { + private static final int MINIMUM_CAPACITY = 1; + +- private static final Stack containerStack = new Stack(); +- +- private static final Stack[] heapBufferStacks = new Stack[] { +- new Stack(), new Stack(), new Stack(), new Stack(), +- new Stack(), new Stack(), new Stack(), new Stack(), +- new Stack(), new Stack(), new Stack(), new Stack(), +- new Stack(), new Stack(), new Stack(), new Stack(), +- new Stack(), new Stack(), new Stack(), new Stack(), +- new Stack(), new Stack(), new Stack(), new Stack(), +- new Stack(), new Stack(), new Stack(), new Stack(), +- new Stack(), new Stack(), new Stack(), new Stack(), }; +- +- private static final Stack[] directBufferStacks = new Stack[] { +- new Stack(), new Stack(), new Stack(), new Stack(), +- new Stack(), new Stack(), new Stack(), new Stack(), +- new Stack(), new Stack(), new Stack(), new Stack(), +- new Stack(), new Stack(), new Stack(), new Stack(), +- new Stack(), new Stack(), new Stack(), new Stack(), +- new Stack(), new Stack(), new Stack(), new Stack(), +- new Stack(), new Stack(), new Stack(), new Stack(), +- new Stack(), new Stack(), new Stack(), new Stack(), }; +- + /** ++ * This class leaked great amounts of memory when doing dymanic ++ * ByteBuffer'ing. This part was removed and replaced with traditonal ++ * new()'s. This patch will no longer need to be applied when this class ++ * is operates without leaks in the future. ++ **/ ++ ++ /** + * Returns the direct or heap buffer which is capable of the specified + * size. This method tries to allocate direct buffer first, and then + * tries heap buffer if direct buffer memory is exhausted. Please use +@@ -157,7 +142,7 @@ + return allocate( capacity, false ); + } + } +- ++ + /** + * Returns the buffer which is capable of the specified size. + * +@@ -169,38 +154,18 @@ + { + java.nio.ByteBuffer nioBuffer = allocate0( capacity, direct ); + DefaultByteBuffer buf; +- +- synchronized( containerStack ) +- { +- buf = ( DefaultByteBuffer ) containerStack.pop(); +- } +- +- if( buf == null ) +- { +- buf = new DefaultByteBuffer(); +- } + ++ buf = new DefaultByteBuffer(); ++ + buf.init( nioBuffer ); + return buf; + } + + private static java.nio.ByteBuffer allocate0( int capacity, boolean direct ) + { +- Stack[] bufferStacks = direct? directBufferStacks : heapBufferStacks; +- int idx = getBufferStackIndex( bufferStacks, capacity ); +- Stack stack = bufferStacks[ idx ]; +- +- java.nio.ByteBuffer buf; +- synchronized( stack ) +- { +- buf = ( java.nio.ByteBuffer ) stack.pop(); +- } +- +- if( buf == null ) +- { +- buf = direct ? java.nio.ByteBuffer.allocateDirect( MINIMUM_CAPACITY << idx ) : +- java.nio.ByteBuffer.allocate( MINIMUM_CAPACITY << idx ); +- } ++ java.nio.ByteBuffer buf; ++ buf = direct ? java.nio.ByteBuffer.allocateDirect( capacity ) : ++ java.nio.ByteBuffer.allocate( capacity ); + + buf.clear(); + buf.order( ByteOrder.BIG_ENDIAN ); +@@ -209,13 +174,7 @@ + + private static void release0( java.nio.ByteBuffer buf ) + { +- Stack[] bufferStacks = buf.isDirect()? directBufferStacks : heapBufferStacks; +- Stack stack = bufferStacks[ getBufferStackIndex( bufferStacks, buf.capacity() ) ]; +- synchronized( stack ) +- { +- // push back +- stack.push( buf ); +- } ++ buf = null; + } + + /** +@@ -567,10 +526,6 @@ + } + + release0( buf ); +- synchronized( containerStack ) +- { +- containerStack.push( this ); +- } + } + + public java.nio.ByteBuffer buf() diff --git a/ldap/servers/ntds/apacheds/org/apache/ldap/server/NetAPIPartition.java b/ldap/servers/ntds/apacheds/org/apache/ldap/server/NetAPIPartition.java index c4403f2c..34aaf95c 100644 --- a/ldap/servers/ntds/apacheds/org/apache/ldap/server/NetAPIPartition.java +++ b/ldap/servers/ntds/apacheds/org/apache/ldap/server/NetAPIPartition.java @@ -1033,8 +1033,14 @@ public class NetAPIPartition implements ContextPartition { attribute.add(user.GetSIDHexStr()); attributes.put(attribute); + // Convert from NT4 format to AD format + Long accountExpires = new Long(user.GetAccountExpires()); + // First convert epoch from 1970 to 1601 + accountExpires = new Long(accountExpires.longValue() + ((long)134774 * (long)86400)); + // Then convert from seconds to tenths of micro seconds + accountExpires = new Long(accountExpires.longValue() * (long)10000000); attribute = new BasicAttribute("accountExpires"); - attribute.add(new Long(user.GetAccountExpires()).toString()); + attribute.add(accountExpires.toString()); attributes.put(attribute); attribute = new BasicAttribute("badPwdCount"); @@ -1079,11 +1085,9 @@ public class NetAPIPartition implements ContextPartition { attribute.add(new Long(user.GetLastLogon()).toString()); attributes.put(attribute); - /* attribute = new BasicAttribute("logonHours"); attribute.add(HexStringToByteArray(user.GetLogonHours())); attributes.put(attribute); - */ attribute = new BasicAttribute("maxStorage"); attribute.add(new Long(user.GetMaxStorage()).toString()); @@ -1273,14 +1277,20 @@ public class NetAPIPartition implements ContextPartition { for(int i = 0; i < mods.length; i++) { if(mods[i].getAttribute().getID().compareToIgnoreCase("accountExpires") == 0) { + // Convert from AD format to NT4 format + Long accountExpires = new Long((String)mods[i].getAttribute().get()); + // First convert from tenths of micro seconds to seconds + accountExpires = new Long(accountExpires.longValue() / (long)10000000); + // Then convert epoch from 1601 to 1970 + accountExpires = new Long(accountExpires.longValue() - ((long)134774 * (long)86400)); if(mods[i].getModificationOp() == DirContext.ADD_ATTRIBUTE) { - user.SetAccountExpires(new Long((String)mods[i].getAttribute().get()).longValue()); + user.SetAccountExpires(accountExpires.longValue()); } else if(mods[i].getModificationOp() == DirContext.REMOVE_ATTRIBUTE) { user.SetAccountExpires(new Long(-1).longValue()); } else if(mods[i].getModificationOp() == DirContext.REPLACE_ATTRIBUTE) { - user.SetAccountExpires(new Long((String)mods[i].getAttribute().get()).longValue()); + user.SetAccountExpires(accountExpires.longValue()); } } else if(mods[i].getAttribute().getID().compareToIgnoreCase("codePage") == 0) { @@ -1349,19 +1359,17 @@ public class NetAPIPartition implements ContextPartition { user.SetHomeDirDrive((String)mods[i].getAttribute().get()); } } - /* - else if(mods[i].getAttribute().getID().compareToIgnoreCase("logonHours") == 0) { + else if(mods[i].getAttribute().getID().compareToIgnoreCase("logonHours") == 0) { if(mods[i].getModificationOp() == DirContext.ADD_ATTRIBUTE) { - user.SetLogonHours(ByteArrayToHexString((byte[])mods[i].getAttribute().get())); + user.SetLogonHours(ByteArrayToHexString(mods[i].getAttribute().get().toString().getBytes())); } else if(mods[i].getModificationOp() == DirContext.REMOVE_ATTRIBUTE) { user.SetLogonHours("ffffffffffffffffffffffffffffffffffffffffff"); } else if(mods[i].getModificationOp() == DirContext.REPLACE_ATTRIBUTE) { - user.SetLogonHours(ByteArrayToHexString((byte[])mods[i].getAttribute().get())); + user.SetLogonHours(ByteArrayToHexString(mods[i].getAttribute().get().toString().getBytes())); } } - */ else if(mods[i].getAttribute().getID().compareToIgnoreCase("maxStorage") == 0) { if(mods[i].getModificationOp() == DirContext.ADD_ATTRIBUTE) { user.SetMaxStorage(new Long((String)mods[i].getAttribute().get()).longValue()); diff --git a/ldap/servers/ntds/apacheds/readme.txt b/ldap/servers/ntds/apacheds/readme.txt index 42a5646b..57455440 100644 --- a/ldap/servers/ntds/apacheds/readme.txt +++ b/ldap/servers/ntds/apacheds/readme.txt @@ -3,7 +3,7 @@ basic instructions for our apacheds: for our jar component # svn co http://svn.apache.org/repos/asf/directory # cd directory/apacheds/trunk/ -# apply the patch +# apply the patches # maven -D maven.test.skip=true multiproject:install # cd main/target # copy apacheds-main-${VER}.jar into component directory |