]> git.ipfire.org Git - thirdparty/pdns.git/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)
committerPieter Lexis <pieter.lexis@powerdns.com>
Tue, 7 Nov 2017 20:26:11 +0000 (21:26 +0100)
(cherry picked from commit 7cfe0cc38e6db211da1b880bf24cfe9a9e6914cd)

modules/bindbackend/bindbackend2.cc
modules/bindbackend/bindbackend2.hh

index 3baf25ebb43e7e8b937bf08407d22243e5ca29dd..e88a93208c42f89ce7810165263df316890e4805 100644 (file)
@@ -203,12 +203,11 @@ 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) {
-      throw DBException("Unable to open temporary zonefile '"+d_transaction_tmpname+"': "+stringerror());
       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());
     }
     
     *d_of<<"; Written by PowerDNS, don't edit!"<<endl;
@@ -223,8 +222,7 @@ bool Bind2Backend::commitTransaction()
 {
   if(d_transaction_id < 0)
     return true;
-  delete d_of;
-  d_of=0;
+  d_of.reset();
 
   BB2DomainInfo bbd;
   if(safeGetBBDomainInfo(d_transaction_id, &bbd)) {
@@ -244,9 +242,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;
   }
 
@@ -289,7 +286,9 @@ bool Bind2Backend::feedRecord(const DNSResourceRecord &rr, string *ordername)
     stripDomainSuffix(&content, name);
     // falltrough
   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 a93b44805ea4252d08526fddbd425ca0d7fdeeb6..df202677e0d6be7fca8f220b63fca14d6ae8729d 100644 (file)
@@ -299,7 +299,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