Commit 785ade58 authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[2387] Fix leaks

parent 85655172
......@@ -70,12 +70,14 @@ struct DNSKEYImpl {
DNSKEY::DNSKEY(const std::string& dnskey_str) :
impl_(NULL)
{
std::auto_ptr<DNSKEYImpl> impl_ptr(NULL);
try {
std::istringstream ss(dnskey_str);
MasterLexer lexer;
lexer.pushSource(ss);
constructFromLexer(lexer);
impl_ptr.reset(constructFromLexer(lexer));
if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
isc_throw(InvalidRdataText,
......@@ -86,9 +88,13 @@ DNSKEY::DNSKEY(const std::string& dnskey_str) :
"Failed to construct DNSKEY from '" << dnskey_str << "': "
<< ex.what());
}
impl_ = impl_ptr.release();
}
DNSKEY::DNSKEY(InputBuffer& buffer, size_t rdata_len) {
DNSKEY::DNSKEY(InputBuffer& buffer, size_t rdata_len) :
impl_(NULL)
{
if (rdata_len < 4) {
isc_throw(InvalidRdataLength, "DNSKEY too short: " << rdata_len);
}
......@@ -131,10 +137,10 @@ DNSKEY::DNSKEY(MasterLexer& lexer, const Name*,
MasterLoader::Options, MasterLoaderCallbacks&) :
impl_(NULL)
{
constructFromLexer(lexer);
impl_ = constructFromLexer(lexer);
}
void
DNSKEYImpl*
DNSKEY::constructFromLexer(MasterLexer& lexer) {
const uint32_t flags = lexer.getNextToken(MasterToken::NUMBER).getNumber();
if (flags > 0xffff) {
......@@ -183,7 +189,7 @@ DNSKEY::constructFromLexer(MasterLexer& lexer) {
decodeBase64(keydata_str, keydata);
}
impl_ = new DNSKEYImpl(flags, protocol, algorithm, keydata);
return (new DNSKEYImpl(flags, protocol, algorithm, keydata));
}
DNSKEY::DNSKEY(const DNSKEY& source) :
......
......@@ -54,7 +54,7 @@ public:
uint8_t getAlgorithm() const;
private:
void constructFromLexer(isc::dns::MasterLexer& lexer);
DNSKEYImpl* constructFromLexer(isc::dns::MasterLexer& lexer);
DNSKEYImpl* impl_;
};
......
......@@ -85,12 +85,14 @@ struct NSEC3Impl {
NSEC3::NSEC3(const std::string& nsec3_str) :
impl_(NULL)
{
std::auto_ptr<NSEC3Impl> impl_ptr(NULL);
try {
std::istringstream ss(nsec3_str);
MasterLexer lexer;
lexer.pushSource(ss);
constructFromLexer(lexer);
impl_ptr.reset(constructFromLexer(lexer));
if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
isc_throw(InvalidRdataText,
......@@ -101,6 +103,8 @@ NSEC3::NSEC3(const std::string& nsec3_str) :
"Failed to construct NSEC3 from '" << nsec3_str << "': "
<< ex.what());
}
impl_ = impl_ptr.release();
}
/// \brief Constructor with a context of MasterLexer.
......@@ -122,10 +126,10 @@ NSEC3::NSEC3(MasterLexer& lexer, const Name*, MasterLoader::Options,
MasterLoaderCallbacks&) :
impl_(NULL)
{
constructFromLexer(lexer);
impl_ = constructFromLexer(lexer);
}
void
NSEC3Impl*
NSEC3::constructFromLexer(MasterLexer& lexer) {
vector<uint8_t> salt;
const ParseNSEC3ParamResult params =
......@@ -147,11 +151,13 @@ NSEC3::constructFromLexer(MasterLexer& lexer) {
vector<uint8_t> typebits;
// For NSEC3 empty bitmap is possible and allowed.
buildBitmapsFromLexer("NSEC3", lexer, typebits, true);
impl_ = new NSEC3Impl(params.algorithm, params.flags, params.iterations,
salt, next, typebits);
return (new NSEC3Impl(params.algorithm, params.flags, params.iterations,
salt, next, typebits));
}
NSEC3::NSEC3(InputBuffer& buffer, size_t rdata_len) {
NSEC3::NSEC3(InputBuffer& buffer, size_t rdata_len) :
impl_(NULL)
{
vector<uint8_t> salt;
const ParseNSEC3ParamResult params =
parseNSEC3ParamWire("NSEC3", buffer, rdata_len, salt);
......
......@@ -48,7 +48,7 @@ public:
const std::vector<uint8_t>& getNext() const;
private:
void constructFromLexer(isc::dns::MasterLexer& lexer);
NSEC3Impl* constructFromLexer(isc::dns::MasterLexer& lexer);
NSEC3Impl* impl_;
};
......
......@@ -64,12 +64,14 @@ struct NSEC3PARAMImpl {
NSEC3PARAM::NSEC3PARAM(const std::string& nsec3param_str) :
impl_(NULL)
{
std::auto_ptr<NSEC3PARAMImpl> impl_ptr(NULL);
try {
std::istringstream ss(nsec3param_str);
MasterLexer lexer;
lexer.pushSource(ss);
constructFromLexer(lexer);
impl_ptr.reset(constructFromLexer(lexer));
if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
isc_throw(InvalidRdataText,
......@@ -80,6 +82,8 @@ NSEC3PARAM::NSEC3PARAM(const std::string& nsec3param_str) :
"Failed to construct NSEC3PARAM from '" << nsec3param_str
<< "': " << ex.what());
}
impl_ = impl_ptr.release();
}
/// \brief Constructor with a context of MasterLexer.
......@@ -101,20 +105,22 @@ NSEC3PARAM::NSEC3PARAM(MasterLexer& lexer, const Name*, MasterLoader::Options,
MasterLoaderCallbacks&) :
impl_(NULL)
{
constructFromLexer(lexer);
impl_ = constructFromLexer(lexer);
}
void
NSEC3PARAMImpl*
NSEC3PARAM::constructFromLexer(MasterLexer& lexer) {
vector<uint8_t> salt;
const ParseNSEC3ParamResult params =
parseNSEC3ParamFromLexer("NSEC3PARAM", lexer, salt);
impl_ = new NSEC3PARAMImpl(params.algorithm, params.flags,
params.iterations, salt);
return (new NSEC3PARAMImpl(params.algorithm, params.flags,
params.iterations, salt));
}
NSEC3PARAM::NSEC3PARAM(InputBuffer& buffer, size_t rdata_len) {
NSEC3PARAM::NSEC3PARAM(InputBuffer& buffer, size_t rdata_len) :
impl_(NULL)
{
vector<uint8_t> salt;
const ParseNSEC3ParamResult params =
parseNSEC3ParamWire("NSEC3PARAM", buffer, rdata_len, salt);
......
......@@ -50,7 +50,7 @@ public:
const std::vector<uint8_t>& getSalt() const;
private:
void constructFromLexer(isc::dns::MasterLexer& lexer);
NSEC3PARAMImpl* constructFromLexer(isc::dns::MasterLexer& lexer);
NSEC3PARAMImpl* impl_;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment