From 2bbc9eb09944b4b573994f6c33f15c8ab4e52b02 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 19 Oct 2021 19:34:16 -0700 Subject: [PATCH] use make_unique instead of new Signed-off-by: Rosen Penev --- modules/bindbackend/bindbackend2.cc | 2 +- modules/geoipbackend/geoipinterface-dat.cc | 2 +- modules/geoipbackend/geoipinterface-mmdb.cc | 2 +- modules/gmysqlbackend/smysql.cc | 2 +- modules/godbcbackend/sodbc.cc | 2 +- modules/gpgsqlbackend/spgsql.cc | 2 +- modules/pipebackend/pipebackend.cc | 8 +++--- modules/remotebackend/httpconnector.cc | 2 +- modules/remotebackend/remotebackend.cc | 8 +++--- modules/tinydnsbackend/tinydnsbackend.cc | 8 +++--- pdns/comfun.cc | 2 +- pdns/common_startup.cc | 2 +- pdns/dbdnsseckeeper.cc | 2 +- pdns/dnsdist-lua.cc | 16 +++++------ pdns/dnsdist-rings.hh | 2 +- pdns/dnsdist.cc | 6 ++-- pdns/dnsdistdist/dnsdist-kvs.cc | 2 +- pdns/dnsdistdist/doh.cc | 4 +-- pdns/dnsdistdist/test-dnsdistkvs_cc.cc | 6 ++-- pdns/dnsdistdist/test-dnsdistnghttp2_cc.cc | 2 +- pdns/dnsrecords.hh | 6 ++-- pdns/dnsscope.cc | 4 +-- pdns/dnstcpbench.cc | 2 +- pdns/dnswasher.cc | 4 +-- pdns/ixfrdist-web.cc | 4 +-- pdns/lua-base4.cc | 2 +- pdns/lua-record.cc | 6 ++-- pdns/lua-recursor4.cc | 8 +++--- pdns/nsec3dig.cc | 2 +- pdns/packethandler.cc | 4 +-- pdns/pdns_recursor.cc | 31 ++++++++++----------- pdns/pkcs11signers.cc | 14 +++++----- pdns/receiver.cc | 4 +-- pdns/recursordist/stable-bloom.hh | 2 +- pdns/recursordist/test-rec-zonetocache.cc | 2 +- pdns/recursordist/test-syncres_cc.cc | 14 +++++----- pdns/recursordist/test-syncres_cc4.cc | 4 +-- pdns/resolver.cc | 2 +- pdns/saxfr.cc | 2 +- pdns/sodiumsigners.cc | 8 +++--- pdns/ssqlite3.cc | 2 +- pdns/sstuff.hh | 2 +- pdns/syncres.hh | 8 +++--- pdns/tcpiohandler.cc | 4 +-- pdns/toysdig.cc | 2 +- pdns/ws-auth.cc | 2 +- 46 files changed, 113 insertions(+), 114 deletions(-) diff --git a/modules/bindbackend/bindbackend2.cc b/modules/bindbackend/bindbackend2.cc index 1443681a39b7..216b1b9cb3e2 100644 --- a/modules/bindbackend/bindbackend2.cc +++ b/modules/bindbackend/bindbackend2.cc @@ -224,7 +224,7 @@ bool Bind2Backend::startTransaction(const DNSName& qname, int id) return false; } - d_of = std::unique_ptr(new ofstream(d_transaction_tmpname.c_str())); + d_of = std::make_unique(d_transaction_tmpname); if (!*d_of) { unlink(d_transaction_tmpname.c_str()); close(fd); diff --git a/modules/geoipbackend/geoipinterface-dat.cc b/modules/geoipbackend/geoipinterface-dat.cc index 5a5a05dac4fb..75b11ccc58f8 100644 --- a/modules/geoipbackend/geoipinterface-dat.cc +++ b/modules/geoipbackend/geoipinterface-dat.cc @@ -476,7 +476,7 @@ unique_ptr GeoIPInterface::makeDATInterface(const string& fname, const auto& opt = opts.find("mode"); if (opt != opts.end()) mode = opt->second; - return unique_ptr(new GeoIPInterfaceDAT(fname, mode)); + return std::make_unique(fname, mode); } #else diff --git a/modules/geoipbackend/geoipinterface-mmdb.cc b/modules/geoipbackend/geoipinterface-mmdb.cc index b8a11ef806a9..969d5abc5293 100644 --- a/modules/geoipbackend/geoipinterface-mmdb.cc +++ b/modules/geoipbackend/geoipinterface-mmdb.cc @@ -283,7 +283,7 @@ unique_ptr GeoIPInterface::makeMMDBInterface(const string& fname const auto& opt_lang = opts.find("language"); if (opt_lang != opts.end()) language = opt_lang->second; - return unique_ptr(new GeoIPInterfaceMMDB(fname, mode, language)); + return std::make_unique(fname, mode, language); } #else diff --git a/modules/gmysqlbackend/smysql.cc b/modules/gmysqlbackend/smysql.cc index b3ce048f19d8..8b3c80bbc556 100644 --- a/modules/gmysqlbackend/smysql.cc +++ b/modules/gmysqlbackend/smysql.cc @@ -552,7 +552,7 @@ SSqlException SMySQL::sPerrorException(const string& reason) std::unique_ptr SMySQL::prepare(const string& query, int nparams) { - return std::unique_ptr(new SMySQLStatement(query, s_dolog, nparams, &d_db)); + return std::make_unique(query, s_dolog, nparams, &d_db); } void SMySQL::execute(const string& query) diff --git a/modules/godbcbackend/sodbc.cc b/modules/godbcbackend/sodbc.cc index 2985557a770f..a1a7ad0255bf 100644 --- a/modules/godbcbackend/sodbc.cc +++ b/modules/godbcbackend/sodbc.cc @@ -479,7 +479,7 @@ SSqlException SODBC::sPerrorException(const std::string& reason) std::unique_ptr SODBC::prepare(const string& query, int nparams) { - return std::unique_ptr(new SODBCStatement(query, m_log, nparams, m_connection)); + return std::make_unique(query, m_log, nparams, m_connection); } void SODBC::startTransaction() diff --git a/modules/gpgsqlbackend/spgsql.cc b/modules/gpgsqlbackend/spgsql.cc index c40347fd6768..996d72dbc7aa 100644 --- a/modules/gpgsqlbackend/spgsql.cc +++ b/modules/gpgsqlbackend/spgsql.cc @@ -375,7 +375,7 @@ void SPgSQL::execute(const string& query) std::unique_ptr SPgSQL::prepare(const string& query, int nparams) { d_nstatements++; - return std::unique_ptr(new SPgSQLStatement(query, s_dolog, nparams, this, d_nstatements)); + return std::make_unique(query, s_dolog, nparams, this, d_nstatements); } void SPgSQL::startTransaction() diff --git a/modules/pipebackend/pipebackend.cc b/modules/pipebackend/pipebackend.cc index b540a4c308e0..5773adcf0bcc 100644 --- a/modules/pipebackend/pipebackend.cc +++ b/modules/pipebackend/pipebackend.cc @@ -66,10 +66,10 @@ void CoWrapper::launch() throw ArgException("pipe-command is not specified"); if (isUnixSocket(d_command)) { - d_cp = std::unique_ptr(new UnixRemote(d_command, d_timeout)); + d_cp = std::make_unique(d_command, d_timeout); } else { - auto coprocess = std::unique_ptr(new CoProcess(d_command, d_timeout)); + auto coprocess = std::make_unique(d_command, d_timeout); coprocess->launch(); d_cp = std::move(coprocess); } @@ -130,11 +130,11 @@ void PipeBackend::launch() try { if (!getArg("regex").empty()) { - d_regex = std::unique_ptr(new Regex(getArg("regex"))); + d_regex = std::make_unique(getArg("regex")); } d_regexstr = getArg("regex"); d_abiVersion = getArgAsNum("abi-version"); - d_coproc = unique_ptr(new CoWrapper(getArg("command"), getArgAsNum("timeout"), getArgAsNum("abi-version"))); + d_coproc = std::make_unique(getArg("command"), getArgAsNum("timeout"), getArgAsNum("abi-version")); } catch (const ArgException& A) { diff --git a/modules/remotebackend/httpconnector.cc b/modules/remotebackend/httpconnector.cc index 99c0676e0edd..2c21d85c095f 100644 --- a/modules/remotebackend/httpconnector.cc +++ b/modules/remotebackend/httpconnector.cc @@ -385,7 +385,7 @@ int HTTPConnector::send_message(const Json& input) while (gAddrPtr) { try { - d_socket = std::unique_ptr(new Socket(gAddrPtr->ai_family, gAddrPtr->ai_socktype, gAddrPtr->ai_protocol)); + d_socket = std::make_unique(gAddrPtr->ai_family, gAddrPtr->ai_socktype, gAddrPtr->ai_protocol); d_addr.setSockaddr(gAddrPtr->ai_addr, gAddrPtr->ai_addrlen); d_socket->connect(d_addr); d_socket->setNonBlocking(); diff --git a/modules/remotebackend/remotebackend.cc b/modules/remotebackend/remotebackend.cc index 764deee33d37..380d956442de 100644 --- a/modules/remotebackend/remotebackend.cc +++ b/modules/remotebackend/remotebackend.cc @@ -165,20 +165,20 @@ int RemoteBackend::build() // connectors know what they are doing if (type == "unix") { - this->connector = std::unique_ptr(new UnixsocketConnector(options)); + this->connector = std::make_unique(options); } else if (type == "http") { - this->connector = std::unique_ptr(new HTTPConnector(options)); + this->connector = std::make_unique(options); } else if (type == "zeromq") { #ifdef REMOTEBACKEND_ZEROMQ - this->connector = std::unique_ptr(new ZeroMQConnector(options)); + this->connector = std::make_unique(options); #else throw PDNSException("Invalid connection string: zeromq connector support not enabled. Recompile with --enable-remotebackend-zeromq"); #endif } else if (type == "pipe") { - this->connector = std::unique_ptr(new PipeConnector(options)); + this->connector = std::make_unique(options); } else { throw PDNSException("Invalid connection string: unknown connector"); diff --git a/modules/tinydnsbackend/tinydnsbackend.cc b/modules/tinydnsbackend/tinydnsbackend.cc index aa6cf959d827..9292d3803cf2 100644 --- a/modules/tinydnsbackend/tinydnsbackend.cc +++ b/modules/tinydnsbackend/tinydnsbackend.cc @@ -58,7 +58,7 @@ vector TinyDNSBackend::getLocations() for (int i = 4; i >= 0; i--) { string searchkey(key, i + 2); try { - auto reader = std::unique_ptr(new CDB(getArg("dbfile"))); + auto reader = std::make_unique(getArg("dbfile")); ret = reader->findall(searchkey); } catch (const std::exception& e) { @@ -158,7 +158,7 @@ void TinyDNSBackend::getAllDomains(vector* domains, bool getSerial, d_dnspacket = NULL; try { - d_cdbReader = std::unique_ptr(new CDB(getArg("dbfile"))); + d_cdbReader = std::make_unique(getArg("dbfile")); } catch (const std::exception& e) { g_log << Logger::Error << e.what() << endl; @@ -201,7 +201,7 @@ bool TinyDNSBackend::list(const DNSName& target, int domain_id, bool include_dis d_isGetDomains = false; string key = target.toDNSStringLC(); try { - d_cdbReader = std::unique_ptr(new CDB(getArg("dbfile"))); + d_cdbReader = std::make_unique(getArg("dbfile")); } catch (const std::exception& e) { g_log << Logger::Error << e.what() << endl; @@ -231,7 +231,7 @@ void TinyDNSBackend::lookup(const QType& qtype, const DNSName& qdomain, int zone d_qtype = qtype; try { - d_cdbReader = std::unique_ptr(new CDB(getArg("dbfile"))); + d_cdbReader = std::make_unique(getArg("dbfile")); } catch (const std::exception& e) { g_log << Logger::Error << e.what() << endl; diff --git a/pdns/comfun.cc b/pdns/comfun.cc index eaabb9e09b62..01a1fff2cc3f 100644 --- a/pdns/comfun.cc +++ b/pdns/comfun.cc @@ -429,7 +429,7 @@ try } else if(mode=="scan-ns") { ifstream ns(string(argv[2])+".nameservers"); - g_powerdns = std::unique_ptr(new ofstream(string(argv[2])+".powerdns")); + g_powerdns = std::make_unique(string(argv[2]) + ".powerdns"); string line; int count=0; vector parts; diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index c80607b54180..261de435b1bf 100644 --- a/pdns/common_startup.cc +++ b/pdns/common_startup.cc @@ -647,7 +647,7 @@ void mainthread() Utility::dropUserPrivs(newuid); if(::arg().mustDo("resolver")){ - DP=std::unique_ptr(new DNSProxy(::arg()["resolver"])); + DP = std::make_unique(::arg()["resolver"]); DP->go(); } diff --git a/pdns/dbdnsseckeeper.cc b/pdns/dbdnsseckeeper.cc index 385e30208900..44dce8f7f313 100644 --- a/pdns/dbdnsseckeeper.cc +++ b/pdns/dbdnsseckeeper.cc @@ -741,7 +741,7 @@ bool DNSSECKeeper::rectifyZone(const DNSName& zone, string& error, string& info, } // We don't have a *full* Ueberbackend, just a key-only one. // Let's create one and use it - b = std::unique_ptr(new UeberBackend()); + b = std::make_unique(); B = b.get(); } diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 8671f54ca0f9..0e2a29e1d541 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -700,8 +700,8 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) } // only works pre-startup, so no sync necessary - g_frontends.push_back(std::unique_ptr(new ClientState(loc, false, reusePort, tcpFastOpenQueueSize, interface, cpus))); - auto tcpCS = std::unique_ptr(new ClientState(loc, true, reusePort, tcpFastOpenQueueSize, interface, cpus)); + g_frontends.push_back(std::make_unique(loc, false, reusePort, tcpFastOpenQueueSize, interface, cpus)); + auto tcpCS = std::make_unique(loc, true, reusePort, tcpFastOpenQueueSize, interface, cpus); if (tcpListenQueueSize > 0) { tcpCS->tcpListenQueueSize = tcpListenQueueSize; } @@ -740,8 +740,8 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) try { ComboAddress loc(addr, 53); // only works pre-startup, so no sync necessary - g_frontends.push_back(std::unique_ptr(new ClientState(loc, false, reusePort, tcpFastOpenQueueSize, interface, cpus))); - auto tcpCS = std::unique_ptr(new ClientState(loc, true, reusePort, tcpFastOpenQueueSize, interface, cpus)); + g_frontends.push_back(std::make_unique(loc, false, reusePort, tcpFastOpenQueueSize, interface, cpus)); + auto tcpCS = std::make_unique(loc, true, reusePort, tcpFastOpenQueueSize, interface, cpus); if (tcpListenQueueSize > 0) { tcpCS->tcpListenQueueSize = tcpListenQueueSize; } @@ -1517,13 +1517,13 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) auto ctx = std::make_shared(providerName, certKeys); /* UDP */ - auto cs = std::unique_ptr(new ClientState(ComboAddress(addr, 443), false, reusePort, tcpFastOpenQueueSize, interface, cpus)); + auto cs = std::make_unique(ComboAddress(addr, 443), false, reusePort, tcpFastOpenQueueSize, interface, cpus); cs->dnscryptCtx = ctx; g_dnsCryptLocals.push_back(ctx); g_frontends.push_back(std::move(cs)); /* TCP */ - cs = std::unique_ptr(new ClientState(ComboAddress(addr, 443), true, reusePort, tcpFastOpenQueueSize, interface, cpus)); + cs = std::make_unique(ComboAddress(addr, 443), true, reusePort, tcpFastOpenQueueSize, interface, cpus); cs->dnscryptCtx = ctx; if (tcpListenQueueSize > 0) { cs->tcpListenQueueSize = tcpListenQueueSize; @@ -2335,7 +2335,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) parseTLSConfig(frontend->d_tlsConfig, "addDOHLocal", vars); } g_dohlocals.push_back(frontend); - auto cs = std::unique_ptr(new ClientState(frontend->d_local, true, reusePort, tcpFastOpenQueueSize, interface, cpus)); + auto cs = std::make_unique(frontend->d_local, true, reusePort, tcpFastOpenQueueSize, interface, cpus); cs->dohFrontend = frontend; if (tcpListenQueueSize > 0) { cs->tcpListenQueueSize = tcpListenQueueSize; @@ -2527,7 +2527,7 @@ ::vector>> keyFiles) { #endif } // only works pre-startup, so no sync necessary - auto cs = std::unique_ptr(new ClientState(frontend->d_addr, true, reusePort, tcpFastOpenQueueSize, interface, cpus)); + auto cs = std::make_unique(frontend->d_addr, true, reusePort, tcpFastOpenQueueSize, interface, cpus); cs->tlsFrontend = frontend; if (tcpListenQueueSize > 0) { cs->tcpListenQueueSize = tcpListenQueueSize; diff --git a/pdns/dnsdist-rings.hh b/pdns/dnsdist-rings.hh index adff0b6ac945..0ee4f22be90c 100644 --- a/pdns/dnsdist-rings.hh +++ b/pdns/dnsdist-rings.hh @@ -84,7 +84,7 @@ struct Rings { /* resize all the rings */ for (auto& shard : d_shards) { - shard = std::unique_ptr(new Shard()); + shard = std::make_unique(); shard->queryRing.lock()->set_capacity(newCapacity / numberOfShards); shard->respRing.lock()->set_capacity(newCapacity / numberOfShards); } diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 94286c507d93..a82247f4c254 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -1594,9 +1594,9 @@ static void MultipleMessagesUDPClientThread(ClientState* cs, LocalHolders& holde }; const size_t vectSize = g_udpVectorSize; - auto recvData = std::unique_ptr(new MMReceiver[vectSize]); - auto msgVec = std::unique_ptr(new struct mmsghdr[vectSize]); - auto outMsgVec = std::unique_ptr(new struct mmsghdr[vectSize]); + auto recvData = std::make_unique(vectSize); + auto msgVec = std::make_unique(vectSize); + auto outMsgVec = std::make_unique(vectSize); /* the actual buffer is larger because: - we may have to add EDNS and/or ECS diff --git a/pdns/dnsdistdist/dnsdist-kvs.cc b/pdns/dnsdistdist/dnsdist-kvs.cc index ead0e1096553..c2b6272ac4a0 100644 --- a/pdns/dnsdistdist/dnsdist-kvs.cc +++ b/pdns/dnsdistdist/dnsdist-kvs.cc @@ -190,7 +190,7 @@ CDBKVStore::~CDBKVStore() { bool CDBKVStore::reload(const struct stat& st) { - auto newCDB = std::unique_ptr(new CDB(d_fname)); + auto newCDB = std::make_unique(d_fname); { *(d_cdb.write_lock()) = std::move(newCDB); } diff --git a/pdns/dnsdistdist/doh.cc b/pdns/dnsdistdist/doh.cc index 0b46a1a89bf6..c1d83c2543ad 100644 --- a/pdns/dnsdistdist/doh.cc +++ b/pdns/dnsdistdist/doh.cc @@ -823,7 +823,7 @@ static void doh_dispatch_query(DOHServerConfig* dsc, h2o_handler_t* self, h2o_re uint16_t qtype; DNSName qname(reinterpret_cast(query.data()), query.size(), sizeof(dnsheader), false, &qtype); - auto du = std::unique_ptr(new DOHUnit); + auto du = std::make_unique(); du->dsc = dsc; du->req = req; du->ids.origDest = local; @@ -1440,7 +1440,7 @@ static void setupTLSContext(DOHAcceptContext& acceptCtx, auto ctx = libssl_init_server_context(tlsConfig, acceptCtx.d_ocspResponses); if (tlsConfig.d_enableTickets && tlsConfig.d_numberOfTicketsKeys > 0) { - acceptCtx.d_ticketKeys = std::unique_ptr(new OpenSSLTLSTicketKeysRing(tlsConfig.d_numberOfTicketsKeys)); + acceptCtx.d_ticketKeys = std::make_unique(tlsConfig.d_numberOfTicketsKeys); SSL_CTX_set_tlsext_ticket_key_cb(ctx.get(), &ticket_key_callback); libssl_set_ticket_key_callback_data(ctx.get(), &acceptCtx); } diff --git a/pdns/dnsdistdist/test-dnsdistkvs_cc.cc b/pdns/dnsdistdist/test-dnsdistkvs_cc.cc index bc013bd0892e..cc21b1f3b28f 100644 --- a/pdns/dnsdistdist/test-dnsdistkvs_cc.cc +++ b/pdns/dnsdistdist/test-dnsdistkvs_cc.cc @@ -354,11 +354,11 @@ BOOST_AUTO_TEST_CASE(test_LMDB) { transaction->commit(); } - auto lmdb = std::unique_ptr(new LMDBKVStore(dbPath, "db-name")); + std::unique_ptr lmdb = std::make_unique(dbPath, "db-name"); doKVSChecks(lmdb, lc, rem, dq, plaintextDomain); lmdb.reset(); - lmdb = std::unique_ptr(new LMDBKVStore(dbPath, "range-db-name")); + lmdb = std::make_unique(dbPath, "range-db-name"); doKVSRangeChecks(lmdb); /* std::string value; @@ -414,7 +414,7 @@ BOOST_AUTO_TEST_CASE(test_CDB) { writer.close(); } - auto cdb = std::unique_ptr(new CDBKVStore(db, 0)); + std::unique_ptr cdb = std::make_unique(db, 0); doKVSChecks(cdb, lc, rem, dq, plaintextDomain); /* diff --git a/pdns/dnsdistdist/test-dnsdistnghttp2_cc.cc b/pdns/dnsdistdist/test-dnsdistnghttp2_cc.cc index e26e0a907589..969fc7c98f46 100644 --- a/pdns/dnsdistdist/test-dnsdistnghttp2_cc.cc +++ b/pdns/dnsdistdist/test-dnsdistnghttp2_cc.cc @@ -664,7 +664,7 @@ struct TestFixture { s_steps.clear(); s_responses.clear(); - s_mplexer = std::unique_ptr(new MockupFDMultiplexer()); + s_mplexer = std::make_unique(); } ~TestFixture() { diff --git a/pdns/dnsrecords.hh b/pdns/dnsrecords.hh index 3a2f6d1fba78..7f0a057437a2 100644 --- a/pdns/dnsrecords.hh +++ b/pdns/dnsrecords.hh @@ -595,7 +595,7 @@ public: NSECBitmap(const NSECBitmap& rhs): d_set(rhs.d_set) { if (rhs.d_bitset) { - d_bitset = std::unique_ptr>(new std::bitset(*(rhs.d_bitset))); + d_bitset = std::make_unique>(*(rhs.d_bitset)); } } NSECBitmap& operator=(const NSECBitmap& rhs) @@ -603,7 +603,7 @@ public: d_set = rhs.d_set; if (rhs.d_bitset) { - d_bitset = std::unique_ptr>(new std::bitset(*(rhs.d_bitset))); + d_bitset = std::make_unique>(*(rhs.d_bitset)); } return *this; @@ -652,7 +652,7 @@ private: void migrateToBitSet() { - d_bitset = std::unique_ptr>(new std::bitset()); + d_bitset = std::make_unique>(); for (const auto& type : d_set) { d_bitset->set(type); } diff --git a/pdns/dnsscope.cc b/pdns/dnsscope.cc index 061e04a68c6a..dd6e2ca2cbd4 100644 --- a/pdns/dnsscope.cc +++ b/pdns/dnsscope.cc @@ -224,8 +224,8 @@ try PcapPacketReader pr(files[fno]); std::unique_ptr pw=nullptr; if(!g_vm["write-failures"].as().empty()) - pw=std::unique_ptr(new PcapPacketWriter(g_vm["write-failures"].as(), pr)); - + pw = std::make_unique(g_vm["write-failures"].as(), pr); + EDNSOpts edo; while(pr.getUDPPacket()) { diff --git a/pdns/dnstcpbench.cc b/pdns/dnstcpbench.cc index aa461ac18d96..51f1e8b3cefd 100644 --- a/pdns/dnstcpbench.cc +++ b/pdns/dnstcpbench.cc @@ -134,7 +134,7 @@ try throw PDNSException("tcp read failed"); len=ntohs(len); - std::unique_ptr creply(new char[len]); + auto creply = std::make_unique(len); int n=0; int numread; while(n make() { - return std::unique_ptr(new IPSeqObfuscator()); + return std::make_unique(); } uint32_t obf4(uint32_t orig) override @@ -133,7 +133,7 @@ class IPCipherObfuscator : public IPObfuscator {} static std::unique_ptr make(std::string key, bool decrypt) { - return std::unique_ptr(new IPCipherObfuscator(key, decrypt)); + return std::make_unique(key, decrypt); } uint32_t obf4(uint32_t orig) override diff --git a/pdns/ixfrdist-web.cc b/pdns/ixfrdist-web.cc index 91596a62d52c..efbde189b568 100644 --- a/pdns/ixfrdist-web.cc +++ b/pdns/ixfrdist-web.cc @@ -25,8 +25,8 @@ #include "iputils.hh" #include "ixfrdist-stats.hh" -IXFRDistWebServer::IXFRDistWebServer(const ComboAddress &listenAddress, const NetmaskGroup &acl, const string &loglevel) : - d_ws(std::unique_ptr(new WebServer(listenAddress.toString(), listenAddress.getPort()))) +IXFRDistWebServer::IXFRDistWebServer(const ComboAddress& listenAddress, const NetmaskGroup& acl, const string& loglevel) : + d_ws(std::make_unique(listenAddress.toString(), listenAddress.getPort())) { d_ws->setACL(acl); d_ws->setLogLevel(loglevel); diff --git a/pdns/lua-base4.cc b/pdns/lua-base4.cc index efbf71257a27..8c8d46fc9402 100644 --- a/pdns/lua-base4.cc +++ b/pdns/lua-base4.cc @@ -37,7 +37,7 @@ void BaseLua4::loadString(const std::string &script) { void BaseLua4::getFeatures(Features &) { } void BaseLua4::prepareContext() { - d_lw = std::unique_ptr(new LuaContext); + d_lw = std::make_unique(); // lua features available Features features; diff --git a/pdns/lua-record.cc b/pdns/lua-record.cc index 2c75a15979dc..dfa118a6fbaf 100644 --- a/pdns/lua-record.cc +++ b/pdns/lua-record.cc @@ -229,7 +229,7 @@ class IsUpOracle bool IsUpOracle::isUp(const CheckDesc& cd) { if (!d_checkerThread) { - d_checkerThread = std::unique_ptr(new std::thread(&IsUpOracle::checkThread, this)); + d_checkerThread = std::make_unique([this] { return checkThread(); }); } time_t now = time(nullptr); { @@ -248,7 +248,7 @@ bool IsUpOracle::isUp(const CheckDesc& cd) auto statuses = d_statuses.write_lock(); // Make sure we don't insert new entry twice now we have the lock if (statuses->find(cd) == statuses->end()) { - (*statuses)[cd] = std::unique_ptr(new CheckState{now}); + (*statuses)[cd] = std::make_unique(now); } } return false; @@ -972,7 +972,7 @@ std::vector> luaSynth(const std::string& code, cons LuaContext& lua = *s_LUA->getLua(); - s_lua_record_ctx = std::unique_ptr(new lua_record_ctx_t()); + s_lua_record_ctx = std::make_unique(); s_lua_record_ctx->qname = query; s_lua_record_ctx->zone = zone; s_lua_record_ctx->zoneid = zoneid; diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index b77d98418a23..841eb5558507 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -728,7 +728,7 @@ RecursorLua4::~RecursorLua4() {} const char* pdns_ffi_param_get_qname(pdns_ffi_param_t* ref) { if (!ref->qnameStr) { - ref->qnameStr = std::unique_ptr(new std::string(ref->params.qname.toStringNoDot())); + ref->qnameStr = std::make_unique(ref->params.qname.toStringNoDot()); } return ref->qnameStr->c_str(); @@ -749,7 +749,7 @@ uint16_t pdns_ffi_param_get_qtype(const pdns_ffi_param_t* ref) const char* pdns_ffi_param_get_remote(pdns_ffi_param_t* ref) { if (!ref->remoteStr) { - ref->remoteStr = std::unique_ptr(new std::string(ref->params.remote.toString())); + ref->remoteStr = std::make_unique(ref->params.remote.toString()); } return ref->remoteStr->c_str(); @@ -780,7 +780,7 @@ uint16_t pdns_ffi_param_get_remote_port(const pdns_ffi_param_t* ref) const char* pdns_ffi_param_get_local(pdns_ffi_param_t* ref) { if (!ref->localStr) { - ref->localStr = std::unique_ptr(new std::string(ref->params.local.toString())); + ref->localStr = std::make_unique(ref->params.local.toString()); } return ref->localStr->c_str(); @@ -803,7 +803,7 @@ const char* pdns_ffi_param_get_edns_cs(pdns_ffi_param_t* ref) } if (!ref->ednssubnetStr) { - ref->ednssubnetStr = std::unique_ptr(new std::string(ref->params.ednssubnet.toStringNoMask())); + ref->ednssubnetStr = std::make_unique(ref->params.ednssubnet.toStringNoMask()); } return ref->ednssubnetStr->c_str(); diff --git a/pdns/nsec3dig.cc b/pdns/nsec3dig.cc index 1caf49ff5193..13dcdf057194 100644 --- a/pdns/nsec3dig.cc +++ b/pdns/nsec3dig.cc @@ -142,7 +142,7 @@ try throw PDNSException("tcp read failed"); len=ntohs(len); - std::unique_ptr creply(new char[len]); + auto creply = std::make_unique(len); int n=0; int numread; while(n(new AuthLua4()); + d_pdl = std::make_unique(); d_pdl->loadFile(fname); } fname = ::arg()["lua-dnsupdate-policy-script"]; @@ -86,7 +86,7 @@ PacketHandler::PacketHandler():B(s_programname), d_dk(&B) } else { - d_update_policy_lua = std::unique_ptr(new AuthLua4()); + d_update_policy_lua = std::make_unique(); d_update_policy_lua->loadFile(fname); } } diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 2070bd054a8e..39ba53896eb8 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -2733,7 +2733,7 @@ static void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var) conn->state = TCPConnection::BYTE0; std::unique_ptr dc; try { - dc=std::unique_ptr(new DNSComboWriter(conn->data, g_now)); + dc = std::make_unique(conn->data, g_now); } catch(const MOADNSException &mde) { g_stats.clientParseError++; @@ -3220,7 +3220,7 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr return 0; } - auto dc = std::unique_ptr(new DNSComboWriter(question, g_now, std::move(policyTags), std::move(data), std::move(records))); + auto dc = std::make_unique(question, g_now, std::move(policyTags), std::move(data), std::move(records)); dc->setSocket(fd); dc->d_tag=ctag; dc->d_qhash=qhash; @@ -5525,8 +5525,8 @@ try SyncRes tmp(g_now); // make sure it allocates tsstorage before we do anything, like primeHints or so.. SyncRes::setDomainMap(g_initialDomainMap); t_allowFrom = g_initialAllowFrom; - t_udpclientsocks = std::unique_ptr(new UDPClientSocks()); - t_tcpClientCounts = std::unique_ptr(new tcpClientCounts_t()); + t_udpclientsocks = std::make_unique(); + t_tcpClientCounts = std::make_unique(); if (threadInfo.isHandler) { if (!primeHints()) { @@ -5538,8 +5538,7 @@ try g_log<(new RecursorPacketCache()); - + t_packetCache = std::make_unique(); #ifdef NOD_ENABLED if (threadInfo.isWorker) @@ -5563,25 +5562,25 @@ try unsigned int ringsize=::arg().asNum("stats-ringbuffer-entries") / g_numWorkerThreads; if(ringsize) { - t_remotes = std::unique_ptr(new addrringbuf_t()); + t_remotes = std::make_unique(); if(g_weDistributeQueries) t_remotes->set_capacity(::arg().asNum("stats-ringbuffer-entries") / g_numDistributorThreads); else t_remotes->set_capacity(ringsize); - t_servfailremotes = std::unique_ptr(new addrringbuf_t()); + t_servfailremotes = std::make_unique(); t_servfailremotes->set_capacity(ringsize); - t_bogusremotes = std::unique_ptr(new addrringbuf_t()); + t_bogusremotes = std::make_unique(); t_bogusremotes->set_capacity(ringsize); - t_largeanswerremotes = std::unique_ptr(new addrringbuf_t()); + t_largeanswerremotes = std::make_unique(); t_largeanswerremotes->set_capacity(ringsize); - t_timeouts = std::unique_ptr(new addrringbuf_t()); + t_timeouts = std::make_unique(); t_timeouts->set_capacity(ringsize); - t_queryring = std::unique_ptr > >(new boost::circular_buffer >()); + t_queryring = std::make_unique>>(); t_queryring->set_capacity(ringsize); - t_servfailqueryring = std::unique_ptr > >(new boost::circular_buffer >()); + t_servfailqueryring = std::make_unique>>(); t_servfailqueryring->set_capacity(ringsize); - t_bogusqueryring = std::unique_ptr > >(new boost::circular_buffer >()); + t_bogusqueryring = std::make_unique>>(); t_bogusqueryring->set_capacity(ringsize); } MT = std::make_unique(::arg().asNum("stack-size")); @@ -6121,8 +6120,8 @@ int main(int argc, char **argv) cout<<::arg().helpstring(::arg()["help"])<(new MemRecursorCache(::arg().asNum("record-cache-shards"))); - g_negCache = std::unique_ptr(new NegCache(::arg().asNum("record-cache-shards"))); + g_recCache = std::make_unique(::arg().asNum("record-cache-shards")); + g_negCache = std::make_unique(::arg().asNum("record-cache-shards")); g_quiet=::arg().mustDo("quiet"); Logger::Urgency logUrgency = (Logger::Urgency)::arg().asNum("loglevel"); diff --git a/pdns/pkcs11signers.cc b/pdns/pkcs11signers.cc index 4d79d3a2f15c..3024fc435a72 100644 --- a/pdns/pkcs11signers.cc +++ b/pdns/pkcs11signers.cc @@ -151,7 +151,7 @@ class P11KitAttribute { // this bit is used for getting attribute from object // we provide a pointer for GetAttributeValue to write to CK_BYTE_PTR allocate(CK_ULONG amount) { - buffer = std::unique_ptr(new unsigned char[amount]); + buffer = std::make_unique(amount); buflen = amount; return buffer.get(); } @@ -249,7 +249,7 @@ class Pkcs11Slot { bool Login(const std::string& pin) { if (d_logged_in) return true; - std::unique_ptr uPin(new unsigned char[pin.size()]); + auto uPin = std::make_unique(pin.size()); memcpy(uPin.get(), pin.c_str(), pin.size()); d_err = d_functions->C_Login(this->d_session, CKU_USER, uPin.get(), pin.size()); memset(uPin.get(), 0, pin.size()); @@ -415,8 +415,8 @@ class Pkcs11Token { auto slot = d_slot->lock(); size_t k; - std::unique_ptr pubAttr(new CK_ATTRIBUTE[pubAttributes.size()]); - std::unique_ptr privAttr(new CK_ATTRIBUTE[privAttributes.size()]); + auto pubAttr = std::make_unique(pubAttributes.size()); + auto privAttr = std::make_unique(pubAttributes.size()); k = 0; for(P11KitAttribute& attribute : pubAttributes) { @@ -530,8 +530,8 @@ class Pkcs11Token { size_t k; unsigned long count; - std::unique_ptr handles(new CK_OBJECT_HANDLE[maxobjects]); - std::unique_ptr attr(new CK_ATTRIBUTE[attributes.size()]); + auto handles = std::make_unique(maxobjects); + auto attr = std::make_unique(attributes.size()); k = 0; for(const P11KitAttribute& attribute : attributes) { @@ -568,7 +568,7 @@ class Pkcs11Token { int GetAttributeValue2(Pkcs11Slot& slot, const CK_OBJECT_HANDLE& object, std::vector& attributes) { size_t k; - std::unique_ptr attr(new CK_ATTRIBUTE[attributes.size()]); + auto attr = std::make_unique(attributes.size()); k = 0; for(P11KitAttribute &attribute : attributes) { diff --git a/pdns/receiver.cc b/pdns/receiver.cc index d818ad5d6f9a..e5e67854d31e 100644 --- a/pdns/receiver.cc +++ b/pdns/receiver.cc @@ -583,8 +583,8 @@ int main(int argc, char **argv) if(::arg().mustDo("control-console")) dl=make_unique(); else - dl=std::unique_ptr(new DynListener(s_programname)); - + dl = std::make_unique(s_programname); + writePid(); } DynListener::registerFunc("SHOW",&DLShowHandler, "show a specific statistic or * to get a list", ""); diff --git a/pdns/recursordist/stable-bloom.hh b/pdns/recursordist/stable-bloom.hh index ee5c7b437584..3fc14cce8986 100644 --- a/pdns/recursordist/stable-bloom.hh +++ b/pdns/recursordist/stable-bloom.hh @@ -126,7 +126,7 @@ public: if (bitstr_len > 2 * 64 * 1024 * 1024U) { // twice the current size throw std::runtime_error("SBF: read failed (bitstr_len too big)"); } - unique_ptr bitcstr = make_unique(bitstr_len); + auto bitcstr = std::make_unique(bitstr_len); is.read(bitcstr.get(), bitstr_len); if (is.fail()) { throw std::runtime_error("SBF: read failed (file too short?)"); diff --git a/pdns/recursordist/test-rec-zonetocache.cc b/pdns/recursordist/test-rec-zonetocache.cc index d771674ada4d..3dde7d1237a6 100644 --- a/pdns/recursordist/test-rec-zonetocache.cc +++ b/pdns/recursordist/test-rec-zonetocache.cc @@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE(test_zonetocache) config.d_refreshPeriod = 0; // Start with a new, empty cache - g_recCache = std::unique_ptr(new MemRecursorCache()); + g_recCache = std::make_unique(); BOOST_CHECK_EQUAL(g_recCache->size(), 0U); RecZoneToCache::ZoneToCache(config, 0); unlink(temp); diff --git a/pdns/recursordist/test-syncres_cc.cc b/pdns/recursordist/test-syncres_cc.cc index a18e206d99c7..8836275b18b8 100644 --- a/pdns/recursordist/test-syncres_cc.cc +++ b/pdns/recursordist/test-syncres_cc.cc @@ -14,8 +14,8 @@ GlobalStateHolder g_xdnssec; GlobalStateHolder g_dontThrottleNames; GlobalStateHolder g_dontThrottleNetmasks; GlobalStateHolder g_DoTToAuthNames; -std::unique_ptr g_recCache{nullptr}; -std::unique_ptr g_negCache{nullptr}; +std::unique_ptr g_recCache; +std::unique_ptr g_negCache; unsigned int g_numThreads = 1; bool g_lowercaseOutgoing = false; @@ -82,9 +82,9 @@ bool primeHints(time_t now) { vector nsset; if (!g_recCache) - g_recCache = std::unique_ptr(new MemRecursorCache()); + g_recCache = std::make_unique(); if (!g_negCache) - g_negCache = std::unique_ptr(new NegCache()); + g_negCache = std::make_unique(); DNSRecord arr, aaaarr, nsrr; nsrr.d_name = g_rootdnsname; @@ -142,8 +142,8 @@ void initSR(bool debug) g_log.toConsole(Logger::Error); } - g_recCache = std::unique_ptr(new MemRecursorCache()); - g_negCache = std::unique_ptr(new NegCache()); + g_recCache = std::make_unique(); + g_negCache = std::make_unique(); SyncRes::s_maxqperq = 50; SyncRes::s_maxnsaddressqperq = 10; @@ -227,7 +227,7 @@ void initSR(std::unique_ptr& sr, bool dnssec, bool debug, time_t fakeNo initSR(debug); - sr = std::unique_ptr(new SyncRes(now)); + sr = std::make_unique(now); sr->setDoEDNS0(true); if (dnssec) { sr->setDoDNSSEC(dnssec); diff --git a/pdns/recursordist/test-syncres_cc4.cc b/pdns/recursordist/test-syncres_cc4.cc index e18b41f39ea5..23358d9bc8e7 100644 --- a/pdns/recursordist/test-syncres_cc4.cc +++ b/pdns/recursordist/test-syncres_cc4.cc @@ -927,8 +927,8 @@ BOOST_AUTO_TEST_CASE(test_dnssec_bogus_dnskey_doesnt_match_ds) /* === first without validation, then with (just-in-time validation) === */ /* clear the caches */ - g_recCache = std::unique_ptr(new MemRecursorCache()); - g_negCache = std::unique_ptr(new NegCache()); + g_recCache = std::make_unique(); + g_negCache = std::make_unique(); sr->setDNSSECValidationRequested(false); primeHints(); diff --git a/pdns/resolver.cc b/pdns/resolver.cc index 5cde2e88f344..6377008645d0 100644 --- a/pdns/resolver.cc +++ b/pdns/resolver.cc @@ -228,7 +228,7 @@ namespace pdns { bool Resolver::tryGetSOASerial(DNSName *domain, ComboAddress* remote, uint32_t *theirSerial, uint32_t *theirInception, uint32_t *theirExpire, uint16_t* id) { - auto fds = std::unique_ptr(new struct pollfd[locals.size()]); + auto fds = std::make_unique(locals.size()); size_t i = 0, k; int sock; diff --git a/pdns/saxfr.cc b/pdns/saxfr.cc index 20e677a9efb1..ef0761e5edd1 100644 --- a/pdns/saxfr.cc +++ b/pdns/saxfr.cc @@ -112,7 +112,7 @@ try throw PDNSException("tcp read failed"); len=ntohs(len); - std::unique_ptr creply(new char[len]); + auto creply = std::make_unique(len); int n=0; int numread; while(n seed(new unsigned char[crypto_sign_ed25519_SEEDBYTES]); + auto seed = std::make_unique(crypto_sign_ed25519_SEEDBYTES); memcpy(seed.get(), privateKey.c_str(), crypto_sign_ed25519_SEEDBYTES); crypto_sign_ed25519_seed_keypair(d_pubkey, d_seckey, seed.get()); @@ -106,7 +106,7 @@ void SodiumED25519DNSCryptoKeyEngine::fromPublicKeyString(const std::string& inp std::string SodiumED25519DNSCryptoKeyEngine::sign(const std::string& msg) const { unsigned long long smlen = msg.length() + crypto_sign_ed25519_BYTES; - std::unique_ptr sm(new unsigned char[smlen]); + auto sm = std::make_unique(smlen); crypto_sign_ed25519(sm.get(), &smlen, (const unsigned char*)msg.c_str(), msg.length(), d_seckey); @@ -119,12 +119,12 @@ bool SodiumED25519DNSCryptoKeyEngine::verify(const std::string& msg, const std:: return false; unsigned long long smlen = msg.length() + crypto_sign_ed25519_BYTES; - std::unique_ptr sm(new unsigned char[smlen]); + auto sm = std::make_unique(smlen); memcpy(sm.get(), signature.c_str(), crypto_sign_ed25519_BYTES); memcpy(sm.get() + crypto_sign_ed25519_BYTES, msg.c_str(), msg.length()); - std::unique_ptr m(new unsigned char[smlen]); + auto m = std::make_unique(smlen); return crypto_sign_ed25519_open(m.get(), &smlen, sm.get(), smlen, d_pubkey) == 0; } diff --git a/pdns/ssqlite3.cc b/pdns/ssqlite3.cc index 8602f162ff51..c2c96ebea7b8 100644 --- a/pdns/ssqlite3.cc +++ b/pdns/ssqlite3.cc @@ -229,7 +229,7 @@ SSQLite3::~SSQLite3() } std::unique_ptr SSQLite3::prepare(const string& query, int nparams __attribute__((unused))) { - return std::unique_ptr(new SSQLite3Statement(this, m_dolog, query)); + return std::make_unique(this, m_dolog, query); } void SSQLite3::execute(const string& query) { diff --git a/pdns/sstuff.hh b/pdns/sstuff.hh index 50a669bf8688..5b14e234e60c 100644 --- a/pdns/sstuff.hh +++ b/pdns/sstuff.hh @@ -99,7 +99,7 @@ public: throw NetworkError("Accepting a connection: "+stringerror()); } - return std::unique_ptr(new Socket(s)); + return std::make_unique(s); } //! Get remote address diff --git a/pdns/syncres.hh b/pdns/syncres.hh index d5b84f37ddb3..495dd5d33727 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -428,14 +428,14 @@ public: static void addDontQuery(const std::string& mask) { if (!s_dontQuery) - s_dontQuery = std::unique_ptr(new NetmaskGroup()); + s_dontQuery = std::make_unique(); s_dontQuery->addMask(mask); } static void addDontQuery(const Netmask& mask) { if (!s_dontQuery) - s_dontQuery = std::unique_ptr(new NetmaskGroup()); + s_dontQuery = std::make_unique(); s_dontQuery->addMask(mask); } @@ -906,8 +906,8 @@ private: ostringstream d_trace; shared_ptr d_pdl; boost::optional d_outgoingECSNetwork; - std::shared_ptr>> d_outgoingProtobufServers{nullptr}; - std::shared_ptr>> d_frameStreamServers{nullptr}; + std::shared_ptr>> d_outgoingProtobufServers; + std::shared_ptr>> d_frameStreamServers; boost::optional d_initialRequestId; asyncresolve_t d_asyncResolve{nullptr}; struct timeval d_now; diff --git a/pdns/tcpiohandler.cc b/pdns/tcpiohandler.cc index 85409655d4d1..05d7dbeac6e9 100644 --- a/pdns/tcpiohandler.cc +++ b/pdns/tcpiohandler.cc @@ -478,7 +478,7 @@ class OpenSSLTLSConnection: public TLSConnection void addNewTicket(SSL_SESSION* session) { - d_tlsSessions.push_back(std::unique_ptr(new OpenSSLSession(std::unique_ptr(session, SSL_SESSION_free)))); + d_tlsSessions.push_back(std::make_unique(std::unique_ptr(session, SSL_SESSION_free))); } static int s_tlsConnIndex; @@ -1019,7 +1019,7 @@ class GnuTLSConnection: public TLSConnection if (ret != GNUTLS_E_SUCCESS || sess.size <= 4) { throw std::runtime_error("Error getting GnuTLSSession: " + std::string(gnutls_strerror(ret))); } - conn->d_tlsSessions.push_back(std::unique_ptr(new GnuTLSSession(sess))); + conn->d_tlsSessions.push_back(std::make_unique(sess)); return 0; } diff --git a/pdns/toysdig.cc b/pdns/toysdig.cc index 7247531e66a3..80a63291c28c 100644 --- a/pdns/toysdig.cc +++ b/pdns/toysdig.cc @@ -56,7 +56,7 @@ class TCPResolver : public boost::noncopyable throw PDNSException("EOF on TCP read"); len=ntohs(len); - std::unique_ptr creply(new char[len]); + auto creply = std::make_unique(len); int n=0; int numread; while(n(new WebServer(arg()["webserver-address"], arg().asNum("webserver-port"))); + d_ws = std::make_unique(arg()["webserver-address"], arg().asNum("webserver-port")); d_ws->setApiKey(arg()["api-key"], arg().mustDo("webserver-hash-plaintext-credentials")); d_ws->setPassword(arg()["webserver-password"], arg().mustDo("webserver-hash-plaintext-credentials")); d_ws->setLogLevel(arg()["webserver-loglevel"]);