Fix memory leaks and enable LeakSanitizer
Change-Id: I00c87432398b9bec663e16068a6641c6ca48dc1c
diff --git a/src/validator/certificate-fetcher-ndns-cert.cpp b/src/validator/certificate-fetcher-ndns-cert.cpp
index b5a0b9f..bf64515 100644
--- a/src/validator/certificate-fetcher-ndns-cert.cpp
+++ b/src/validator/certificate-fetcher-ndns-cert.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California.
+ * Copyright (c) 2014-2019, Regents of the University of California.
*
* This file is part of NDNS (Named Data Networking Domain Name Service).
* See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -38,14 +38,14 @@
: m_face(face)
, m_nsCache(make_unique<InMemoryStorageFifo>(nsCacheSize))
, m_startComponentIndex(startComponentIndex)
-{}
+{
+}
void
CertificateFetcherNdnsCert::doFetch(const shared_ptr<security::v2::CertificateRequest>& certRequest,
const shared_ptr<security::v2::ValidationState>& state,
const ValidationContinuation& continueValidation)
{
- using IterativeQueryTag = SimpleTag<shared_ptr<IterativeQueryController>, 1086>;
const Name& key = certRequest->interest.getName();
Name domain = calculateDomain(key);
if (domain.size() == m_startComponentIndex) {
@@ -54,7 +54,7 @@
+ " is globally routable because startComponentIndex="
+ std::to_string(m_startComponentIndex),
certRequest, state, continueValidation);
- return ;
+ return;
}
auto query = std::make_shared<IterativeQueryController>(domain,
@@ -124,13 +124,13 @@
interestName.append(label::CERT_RR_TYPE);
Interest interest(interestName);
m_face.expressInterest(interest,
- [=] (const Interest& interest, const Data& data) {
+ [=] (const Interest&, const Data& data) {
dataCallback(data, certRequest, state, continueValidation);
},
- [=] (const Interest& interest, const lp::Nack& nack) {
+ [=] (const Interest&, const lp::Nack& nack) {
nackCallback(nack, certRequest, state, continueValidation);
},
- [=] (const Interest& interest) {
+ [=] (const Interest&) {
timeoutCallback(certRequest, state, continueValidation);
});
}
@@ -154,14 +154,17 @@
{
NDNS_LOG_DEBUG("Fetched certificate from network " << data.getName());
+ state->removeTag<IterativeQueryTag>();
+
Certificate cert;
try {
cert = Certificate(data);
}
catch (const ndn::tlv::Error& e) {
- return state->fail({security::v2::ValidationError::Code::MALFORMED_CERT, "Fetched a malformed certificate "
- "`" + data.getName().toUri() + "` (" + e.what() + ")"});
+ return state->fail({security::v2::ValidationError::Code::MALFORMED_CERT, "Fetched a malformed "
+ "certificate `" + data.getName().toUri() + "` (" + e.what() + ")"});
}
+
continueValidation(cert, state);
}
@@ -180,8 +183,9 @@
fetch(certRequest, state, continueValidation);
}
else {
- state->fail({security::v2::ValidationError::Code::CANNOT_RETRIEVE_CERT, "Cannot fetch certificate after all "
- "retries `" + certRequest->interest.getName().toUri() + "`"});
+ state->removeTag<IterativeQueryTag>();
+ state->fail({security::v2::ValidationError::Code::CANNOT_RETRIEVE_CERT, "Cannot fetch certificate "
+ "after all retries `" + certRequest->interest.getName().toUri() + "`"});
}
}
@@ -198,8 +202,9 @@
fetch(certRequest, state, continueValidation);
}
else {
- state->fail({security::v2::ValidationError::Code::CANNOT_RETRIEVE_CERT, "Cannot fetch certificate after all "
- "retries `" + certRequest->interest.getName().toUri() + "`"});
+ state->removeTag<IterativeQueryTag>();
+ state->fail({security::v2::ValidationError::Code::CANNOT_RETRIEVE_CERT, "Cannot fetch certificate "
+ "after all retries `" + certRequest->interest.getName().toUri() + "`"});
}
}