]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2185] Add and use a RdataPimplHolder instead of auto_ptr
authorMukund Sivaraman <muks@isc.org>
Fri, 7 Feb 2014 13:00:50 +0000 (18:30 +0530)
committerMukund Sivaraman <muks@isc.org>
Fri, 7 Feb 2014 13:02:22 +0000 (18:32 +0530)
src/lib/dns/rdata/generic/tlsa_52.cc
src/lib/dns/rdata_pimpl_holder.h [new file with mode: 0644]

index fdf3bc32d3acd7c931af5d040c0cfdbbfe7d77ec..a896e8d47f64ae2de0d4b37470f4fd3485d9865e 100644 (file)
@@ -24,6 +24,7 @@
 #include <dns/messagerenderer.h>
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
+#include <dns/rdata_pimpl_holder.h>
 
 using namespace std;
 using boost::lexical_cast;
@@ -126,10 +127,10 @@ TLSA::constructFromLexer(MasterLexer& lexer) {
 TLSA::TLSA(const string& tlsa_str) :
     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 TLSAImpl that constructFromLexer() returns.
-    std::auto_ptr<TLSAImpl> impl_ptr(NULL);
+    // We use a smart pointer here because if there is an exception in
+    // this constructor, the destructor is not called and there could be
+    // leak of the TLSAImpl that constructFromLexer() returns.
+    RdataPimplHolder<TLSAImpl> impl_ptr;
 
     try {
         std::istringstream ss(tlsa_str);
diff --git a/src/lib/dns/rdata_pimpl_holder.h b/src/lib/dns/rdata_pimpl_holder.h
new file mode 100644 (file)
index 0000000..4564405
--- /dev/null
@@ -0,0 +1,58 @@
+// Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef DNS_RDATA_PIMPL_HOLDER_H
+#define DNS_RDATA_PIMPL_HOLDER_H 1
+
+#include <boost/noncopyable.hpp>
+
+namespace isc {
+namespace dns {
+namespace rdata {
+
+template <typename T>
+class RdataPimplHolder : boost::noncopyable {
+public:
+    RdataPimplHolder(T* obj = NULL) :
+        obj_(obj)
+    {}
+
+    ~RdataPimplHolder() {
+        delete obj_;
+    }
+
+    void reset(T* obj = NULL) {
+        delete obj_;
+        obj_ = obj;
+    }
+
+    T* get() {
+        return (obj_);
+    }
+
+    T* release() {
+        T* obj = obj_;
+        obj_ = NULL;
+        return (obj);
+    }
+
+private:
+    T* obj_;
+};
+
+} // namespace rdata
+} // namespace dns
+} // namespace isc
+
+#endif // DNS_RDATA_PIMPL_HOLDER_H