BIND 10 trac2426, updated. 659fb323f0b7fdd279cc1c36b0f5fe6526a0994e [2426] Fix leak of GenericImpl object when an exception is thrown

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Jan 14 12:15:27 UTC 2014


The branch, trac2426 has been updated
       via  659fb323f0b7fdd279cc1c36b0f5fe6526a0994e (commit)
      from  4976235a26688d12d2c2a51f13ef66dc38ff9ee9 (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 659fb323f0b7fdd279cc1c36b0f5fe6526a0994e
Author: Mukund Sivaraman <muks at isc.org>
Date:   Tue Jan 14 17:40:46 2014 +0530

    [2426] Fix leak of GenericImpl object when an exception is thrown

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

Summary of changes:
 src/lib/dns/rdata.cc |   21 +++++++++++++++------
 src/lib/dns/rdata.h  |    2 +-
 2 files changed, 16 insertions(+), 7 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/rdata.cc b/src/lib/dns/rdata.cc
index cdd03c1..4f7962c 100644
--- a/src/lib/dns/rdata.cc
+++ b/src/lib/dns/rdata.cc
@@ -212,7 +212,7 @@ Generic::Generic(isc::util::InputBuffer& buffer, size_t rdata_len) {
     impl_ = new GenericImpl(data);
 }
 
-void
+GenericImpl*
 Generic::constructFromLexer(MasterLexer& lexer) {
     const MasterToken& token = lexer.getNextToken(MasterToken::STRING);
     if (token.getString() != "\\#") {
@@ -268,16 +268,23 @@ Generic::constructFromLexer(MasterLexer& lexer) {
                   << data.size() << " vs. " << rdlen);
     }
 
-    impl_ = new GenericImpl(data);
+    return (new GenericImpl(data));
 }
 
-Generic::Generic(const std::string& rdata_string) {
+Generic::Generic(const std::string& rdata_string) :
+    impl_(NULL)
+{
+    // We use auto_ptr here because if there is an exception in this
+    // constructor, the destructor is not called and there could be a
+    // leak of the GenericImpl that constructFromLexer() returns.
+    std::auto_ptr<GenericImpl> impl_ptr(NULL);
+
     try {
         std::istringstream ss(rdata_string);
         MasterLexer lexer;
         lexer.pushSource(ss);
 
-        constructFromLexer(lexer);
+        impl_ptr.reset(constructFromLexer(lexer));
 
         if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
             isc_throw(InvalidRdataText, "extra input text for unknown RDATA: "
@@ -287,13 +294,15 @@ Generic::Generic(const std::string& rdata_string) {
         isc_throw(InvalidRdataText, "Failed to construct unknown RDATA "
                   "from '" << rdata_string << "': " << ex.what());
     }
+
+    impl_ = impl_ptr.release();
 }
 
 Generic::Generic(MasterLexer& lexer, const Name*,
                  MasterLoader::Options,
-                 MasterLoaderCallbacks&)
+                 MasterLoaderCallbacks&) :
+    impl_(constructFromLexer(lexer))
 {
-    constructFromLexer(lexer);
 }
 
 Generic::~Generic() {
diff --git a/src/lib/dns/rdata.h b/src/lib/dns/rdata.h
index 01ce7b3..5468e26 100644
--- a/src/lib/dns/rdata.h
+++ b/src/lib/dns/rdata.h
@@ -378,7 +378,7 @@ public:
     //@}
 
 private:
-    void constructFromLexer(MasterLexer& lexer);
+    GenericImpl* constructFromLexer(MasterLexer& lexer);
 
     GenericImpl* impl_;
 };



More information about the bind10-changes mailing list