From 48096cf069e5166b9312ea68709bf22e5cb2f252 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 23 Jun 2016 10:40:01 +0200 Subject: [PATCH] rec: Use a ptr instead of a temporary vector for `dq policyTags` --- pdns/lua-recursor4.cc | 26 ++++++++++++-------------- pdns/lua-recursor4.hh | 2 +- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index 84ad7d0e7..f3b9ace73 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -343,18 +343,22 @@ RecursorLua4::RecursorLua4(const std::string& fname) d_lw->registerFunction("getRecords", &DNSQuestion::getRecords); d_lw->registerFunction("setRecords", &DNSQuestion::setRecords); - d_lw->registerFunction("addPolicyTag", [](DNSQuestion& dq, const std::string& tag) { dq.policyTags.push_back(tag); }); + d_lw->registerFunction("addPolicyTag", [](DNSQuestion& dq, const std::string& tag) { if (dq.policyTags) { dq.policyTags->push_back(tag); } }); d_lw->registerFunction >&)>("setPolicyTags", [](DNSQuestion& dq, const std::vector >& tags) { - dq.policyTags.clear(); - for (const auto& tag : tags) { - dq.policyTags.push_back(tag.second); + if (dq.policyTags) { + dq.policyTags->clear(); + for (const auto& tag : tags) { + dq.policyTags->push_back(tag.second); + } } }); d_lw->registerFunction >(DNSQuestion::*)()>("getPolicyTags", [](const DNSQuestion& dq) { std::vector > ret; - int count = 1; - for (const auto& tag : dq.policyTags) { - ret.push_back({count++, tag}); + if (dq.policyTags) { + int count = 1; + for (const auto& tag : *dq.policyTags) { + ret.push_back({count++, tag}); + } } return ret; }); @@ -512,16 +516,10 @@ bool RecursorLua4::genhook(luacall_t& func, const ComboAddress& remote,const Com dq->tag = tag; dq->ednsOptions = ednsOpts; dq->isTcp = isTcp; - if (policyTags) { - dq->policyTags = *policyTags; - } + dq->policyTags = policyTags; bool handled=func(dq); if(variable) *variable |= dq->variable; // could still be set to indicate this *name* is variable, even if not 'handled' - if (policyTags) { // same - *policyTags = dq->policyTags; - } - if(handled) { loop:; ret=dq->rcode; diff --git a/pdns/lua-recursor4.hh b/pdns/lua-recursor4.hh index f168cd8a0..cbf808784 100644 --- a/pdns/lua-recursor4.hh +++ b/pdns/lua-recursor4.hh @@ -67,7 +67,7 @@ private: DNSName followupName; string appliedPolicy; - std::vector policyTags; + std::vector* policyTags; bool isTcp; }; -- 2.40.0