]> git.sur5r.net Git - openldap/blobdiff - libraries/liblmdb/mdb.c
ITS#7955, #7671 fix MDB_PREV_DUP
[openldap] / libraries / liblmdb / mdb.c
index 1eb46d303303d0be8bf1f215ea07ec64bfc939c6..a7659a5b3c8217399c37d32fb89d08e31925edf7 100644 (file)
@@ -90,7 +90,7 @@ extern int cacheflush(char *addr, int nbytes, int cache);
 #include <time.h>
 #include <unistd.h>
 
-#if defined(__sun)
+#if defined(__sun) || defined(ANDROID)
 /* Most platforms have posix_memalign, older may only have memalign */
 #define HAVE_MEMALIGN  1
 #include <malloc.h>
@@ -1948,7 +1948,7 @@ mdb_page_alloc(MDB_cursor *mc, int num, MDB_page **mp)
 #else
        enum { Paranoid = 0, Max_retries = INT_MAX /*infinite*/ };
 #endif
-       int rc, retry = num * 20;
+       int rc, retry = num * 60;
        MDB_txn *txn = mc->mc_txn;
        MDB_env *env = txn->mt_env;
        pgno_t pgno, *mop = env->me_pghead;
@@ -2626,6 +2626,7 @@ mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **ret)
        if (!(flags & MDB_RDONLY)) {
                if (!parent) {
                        txn = env->me_txn0;
+                       txn->mt_flags = 0;
                        goto ok;
                }
                size += env->me_maxdbs * sizeof(MDB_cursor *);
@@ -2773,12 +2774,27 @@ mdb_txn_reset0(MDB_txn *txn, const char *act)
                txn->mt_numdbs = 0;             /* close nothing if called again */
                txn->mt_dbxs = NULL;    /* mark txn as reset */
        } else {
-               mdb_cursors_close(txn, 0);
+               pgno_t *pghead = env->me_pghead;
+               env->me_pghead = NULL;
+               env->me_pglast = 0;
 
                if (!(env->me_flags & MDB_WRITEMAP)) {
                        mdb_dlist_free(txn);
                }
-               mdb_midl_free(env->me_pghead);
+
+               if (!txn->mt_parent) {
+                       if (mdb_midl_shrink(&txn->mt_free_pgs))
+                               env->me_free_pgs = txn->mt_free_pgs;
+
+                       env->me_txn = NULL;
+                       /* The writer mutex was locked in mdb_txn_begin. */
+                       if (env->me_txns)
+                               UNLOCK_MUTEX_W(env);
+               }
+
+               mdb_cursors_close(txn, 0);
+
+               mdb_midl_free(pghead);
 
                if (txn->mt_parent) {
                        txn->mt_parent->mt_child = NULL;
@@ -2786,18 +2802,7 @@ mdb_txn_reset0(MDB_txn *txn, const char *act)
                        mdb_midl_free(txn->mt_free_pgs);
                        mdb_midl_free(txn->mt_spill_pgs);
                        free(txn->mt_u.dirty_list);
-                       return;
                }
-
-               if (mdb_midl_shrink(&txn->mt_free_pgs))
-                       env->me_free_pgs = txn->mt_free_pgs;
-               env->me_pghead = NULL;
-               env->me_pglast = 0;
-
-               env->me_txn = NULL;
-               /* The writer mutex was locked in mdb_txn_begin. */
-               if (env->me_txns)
-                       UNLOCK_MUTEX_W(env);
        }
 }
 
@@ -4559,6 +4564,7 @@ mdb_env_close0(MDB_env *env, int excl)
        free(env->me_dbxs);
        free(env->me_path);
        free(env->me_dirty_list);
+       free(env->me_txn0);
        mdb_midl_free(env->me_free_pgs);
 
        if (env->me_flags & MDB_ENV_TXKEY) {
@@ -5422,11 +5428,11 @@ mdb_cursor_prev(MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op)
                                        }
                                        return rc;
                                }
-                       } else {
-                               mc->mc_xcursor->mx_cursor.mc_flags &= ~(C_INITIALIZED|C_EOF);
-                               if (op == MDB_PREV_DUP)
-                                       return MDB_NOTFOUND;
                        }
+               } else {
+                       mc->mc_xcursor->mx_cursor.mc_flags &= ~(C_INITIALIZED|C_EOF);
+                       if (op == MDB_PREV_DUP)
+                               return MDB_NOTFOUND;
                }
        }