BIND 10 trac1747, updated. 5c681eddd0ab1819dc7fadd692cadf98991a4d64 [1747] added RAII-lookalike cleaner object to Query::process()

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Mar 14 14:23:46 UTC 2012


The branch, trac1747 has been updated
       via  5c681eddd0ab1819dc7fadd692cadf98991a4d64 (commit)
      from  83474d8f558bebb4be0b0f75e843fab993ee3713 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5c681eddd0ab1819dc7fadd692cadf98991a4d64
Author: Jelte Jansen <jelte at isc.org>
Date:   Wed Mar 14 15:23:18 2012 +0100

    [1747] added RAII-lookalike cleaner object to Query::process()

-----------------------------------------------------------------------

Summary of changes:
 src/bin/auth/query.cc |   21 ++++++++++++++-------
 src/bin/auth/query.h  |   25 ++++++++++++++++++-------
 2 files changed, 32 insertions(+), 14 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/auth/query.cc b/src/bin/auth/query.cc
index 424d05b..db1223d 100644
--- a/src/bin/auth/query.cc
+++ b/src/bin/auth/query.cc
@@ -90,6 +90,7 @@ getAdditional(const Name& qname, RRType qtype,
         results.push_back(*it);
     }
 }
+
 }
 
 namespace isc {
@@ -355,11 +356,9 @@ Query::process(datasrc::DataSourceClient& datasrc_client,
                const isc::dns::Name& qname, const isc::dns::RRType& qtype,
                isc::dns::Message& response, bool dnssec)
 {
-    // First a bit of house cleaning
-    // The call to reset() could in theory be ommitted, but
-    // seems prudent, just in case a previous process() left
-    // data in here.
-    reset();
+    // Set up the cleaner object so internal pointers and vectors are
+    // always reset after scope leaves this method
+    QueryCleaner cleaner(*this);
 
     // Set up query parameters for the rest of the (internal) methods
     initialize(datasrc_client, qname, qtype, response, dnssec);
@@ -556,12 +555,20 @@ void
 Query::createResponse() {
     for_each(answers_.begin(), answers_.end(),
              RRsetInserter(*response_, Message::SECTION_ANSWER, dnssec_));
-    answers_.clear();
     for_each(authorities_.begin(), authorities_.end(),
              RRsetInserter(*response_, Message::SECTION_AUTHORITY, dnssec_));
-    authorities_.clear();
     for_each(additionals_.begin(), additionals_.end(),
              RRsetInserter(*response_, Message::SECTION_ADDITIONAL, dnssec_));
+}
+
+void
+Query::reset() {
+    datasrc_client_ = NULL;
+    qname_ = NULL;
+    qtype_ = NULL;
+    response_ = NULL;
+    answers_.clear();
+    authorities_.clear();
     additionals_.clear();
 }
 
diff --git a/src/bin/auth/query.h b/src/bin/auth/query.h
index 062925c..e295d91 100644
--- a/src/bin/auth/query.h
+++ b/src/bin/auth/query.h
@@ -264,13 +264,23 @@ private:
     /// After they are added, the vectors are cleared.
     void createResponse();
 
-    /// \brief Resets any partly built response data
-    void
-    reset() {
-        answers_.clear();
-        authorities_.clear();
-        additionals_.clear();
-    }
+    /// \brief Resets any partly built response data, and internal pointers
+    ///
+    /// Called by the QueryCleaner object upon its destruction
+    void reset();
+
+    /// \brief Internal class used for cleanup of Query members
+    ///
+    /// The process() call creates an object of this class, which
+    /// upon its destruction, calls Query::reset(), so that outside
+    /// of single calls to process(), the query state is always clean.
+    class QueryCleaner {
+    public:
+        QueryCleaner(isc::auth::Query& query) : query_(query) {}
+        ~QueryCleaner() { query_.reset(); }
+    private:
+        isc::auth::Query& query_;
+    };
 
 public:
     /// Default constructor.
@@ -287,6 +297,7 @@ public:
         additionals_.reserve(RESERVE_RRSETS);
     }
 
+
     /// Process the query.
     ///
     /// This method first identifies the zone that best matches the query



More information about the bind10-changes mailing list