From 5b23d7e452761a99a816f16cec1933301f034885 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Thu, 7 Sep 2017 09:09:44 +0300 Subject: [PATCH] mdbx: fix mdbx_dbi_open_ex(MDBX_CREATE) for rdonly txn. Fix https://github.com/leo-yuriev/libmdbx/issues/19 Change-Id: I3ae1ab3188482fd8c31de51d62e34591082cd60a --- src/mdbx.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mdbx.c b/src/mdbx.c index 4b0fd782..4edacd83 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -8118,6 +8118,8 @@ static void mdbx_cursor_copy(const MDBX_cursor *csrc, MDBX_cursor *cdst); /* Perform act while tracking temporary cursor mn */ #define WITH_CURSOR_TRACKING(mn, act) \ do { \ + mdbx_cassert(&(mn), \ + mn.mc_txn->mt_cursors != NULL /* must be not rdonly txt */); \ MDBX_cursor mc_dummy, *tracked, \ **tp = &(mn).mc_txn->mt_cursors[mn.mc_dbi]; \ if ((mn).mc_flags & C_SUB) { \ @@ -10080,6 +10082,10 @@ int mdbx_dbi_open_ex(MDBX_txn *txn, const char *table_name, unsigned user_flags, return MDBX_INCOMPATIBLE; } + if (rc != MDBX_SUCCESS && + unlikely(txn->mt_flags & (MDBX_TXN_RDONLY | MDBX_TXN_BLOCKED))) + return (txn->mt_flags & MDBX_TXN_RDONLY) ? MDBX_EACCESS : MDBX_BAD_TXN; + /* Done here so we cannot fail after creating a new DB */ char *namedup = mdbx_strdup(table_name); if (unlikely(!namedup))