|
@@ -314,6 +314,8 @@ LSUP_mdbstore_new (const char *path, const LSUP_Buffer *default_ctx)
|
|
|
LSUP_nsmap_add (nsm, init_nsmap[i][0], init_nsmap[i][1]);
|
|
|
|
|
|
LSUP_mdbstore_nsm_store (store, nsm);
|
|
|
+
|
|
|
+ LSUP_nsmap_free (nsm);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -989,10 +991,12 @@ LSUP_mdbstore_nsm_store (LSUP_MDBStore *store, const LSUP_NSMap *nsm)
|
|
|
for (size_t i = 0; nsm_data[i] != NULL; i++) {
|
|
|
// At least 1 action. If not OK, it will change during the iteration.
|
|
|
if (i == 0) rc = LSUP_OK;
|
|
|
+ // On previous error, just clean up the NSM data array.
|
|
|
+ if (rc < 0) goto loop_end;
|
|
|
|
|
|
- pfx_v.mv_data = (void *) nsm_data[i];
|
|
|
+ pfx_v.mv_data = (void *) nsm_data[i][0];
|
|
|
pfx_v.mv_size = strlen (nsm_data[i][0]) + 1;
|
|
|
- ns_v.mv_data = (void *) nsm_data[i] + 1;
|
|
|
+ ns_v.mv_data = (void *) nsm_data[i][1];
|
|
|
ns_v.mv_size = strlen (nsm_data[i][1]) + 1;
|
|
|
|
|
|
// If either ns or pfx exist, skip.
|
|
@@ -1002,22 +1006,24 @@ LSUP_mdbstore_nsm_store (LSUP_MDBStore *store, const LSUP_NSMap *nsm)
|
|
|
mdb_cursor_get (icur, &ns_v, &pfx_v, MDB_SET) != MDB_NOTFOUND
|
|
|
) {
|
|
|
rc = LSUP_CONFLICT;
|
|
|
- continue;
|
|
|
+ goto loop_end;
|
|
|
}
|
|
|
|
|
|
db_rc = mdb_cursor_put (dcur, &pfx_v, &ns_v, 0);
|
|
|
db_rc |= mdb_cursor_put (icur, &ns_v, &pfx_v, 0);
|
|
|
if (db_rc != MDB_SUCCESS) {
|
|
|
log_error ("DB error: %s", LSUP_strerror (db_rc));
|
|
|
- free (nsm_data);
|
|
|
- return LSUP_DB_ERR;
|
|
|
+ rc = LSUP_DB_ERR;
|
|
|
}
|
|
|
+loop_end:
|
|
|
+ free (nsm_data[i]);
|
|
|
}
|
|
|
free (nsm_data);
|
|
|
|
|
|
- if (UNLIKELY (mdb_txn_commit (txn) != MDB_SUCCESS)) {
|
|
|
+ if (UNLIKELY (rc != LSUP_OK)) mdb_txn_abort (txn);
|
|
|
+ else if (UNLIKELY (mdb_txn_commit (txn) != MDB_SUCCESS)) {
|
|
|
mdb_txn_abort (txn);
|
|
|
- return LSUP_TXN_ERR;
|
|
|
+ rc = LSUP_TXN_ERR;
|
|
|
}
|
|
|
|
|
|
return rc;
|
|
@@ -1029,6 +1035,8 @@ LSUP_mdbstore_tkey_exists (LSUP_MDBStore *store, LSUP_Key tkey)
|
|
|
{
|
|
|
int db_rc, rc;
|
|
|
MDB_val key, data;
|
|
|
+ key.mv_data = &tkey;
|
|
|
+ key.mv_size = KLEN;
|
|
|
|
|
|
MDB_txn *txn = NULL;
|
|
|
mdb_txn_begin (store->env, NULL, MDB_RDONLY, &txn);
|