From: Remi Gacogne Date: Fri, 22 Sep 2017 12:26:04 +0000 (+0200) Subject: auth: Use a unique pointer for bind backend's `d_of` X-Git-Tag: rec-4.1.0-rc1~23^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7cfe0cc38e6db211da1b880bf24cfe9a9e6914cd;p=pdns auth: Use a unique pointer for bind backend's `d_of` --- diff --git a/modules/bindbackend/bindbackend2.cc b/modules/bindbackend/bindbackend2.cc index f7f7a7acb..a68a7a93a 100644 --- a/modules/bindbackend/bindbackend2.cc +++ b/modules/bindbackend/bindbackend2.cc @@ -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(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< alsoNotify; //!< this is used to store the also-notify list of interested peers. - ofstream *d_of; + std::unique_ptr 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