- 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 class s1ap_paging
{ {
s1ap_paging() = default;
public: public:
static s1ap_paging* m_instance; virtual ~s1ap_paging() = default;
static s1ap_paging* get_instance(void);
static void cleanup(void); static s1ap_paging* get_instance();
void init(void); void init();
// Packing/unpacking helper functions // Packing/unpacking helper functions
bool send_paging(uint64_t imsi, uint16_t erab_to_setup); bool send_paging(uint64_t imsi, uint16_t erab_to_setup);
private: private:
s1ap_paging();
virtual ~s1ap_paging();
mme* m_mme; mme* m_mme;
s1ap* m_s1ap; s1ap* m_s1ap;
srslte::log_filter* m_s1ap_log; srslte::log_filter* m_s1ap_log;

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

Loading…
Cancel
Save