- Fixed a memory leak in s1ap_paging. The static instance was not getting freed.

- Rewrite the singleton to self manage its lifetime.
master
faluco 4 years ago committed by faluco
parent f0d651ae8e
commit b5b726ed48

@ -33,19 +33,18 @@ class mme;
class s1ap_paging
{
s1ap_paging() = default;
public:
static s1ap_paging* m_instance;
static s1ap_paging* get_instance(void);
static void cleanup(void);
void init(void);
virtual ~s1ap_paging() = default;
static s1ap_paging* get_instance();
void init();
// Packing/unpacking helper functions
bool send_paging(uint64_t imsi, uint16_t erab_to_setup);
private:
s1ap_paging();
virtual ~s1ap_paging();
mme* m_mme;
s1ap* m_s1ap;
srslte::log_filter* m_s1ap_log;

@ -27,40 +27,13 @@
namespace srsepc {
s1ap_paging* s1ap_paging::m_instance = NULL;
pthread_mutex_t s1ap_paging_instance_mutex = PTHREAD_MUTEX_INITIALIZER;
s1ap_paging::s1ap_paging()
{
return;
}
s1ap_paging::~s1ap_paging()
{
return;
}
s1ap_paging* s1ap_paging::get_instance(void)
{
pthread_mutex_lock(&s1ap_paging_instance_mutex);
if (NULL == m_instance) {
m_instance = new s1ap_paging();
}
pthread_mutex_unlock(&s1ap_paging_instance_mutex);
return (m_instance);
}
void s1ap_paging::cleanup(void)
s1ap_paging* s1ap_paging::get_instance()
{
pthread_mutex_lock(&s1ap_paging_instance_mutex);
if (NULL != m_instance) {
delete m_instance;
m_instance = NULL;
}
pthread_mutex_unlock(&s1ap_paging_instance_mutex);
static std::unique_ptr<s1ap_paging> m_instance = std::unique_ptr<s1ap_paging>(new s1ap_paging);
return m_instance.get();
}
void s1ap_paging::init(void)
void s1ap_paging::init()
{
m_s1ap = s1ap::get_instance();
m_mme = mme::get_instance();
@ -80,7 +53,7 @@ bool s1ap_paging::send_paging(uint64_t imsi, uint16_t erab_to_setup)
// Getting UE NAS Context
nas* nas_ctx = m_s1ap->find_nas_ctx_from_imsi(imsi);
if (nas_ctx == NULL) {
if (nas_ctx == nullptr) {
m_s1ap_log->error("Could not find UE to page NAS context\n");
return false;
}

Loading…
Cancel
Save