From: Remi Gacogne Date: Wed, 29 May 2019 09:45:12 +0000 (+0200) Subject: LMDB: Initialize d_cursor in the base ctor X-Git-Tag: dnsdist-1.4.0-beta1~8^2~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=331899ba39369edef33e36fb727c563620c8380a;p=thirdparty%2Fpdns.git LMDB: Initialize d_cursor in the base ctor It's always properly initialized in the derived classes so far, but let's make sure it stays that way. Also make sure we don't call mdb_cursor_close() on a nullptr cursor after being moved. Reported by Coverity (CID 1401632). --- diff --git a/modules/lmdbbackend/lmdb-safe.hh b/modules/lmdbbackend/lmdb-safe.hh index de5e9aef85..9b658741b4 100644 --- a/modules/lmdbbackend/lmdb-safe.hh +++ b/modules/lmdbbackend/lmdb-safe.hh @@ -372,7 +372,7 @@ public: return d_cursor; } - MDB_cursor* d_cursor; + MDB_cursor* d_cursor{nullptr}; Transaction* d_parent; }; @@ -389,13 +389,15 @@ public: MDBROCursor(MDBROCursor&& rhs) : MDBGenCursor(rhs.d_parent) { d_cursor = rhs.d_cursor; - rhs.d_cursor=0; + rhs.d_cursor = nullptr; } void close() { - mdb_cursor_close(d_cursor); - d_cursor=0; + if (d_cursor) { + mdb_cursor_close(d_cursor); + d_cursor = nullptr; + } } ~MDBROCursor() @@ -568,7 +570,7 @@ public: MDBRWCursor(MDBRWCursor&& rhs) : MDBGenCursor(rhs.d_parent) { d_cursor = rhs.d_cursor; - rhs.d_cursor=0; + rhs.d_cursor = nullptr; d_parent->reportCursorMove(&rhs, this); } @@ -576,7 +578,7 @@ public: { if(d_cursor) mdb_cursor_close(d_cursor); - d_cursor=0; + d_cursor = nullptr; } ~MDBRWCursor()