mtest*.c: Fix MDB_NOOVERWRITE, plug cursor leak

vl32b
Hallvard Furuseth 10 years ago
parent 9bb915675a
commit 77bdbdd9de
  1. 6
      libraries/liblmdb/mtest.c
  2. 4
      libraries/liblmdb/mtest2.c
  3. 9
      libraries/liblmdb/mtest6.c

@ -54,12 +54,13 @@ int main(int argc,char * argv[])
key.mv_size = sizeof(int); key.mv_size = sizeof(int);
key.mv_data = sval; key.mv_data = sval;
data.mv_size = sizeof(sval);
data.mv_data = sval;
printf("Adding %d values\n", count); printf("Adding %d values\n", count);
for (i=0;i<count;i++) { for (i=0;i<count;i++) {
sprintf(sval, "%03x %d foo bar", values[i], values[i]); sprintf(sval, "%03x %d foo bar", values[i], values[i]);
/* Set <data> in each iteration, since MDB_NOOVERWRITE may modify it */
data.mv_size = sizeof(sval);
data.mv_data = sval;
if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE))) { if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE))) {
j++; j++;
data.mv_size = sizeof(sval); data.mv_size = sizeof(sval);
@ -130,6 +131,7 @@ int main(int argc,char * argv[])
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
mdb_cursor_close(cursor);
mdb_txn_abort(txn); mdb_txn_abort(txn);
printf("Deleting with cursor\n"); printf("Deleting with cursor\n");

@ -57,12 +57,12 @@ int main(int argc,char * argv[])
key.mv_size = sizeof(int); key.mv_size = sizeof(int);
key.mv_data = sval; key.mv_data = sval;
data.mv_size = sizeof(sval);
data.mv_data = sval;
printf("Adding %d values\n", count); printf("Adding %d values\n", count);
for (i=0;i<count;i++) { for (i=0;i<count;i++) {
sprintf(sval, "%03x %d foo bar", values[i], values[i]); sprintf(sval, "%03x %d foo bar", values[i], values[i]);
data.mv_size = sizeof(sval);
data.mv_data = sval;
if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE))) if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE)))
j++; j++;
} }

@ -31,7 +31,7 @@ int main(int argc,char * argv[])
int i = 0, j = 0, rc; int i = 0, j = 0, rc;
MDB_env *env; MDB_env *env;
MDB_dbi dbi; MDB_dbi dbi;
MDB_val key, data; MDB_val key, data, sdata;
MDB_txn *txn; MDB_txn *txn;
MDB_stat mst; MDB_stat mst;
MDB_cursor *cursor; MDB_cursor *cursor;
@ -55,25 +55,28 @@ int main(int argc,char * argv[])
sval = calloc(1, mst.ms_psize / 4); sval = calloc(1, mst.ms_psize / 4);
key.mv_size = sizeof(long); key.mv_size = sizeof(long);
key.mv_data = &kval; key.mv_data = &kval;
data.mv_size = mst.ms_psize / 4 - 30; sdata.mv_size = mst.ms_psize / 4 - 30;
data.mv_data = sval; sdata.mv_data = sval;
printf("Adding 12 values, should yield 3 splits\n"); printf("Adding 12 values, should yield 3 splits\n");
for (i=0;i<12;i++) { for (i=0;i<12;i++) {
kval = i*5; kval = i*5;
sprintf(sval, "%08x", kval); sprintf(sval, "%08x", kval);
data = sdata;
(void)RES(MDB_KEYEXIST, mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE)); (void)RES(MDB_KEYEXIST, mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE));
} }
printf("Adding 12 more values, should yield 3 splits\n"); printf("Adding 12 more values, should yield 3 splits\n");
for (i=0;i<12;i++) { for (i=0;i<12;i++) {
kval = i*5+4; kval = i*5+4;
sprintf(sval, "%08x", kval); sprintf(sval, "%08x", kval);
data = sdata;
(void)RES(MDB_KEYEXIST, mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE)); (void)RES(MDB_KEYEXIST, mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE));
} }
printf("Adding 12 more values, should yield 3 splits\n"); printf("Adding 12 more values, should yield 3 splits\n");
for (i=0;i<12;i++) { for (i=0;i<12;i++) {
kval = i*5+1; kval = i*5+1;
sprintf(sval, "%08x", kval); sprintf(sval, "%08x", kval);
data = sdata;
(void)RES(MDB_KEYEXIST, mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE)); (void)RES(MDB_KEYEXIST, mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE));
} }
E(mdb_cursor_get(cursor, &key, &data, MDB_FIRST)); E(mdb_cursor_get(cursor, &key, &data, MDB_FIRST));

Loading…
Cancel
Save