From: Hallvard Furuseth Date: Fri, 30 May 2014 07:06:08 +0000 (+0200) Subject: ITS#7834 Fix MDB_MULTIPLE writing multiple keys. X-Git-Tag: OPENLDAP_REL_ENG_2_4_40~132^2~8 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ac158c7e1e1a86b13eb7c0d2b14169c0e43e6198;p=openldap ITS#7834 Fix MDB_MULTIPLE writing multiple keys. Update the state before looping, so the key is not duplicated. Broke in 4c8f57615c5ca7b014c038e59c1045182e74f5ad (mostly). --- diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index cbf8c0494e..c4eaa262a0 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -6138,7 +6138,7 @@ current: data->mv_data = METADATA(omp); else memcpy(METADATA(omp), data->mv_data, data->mv_size); - goto done; + return MDB_SUCCESS; } } if ((rc2 = mdb_ovpage_free(mc, omp)) != MDB_SUCCESS) @@ -6154,7 +6154,7 @@ current: memcpy(olddata.mv_data, data->mv_data, data->mv_size); else memcpy(NODEKEY(leaf), key->mv_data, key->mv_size); - goto done; + return MDB_SUCCESS; } mdb_node_del(mc, 0); } @@ -6252,6 +6252,12 @@ put_sub: /* Increment count unless we just replaced an existing item. */ if (insert_data) mc->mc_db->md_entries++; + if (!rc && insert_key) { + /* If we succeeded and the key didn't exist before, + * make sure the cursor is marked valid. + */ + mc->mc_flags |= C_INITIALIZED; + } if (flags & MDB_MULTIPLE) { if (!rc) { next_mult: @@ -6260,17 +6266,12 @@ next_mult: data[1].mv_size = mcount; if (mcount < dcount) { data[0].mv_data = (char *)data[0].mv_data + data[0].mv_size; + insert_key = insert_data = 0; goto more; } } } } -done: - /* If we succeeded and the key didn't exist before, make sure - * the cursor is marked valid. - */ - if (!rc && insert_key) - mc->mc_flags |= C_INITIALIZED; return rc; }