Fix memory leaks and enable LeakSanitizer
Change-Id: I00c87432398b9bec663e16068a6641c6ca48dc1c
diff --git a/src/validator/certificate-fetcher-ndns-appcert.cpp b/src/validator/certificate-fetcher-ndns-appcert.cpp
index 99e7f21..e451e96 100644
--- a/src/validator/certificate-fetcher-ndns-appcert.cpp
+++ b/src/validator/certificate-fetcher-ndns-appcert.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.
@@ -69,12 +69,11 @@
const ValidationContinuation& continueValidation)
{
m_validator->validate(data,
- [=] (const Data& data) {
- onValidationSuccessCallback(data, certRequest, state, continueValidation);
+ [=] (const Data& d) {
+ onValidationSuccessCallback(d, certRequest, state, continueValidation);
},
- [=] (const Data& data,
- const security::v2::ValidationError& errStr) {
- onValidationFailCallback(errStr, certRequest, state, continueValidation);
+ [=] (const Data&, const security::v2::ValidationError& err) {
+ onValidationFailCallback(err, certRequest, state, continueValidation);
});
}
@@ -84,6 +83,7 @@
const shared_ptr<security::v2::ValidationState>& state,
const ValidationContinuation& continueValidation)
{
+ state->removeTag<IterativeQueryTag>();
state->fail({security::v2::ValidationError::Code::CANNOT_RETRIEVE_CERT, "Cannot fetch certificate due to " +
errMsg + " `" + certRequest->interest.getName().toUri() + "`"});
}
@@ -94,10 +94,12 @@
const shared_ptr<security::v2::ValidationState>& state,
const ValidationContinuation& continueValidation)
{
+ state->removeTag<IterativeQueryTag>();
+
if (data.getContentType() == NDNS_NACK) {
- state->fail({security::v2::ValidationError::Code::CANNOT_RETRIEVE_CERT, "Cannot fetch certificate: get a Nack "
- "in query `" + certRequest->interest.getName().toUri() + "`"});
- return;
+ return state->fail({security::v2::ValidationError::Code::CANNOT_RETRIEVE_CERT,
+ "Cannot fetch certificate: got Nack for query `" +
+ certRequest->interest.getName().toUri() + "`"});
}
Certificate cert;
@@ -105,9 +107,10 @@
cert = Certificate(data.getContent().blockFromValue());
}
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);
}
@@ -117,6 +120,7 @@
const shared_ptr<security::v2::ValidationState>& state,
const ValidationContinuation& continueValidation)
{
+ state->removeTag<IterativeQueryTag>();
state->fail({security::v2::ValidationError::Code::CANNOT_RETRIEVE_CERT,
"Cannot fetch certificate due to NDNS validation error: " +
err.getInfo() + " `" + certRequest->interest.getName().toUri() + "`"});
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() + "`"});
}
}