From c2aed12956097aa013025bec918b74ff42c85473 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 22 Sep 2017 14:26:04 +0200 Subject: [PATCH] auth: Use a unique pointer for bind backend's `d_of` (cherry picked from commit 7cfe0cc38e6db211da1b880bf24cfe9a9e6914cd) --- modules/bindbackend/bindbackend2.cc | 17 ++++++++--------- modules/bindbackend/bindbackend2.hh | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/modules/bindbackend/bindbackend2.cc b/modules/bindbackend/bindbackend2.cc index 3baf25ebb4..e88a93208c 100644 --- a/modules/bindbackend/bindbackend2.cc +++ b/modules/bindbackend/bindbackend2.cc @@ -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(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!"<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< 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 -- 2.47.2