]> granicus.if.org Git - pdns/commitdiff
LMDB: Initialize d_cursor in the base ctor
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 29 May 2019 09:45:12 +0000 (11:45 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 29 May 2019 09:45:12 +0000 (11:45 +0200)
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).

modules/lmdbbackend/lmdb-safe.hh

index de5e9aef850312848d10656c58432caff2a2d4b0..9b658741b4e11702112e16b902fbb0c8a5c9f0f5 100644 (file)
@@ -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<MDBROTransaction>(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<MDBRWTransaction>(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()