Closed canepat closed 2 years ago
Hmm, I will fix this (by my self) promptly.
Sorry, I've missed that cursor
explicitly manages the handle, so probably the correct solution is a bit more involved.
Please check out the https://github.com/erthink/libmdbx/commit/d8431a35cb17cc052c1d6b29749416a6bbfb589f
Minor refine commit' comment by the https://github.com/erthink/libmdbx/commit/3c574fca99a5c2882780031f4b4d887e8bfae218.
@canepat, thank you for reporting.
These changes raise now compiler errors on code using mdbx in cases like this:
mdbx::txn tx = ...
mdbx::cursor_managed source{tx.open_cursor(...)};
...
source.close();
source = tx.open_cursor(...); // compiler error here
which compiled and worked as expected before (the leak was present just if close
is not called). I don't think that your goal is prohibiting the cursor_managed
move assignment or am I missing something?
Apart from compiler errors, using the inherited move assignment operator in cursor_managed
class seems insufficient to me because the base class operator does not dispose the handle. Isn't the cursor_managed
class supposed to manage the handle implicitly in all cases?
The change proposed in this PR doesn't break the case listed above and also closes the handle automatically when moving if close
has not been called explicitly.
I've seen now your rework in https://github.com/erthink/libmdbx/commit/464886ab614378cc7036cdd047c6b64adabb8930 and it looks good to me, it should solve my issues in previous comment.
Custom move assignment operator for
cursor_managed
is required to close the current handle before moving (see also https://github.com/torquem-ch/silkworm/issues/575).