aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/hicn
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2019-10-31 15:01:29 +0000
committerMauro Sardara <msardara@cisco.com>2019-10-31 15:14:44 +0000
commitc570e74384a63b88d38d7697be435dd8de130ac8 (patch)
tree0abeb2fcd3d058155a37f31e1b9b23a89c1ab78d /libtransport/src/hicn
parentfc6dfe9f7ee02834ae1e6f56e0aaee36ac3e88dd (diff)
[HICN-371] Solve memory leaks in libtransport.
Signed-off-by: Mauro Sardara <msardara@cisco.com> Change-Id: I654843c3361c7bdb4b160f2441f08e8d91e97384 Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'libtransport/src/hicn')
-rw-r--r--libtransport/src/hicn/transport/core/hicn_forwarder_interface.cc2
-rw-r--r--libtransport/src/hicn/transport/core/portal.h24
-rw-r--r--libtransport/src/hicn/transport/utils/object_pool.h9
3 files changed, 25 insertions, 10 deletions
diff --git a/libtransport/src/hicn/transport/core/hicn_forwarder_interface.cc b/libtransport/src/hicn/transport/core/hicn_forwarder_interface.cc
index 33a37f540..7047a3a67 100644
--- a/libtransport/src/hicn/transport/core/hicn_forwarder_interface.cc
+++ b/libtransport/src/hicn/transport/core/hicn_forwarder_interface.cc
@@ -63,7 +63,7 @@ void fillCommandHeader(CommandHeader *header) {
RouteToSelfCommand createCommandRoute(std::unique_ptr<sockaddr> &&addr,
uint8_t prefix_length) {
- RouteToSelfCommand command;
+ RouteToSelfCommand command = {0};
// check and set IP address
if (addr->sa_family == AF_INET) {
diff --git a/libtransport/src/hicn/transport/core/portal.h b/libtransport/src/hicn/transport/core/portal.h
index 5796308b4..b2614d361 100644
--- a/libtransport/src/hicn/transport/core/portal.h
+++ b/libtransport/src/hicn/transport/core/portal.h
@@ -312,10 +312,10 @@ class Portal {
Portal(asio::io_service &io_service)
: io_service_(io_service),
+ packet_pool_(io_service),
app_name_("libtransport_application"),
consumer_callback_(nullptr),
producer_callback_(nullptr),
- packet_pool_(io_service),
connector_(std::bind(&Portal::processIncomingMessages, this,
std::placeholders::_1),
std::bind(&Portal::setLocalRoutes, this), io_service_,
@@ -419,10 +419,13 @@ class Portal {
this, std::placeholders::_1, hash)));
auto it = pending_interest_hash_table_.find(hash);
- if(it != pending_interest_hash_table_.end()){
+ if (it != pending_interest_hash_table_.end()) {
it->second->cancelTimer();
+
+ // Get reference to interest packet in order to have it destroyed.
+ auto _int = it->second->getInterest();
it->second = std::move(pending_interest);
- }else{
+ } else {
pending_interest_hash_table_[hash] = std::move(pending_interest);
}
}
@@ -562,6 +565,10 @@ class Portal {
TRANSPORT_ALWAYS_INLINE void doClear() {
for (auto &pend_interest : pending_interest_hash_table_) {
pend_interest.second->cancelTimer();
+
+ // Get interest packet from pending interest and do nothing with it. It
+ // will get destroyed as it goes out of scope.
+ auto _int = pend_interest.second->getInterest();
}
pending_interest_hash_table_.clear();
@@ -641,13 +648,14 @@ class Portal {
PendingInterest::Ptr interest_ptr = std::move(it->second);
pending_interest_hash_table_.erase(it);
interest_ptr->cancelTimer();
+ auto _int = interest_ptr->getInterest();
if (interest_ptr->getOnDataCallback() != UNSET_CALLBACK) {
- interest_ptr->on_content_object_callback_(
- std::move(interest_ptr->getInterest()), std::move(content_object));
+ interest_ptr->on_content_object_callback_(std::move(_int),
+ std::move(content_object));
} else if (consumer_callback_) {
- consumer_callback_->onContentObject(
- std::move(interest_ptr->getInterest()), std::move(content_object));
+ consumer_callback_->onContentObject(std::move(_int),
+ std::move(content_object));
}
} else {
TRANSPORT_LOGD("No pending interests for current content (%s)",
@@ -668,6 +676,7 @@ class Portal {
private:
asio::io_service &io_service_;
asio::io_service internal_io_service_;
+ portal_details::Pool packet_pool_;
std::string app_name_;
@@ -677,7 +686,6 @@ class Portal {
ConsumerCallback *consumer_callback_;
ProducerCallback *producer_callback_;
- portal_details::Pool packet_pool_;
portal_details::HandlerMemory async_callback_memory_;
typename ForwarderInt::ConnectorType connector_;
diff --git a/libtransport/src/hicn/transport/utils/object_pool.h b/libtransport/src/hicn/transport/utils/object_pool.h
index e34730e81..e8f837753 100644
--- a/libtransport/src/hicn/transport/utils/object_pool.h
+++ b/libtransport/src/hicn/transport/utils/object_pool.h
@@ -47,7 +47,12 @@ class ObjectPool {
ObjectPool() : destructor_(false) {}
- ~ObjectPool() { destructor_ = true; }
+ ~ObjectPool() {
+ destructor_ = true;
+ for (auto &ptr : object_pool_) {
+ ptr.reset();
+ }
+ }
std::pair<bool, Ptr> get() {
if (object_pool_.empty()) {
@@ -65,6 +70,8 @@ class ObjectPool {
if (TRANSPORT_EXPECT_TRUE(!destructor_)) {
object_pool_.emplace_back(makePtr(object));
+ } else {
+ delete object;
}
}