https://bugs.openldap.org/show_bug.cgi?id=9949

          Issue ID: 9949
           Summary: MDB_RDONLY txn segfaults on newly created database
           Product: LMDB
           Version: unspecified
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Keywords: needs_review
          Severity: normal
          Priority: ---
         Component: liblmdb
          Assignee: b...@openldap.org
          Reporter: jeffrey.reyno...@ticketmaster.com
  Target Milestone: ---

The very simple code will cause a seg fault.

```
  auto env = create_env("env_name"); 
  // creates the environment. not included here because this part is in rust
  // it will open or create the database. i don't think the problem lies in
here.

  MDB_txn* txn{};
  mdb_txn_begin(*env, nullptr, MDB_RDONLY, &txn);

  MDB_dbi dbi{};
  mdb_dbi_open(txn, "db_name", MDB_CREATE, &dbi);
```

This segfaults on `liblmdb/mdb.c:11050`. Specifically `tracked->mc_next = *tp;` 
However, the problem isn't in mdb_dbi_open, it is failing because mt_cursors is
never initialized.

A small change `  mdb_txn_begin(*env, nullptr, 0, &txn);` and mt_cursors will
be initialized with the default env->me_txn0, that has a properly initialized
mt_cursors, per this line `liblmdb/mdb.c:5581`, `txn->mt_cursors = (MDB_cursor
**)(txn->mt_dbs + env->me_maxdbs);`  

for the MDB_RDONLY transaction, it looks like it will initialize mt_cursors
_if_ it happens to have a parent, `liblmdb/mdb.c:3178`, but otherwise it leaves
it uninitialized. 

Is this a bug, or do have i have to a parent to start a readonly transaction on
a new database?

-- 
You are receiving this mail because:
You are on the CC list for the issue.

Reply via email to