From: Mukund Sivaraman Date: Fri, 7 Feb 2014 13:00:50 +0000 (+0530) Subject: [2185] Add and use a RdataPimplHolder instead of auto_ptr X-Git-Tag: bind10-1.2.0beta1-release~41^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9ac39be69c035539d8bca28d3a5e6dd5d0d2ef19;p=thirdparty%2Fkea.git [2185] Add and use a RdataPimplHolder instead of auto_ptr --- diff --git a/src/lib/dns/rdata/generic/tlsa_52.cc b/src/lib/dns/rdata/generic/tlsa_52.cc index fdf3bc32d3..a896e8d47f 100644 --- a/src/lib/dns/rdata/generic/tlsa_52.cc +++ b/src/lib/dns/rdata/generic/tlsa_52.cc @@ -24,6 +24,7 @@ #include #include #include +#include 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 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 + // a leak of the TLSAImpl that constructFromLexer() returns. + RdataPimplHolder 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 index 0000000000..456440525d --- /dev/null +++ b/src/lib/dns/rdata_pimpl_holder.h @@ -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 + +namespace isc { +namespace dns { +namespace rdata { + +template +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