Commit 772db6b7 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Deconstruction/memory leak

parent e524ce7b
......@@ -41,11 +41,3 @@ void free_wrapper(void **ptr) {
}
}
//------------------------------------------------------------------------------
void bdestroy_wrapper(bstring *b) {
if ((b) && (*b)) {
bdestroy(*b);
*b = NULL;
}
}
......@@ -28,9 +28,7 @@
#ifndef FILE_DYNAMIC_MEMORY_CHECK_SEEN
#define FILE_DYNAMIC_MEMORY_CHECK_SEEN
# include "bstrlib.h"
void free_wrapper(void **ptr) __attribute__ ((hot));
void bdestroy_wrapper(bstring *b);
#endif /* FILE_DYNAMIC_MEMORY_CHECK_SEEN */
......@@ -23,6 +23,11 @@
#include "logger.hpp"
#include "conversions.hpp"
extern "C" {
#include "dynamic_memory_check.h"
}
bool mime_parser::parse(const std::string &str) {
std::string CRLF = "\r\n";
Logger::nrf_app().debug("Parsing the message with Simple Parser");
......@@ -91,9 +96,7 @@ unsigned char* mime_parser::format_string_as_hex(const std::string &str) {
printf("\n");
#endif
//free memory
//free_wrapper((void**) &data);
free(data);
data = NULL;
free_wrapper((void**) &data);
return data_hex;
}
......
......@@ -47,7 +47,9 @@ nrf_client *nrf_client_inst = nullptr;
//------------------------------------------------------------------------------
nrf_app::nrf_app(const std::string &config_file, nrf_event &ev)
: m_event_sub(ev) {
: m_event_sub(ev),
m_instance_id2nrf_profile(),
m_instance_id2nrf_subscription() {
Logger::nrf_app().startup("Starting...");
try {
......@@ -114,7 +116,7 @@ void nrf_app::handle_register_nf_instance(
add_nf_profile(nf_instance_id, sn);
Logger::nrf_app().debug("Added/Updated NF Profile to the DB");
// heartbeart management for this NF profile
// Heartbeart management for this NF profile
// get current time
uint64_t ms = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
......@@ -122,7 +124,6 @@ void nrf_app::handle_register_nf_instance(
sn.get()->subscribe_task_tick(ms);
// Notify NF status change event
// m_event_sub.nf_status_change(p); //from subscription
m_event_sub.nf_status_registered(nf_instance_id); // from nrf_app
// display the info
......@@ -553,8 +554,9 @@ void nrf_app::subscribe_nf_status() {
//------------------------------------------------------------------------------
void nrf_app::subscribe_nf_status_registered() {
Logger::nrf_app().debug("Subscribe to NF status registered");
m_event_sub.subscribe_nf_status_registered(
bs2::connection c = m_event_sub.subscribe_nf_status_registered(
boost::bind(&nrf_app::handle_nf_status_registered, this, _1));
connections.push_back(c);
}
//------------------------------------------------------------------------------
......@@ -582,8 +584,9 @@ void nrf_app::handle_nf_status_registered(const std::string &profile_id) {
//------------------------------------------------------------------------------
void nrf_app::subscribe_nf_status_deregistered() {
Logger::nrf_app().debug("Subscribe to NF status deregistered");
m_event_sub.subscribe_nf_status_deregistered(
bs2::connection c = m_event_sub.subscribe_nf_status_deregistered(
boost::bind(&nrf_app::handle_nf_status_deregistered, this, _1));
connections.push_back(c);
}
//------------------------------------------------------------------------------
......@@ -599,8 +602,9 @@ void nrf_app::handle_nf_status_deregistered(const std::string &profile_id) {
//------------------------------------------------------------------------------
void nrf_app::subscribe_nf_status_profile_changed() {
Logger::nrf_app().debug("Subscribe to NF status profile changed");
m_event_sub.subscribe_nf_status_profile_changed(
bs2::connection c = m_event_sub.subscribe_nf_status_profile_changed(
boost::bind(&nrf_app::handle_nf_status_profile_changed, this, _1));
connections.push_back(c);
}
//------------------------------------------------------------------------------
......
......@@ -53,6 +53,14 @@ class nrf_app {
nrf_app(nrf_app const&) = delete;
void operator=(nrf_app const&) = delete;
virtual ~nrf_app() {
Logger::nrf_app().debug("Delete NRF_APP instance...");
for (auto i: connections) {
if (i.connected()) i.disconnect();
}
}
/*
* Handle a Register NF Instance request
* @param [const std::string &] nf_instance_id: Instance ID
......@@ -228,9 +236,9 @@ class nrf_app {
std::map<std::string, std::shared_ptr<nrf_subscription>> instance_id2nrf_subscription;
mutable std::shared_mutex m_instance_id2nrf_subscription;
nrf_event& m_event_sub;
util::uint_generator<uint32_t> evsub_id_generator;
std::vector<bs2::connection> connections;
};
}
}
......
......@@ -3,9 +3,9 @@
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
......@@ -28,50 +28,48 @@
*/
#include "nrf_event.hpp"
#include <iostream>
#include "nrf_app.hpp"
#include "nrf_event_sig.hpp"
#include <iostream>
using namespace oai::nrf::app;
//------------------------------------------------------------------------------
bs2::connection nrf_event::subscribe_task_tick(
const task_sig_t::slot_type& sig, uint64_t period, uint64_t start) {
bs2::connection nrf_event::subscribe_task_tick(const task_sig_t::slot_type &sig,
uint64_t period,
uint64_t start) {
/* Wrap the actual callback in a lambda. The latter checks whether the
* current time is after start time, and ensures that the callback is only
* called every X ms with X being the period time. This way, it is possible
* to register to be notified every X ms instead of every ms, which provides
* greater freedom to implementations. */
auto f = [period,start,sig] (uint64_t t)
{
if (t >= start && (t - start) % period == 0) sig(t);
};
auto f = [period, start, sig](uint64_t t) {
if (t >= start && (t - start) % period == 0) sig(t);
};
return task_tick.connect(f);
}
//------------------------------------------------------------------------------
bs2::connection nrf_event::subscribe_task_tick_extended(
const task_sig_t::extended_slot_type& sig, uint64_t period, uint64_t start) {
const task_sig_t::extended_slot_type &sig, uint64_t period,
uint64_t start) {
/* Wrap the actual callback in a lambda. The latter checks whether the
* current time is after start time, and ensures that the callback is only
* called every X ms with X being the period time. This way, it is possible
* to register to be notified every X ms instead of every ms, which provides
* greater freedom to implementations. */
auto f = [period,start,sig] (const bs2::connection& c, uint64_t t)
{
if (t >= start && (t - start) % period == 0) sig(c, t);
};
auto f = [period, start, sig](const bs2::connection &c, uint64_t t) {
if (t >= start && (t - start) % period == 0) sig(c, t);
};
return task_tick.connect_extended(f);
}
//------------------------------------------------------------------------------
bs2::connection nrf_event::subscribe_nf_status_change(
const nf_status_change_sig_t::slot_type &sig) {
return nf_status_change.connect(sig);
}
//------------------------------------------------------------------------------
bs2::connection nrf_event::subscribe_nf_status_registered(
const nf_status_sig_t::slot_type &sig) {
......@@ -89,8 +87,3 @@ bs2::connection nrf_event::subscribe_nf_status_profile_changed(
const nf_status_sig_t::slot_type &sig) {
return nf_status_profile_changed.connect(sig);
}
......@@ -97,8 +97,8 @@ class nrf_profile : public std::enable_shared_from_this<nrf_profile> {
nrf_profile(nrf_profile &b) = delete;
virtual ~nrf_profile() {
Logger::nrf_app().debug("Delete instance...");
task_connection.disconnect();
Logger::nrf_app().debug("Delete NRF Profile instance...");
if (task_connection.connected()) task_connection.disconnect();
}
/*
......
......@@ -48,8 +48,8 @@ class nrf_subscription {
};
nrf_subscription(nrf_subscription const &) = delete;
virtual ~nrf_subscription() {
Logger::nrf_app().debug("Delete instance...");
ev_connection.disconnect();
Logger::nrf_app().debug("Delete NRF Subscription instance...");
if (ev_connection.connected()) ev_connection.disconnect();
}
void operator=(nrf_subscription const &) = delete;
......
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