]> granicus.if.org Git - pdns/commitdiff
auth: Use a unique pointer for bind backend's `d_of`
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 22 Sep 2017 12:26:04 +0000 (14:26 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 22 Sep 2017 12:26:04 +0000 (14:26 +0200)
modules/bindbackend/bindbackend2.cc
modules/bindbackend/bindbackend2.hh

index f7f7a7acb357ef78e559ef4de88b0a09d3c1d3ee..a68a7a93a550f95bb4319a2ffa46668d1d432b2e 100644 (file)
@@ -204,11 +204,10 @@ bool Bind2Backend::startTransaction(const DNSName &qname, int id)
   BB2DomainInfo bbd;
   if(safeGetBBDomainInfo(id, &bbd)) {
     d_transaction_tmpname=bbd.d_filename+"."+itoa(random());
-    d_of=new ofstream(d_transaction_tmpname.c_str());
+    d_of=std::unique_ptr<ofstream>(new ofstream(d_transaction_tmpname.c_str()));
     if(!*d_of) {
       unlink(d_transaction_tmpname.c_str());
-      delete d_of;
-      d_of=0;
+      d_of.reset();
       throw DBException("Unable to open temporary zonefile '"+d_transaction_tmpname+"': "+stringerror());
     }
     
@@ -224,8 +223,7 @@ bool Bind2Backend::commitTransaction()
 {
   if(d_transaction_id < 0)
     return false;
-  delete d_of;
-  d_of=0;
+  d_of.reset();
 
   BB2DomainInfo bbd;
   if(safeGetBBDomainInfo(d_transaction_id, &bbd)) {
@@ -245,9 +243,8 @@ bool Bind2Backend::abortTransaction()
   // 0  = invalid transact
   // >0 = actual transaction
   if(d_transaction_id > 0) {
-    delete d_of;
-    d_of=0;
     unlink(d_transaction_tmpname.c_str());
+    d_of.reset();
     d_transaction_id=0;
   }
 
@@ -291,7 +288,9 @@ bool Bind2Backend::feedRecord(const DNSResourceRecord &rr, const DNSName &ordern
     stripDomainSuffix(&content, name);
     // fallthrough
   default:
-    *d_of<<qname<<"\t"<<rr.ttl<<"\t"<<rr.qtype.getName()<<"\t"<<content<<endl;
+    if (d_of && *d_of) {
+      *d_of<<qname<<"\t"<<rr.ttl<<"\t"<<rr.qtype.getName()<<"\t"<<content<<endl;
+    }
   }
   return true;
 }
index 68c5257fb89bbbc508bdeed0b25bb14a3aea4dfa..075ec4b4ffbc20d9e30bacf207959b21d52190ae 100644 (file)
@@ -304,7 +304,7 @@ private:
   string d_transaction_tmpname;
   string d_logprefix;
   set<string> alsoNotify; //!< this is used to store the also-notify list of interested peers.
-  ofstream *d_of;
+  std::unique_ptr<ofstream> d_of;
   handle d_handle;
   static string s_binddirectory;                              //!< this is used to store the 'directory' setting of the bind configuration
   static int s_first;                                  //!< this is raised on construction to prevent multiple instances of us being generated