applied patch from Selcuk for DIRSERVER-1649

git-svn-id: https://svn.apache.org/repos/asf/directory/apacheds/branches/apacheds-jdbm@1163237 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java b/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java
index fc4164a..bbe0bb1 100644
--- a/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java
+++ b/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java
@@ -245,13 +245,22 @@
 
                     subentryCache.addSubentry( subentryDn, newSubentry );
                 }
-
-                subentries.close();
             }
             catch ( Exception e )
             {
                 throw new LdapOperationException( e.getMessage(), e );
             }
+            finally
+            {
+                try
+                {
+                    subentries.close();
+                }
+                catch ( Exception e )
+                {
+                    LOG.error( I18n.err( I18n.ERR_168 ), e );
+                }
+            }
         }
     }
 
@@ -377,6 +386,17 @@
         {
             throw new LdapOtherException( e.getMessage(), e );
         }
+        finally
+        {
+            try
+            {
+                subentries.close();
+            }
+            catch ( Exception e )
+            {
+                LOG.error( I18n.err( I18n.ERR_168 ), e );
+            }
+        }
     }
 
 
@@ -1093,6 +1113,17 @@
             {
                 throw new LdapOperationErrorException( e.getMessage(), e );
             }
+            finally
+            {
+                try
+                {
+                    subentries.close();
+                }
+                catch ( Exception e )
+                {
+                    LOG.error( I18n.err( I18n.ERR_168 ), e );
+                }
+            }
 
             // search for all selected entries by the new SS and add references to subentry
             subentry = subentryCache.getSubentry( dn );
@@ -1124,6 +1155,17 @@
             {
                 throw new LdapOperationErrorException( e.getMessage(), e );
             }
+            finally
+            {
+                try
+                {
+                    subentries.close();
+                }
+                catch ( Exception e )
+                {
+                    LOG.error( I18n.err( I18n.ERR_168 ), e );
+                }
+            }
         }
         else
         {
@@ -1232,13 +1274,22 @@
                             oldDn, newName, subentry, candidate ) ) );
                     }
                 }
-
-                subentries.close();
             }
             catch ( Exception e )
             {
                 throw new LdapOperationException( e.getMessage(), e );
             }
+            finally
+            {
+                try
+                {
+                    subentries.close();
+                }
+                catch ( Exception e )
+                {
+                    LOG.error( I18n.err( I18n.ERR_168 ), e );
+                }
+            }
         }
         else
         {
@@ -1323,13 +1374,22 @@
                             oldDn, newName, subentry, candidate ) ) );
                     }
                 }
-
-                subentries.close();
             }
             catch ( Exception e )
             {
                 throw new LdapOperationException( e.getMessage(), e );
             }
+            finally
+            {
+                try
+                {
+                    subentries.close();
+                }
+                catch ( Exception e )
+                {
+                    LOG.error( I18n.err( I18n.ERR_168 ), e );
+                }
+            }
         }
         else
         {
@@ -1404,13 +1464,22 @@
                             oldDn, newName, subentry, candidate ) ) );
                     }
                 }
-
-                subentries.close();
             }
             catch ( Exception e )
             {
                 throw new LdapOperationException( e.getMessage(), e );
             }
+            finally
+            {
+                try
+                {
+                    subentries.close();
+                }
+                catch ( Exception e )
+                {
+                    LOG.error( I18n.err( I18n.ERR_168 ), e );
+                }
+            }
         }
         else
         {
diff --git a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java
index 9f20e3c..b1a6a76 100644
--- a/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java
+++ b/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java
@@ -477,4 +477,26 @@
         super.close( cause );
         containerCursor.close( cause );
     }
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void close() throws Exception
+    {
+        super.close();
+        containerCursor.close();            
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void close( Exception cause ) throws Exception
+    {
+        super.close( cause );
+        containerCursor.close( cause );
+    }
+
 }