Module: kamailio
Branch: master
Commit: 91c5ca751799db4f25a28a495350cc97f7c2f390
URL:
https://github.com/kamailio/kamailio/commit/91c5ca751799db4f25a28a495350cc9…
Author: Aleksandar Yosifov <alexyosifov(a)gmail.com>
Committer: Aleksandar Yosifov <alexyosifov(a)gmail.com>
Date: 2019-08-02T15:13:20+03:00
ims_usrloc_pcscf: Fix problems with double mem free
- Add checks to avoid double memory free in
free_security() method.
Add api to get number of registered contacts.
---
Modified: src/modules/ims_usrloc_pcscf/pcontact.c
Modified: src/modules/ims_usrloc_pcscf/usrloc.c
Modified: src/modules/ims_usrloc_pcscf/usrloc.h
---
Diff:
https://github.com/kamailio/kamailio/commit/91c5ca751799db4f25a28a495350cc9…
Patch:
https://github.com/kamailio/kamailio/commit/91c5ca751799db4f25a28a495350cc9…
---
diff --git a/src/modules/ims_usrloc_pcscf/pcontact.c
b/src/modules/ims_usrloc_pcscf/pcontact.c
index 76297bf1d9..0d156d39c4 100644
--- a/src/modules/ims_usrloc_pcscf/pcontact.c
+++ b/src/modules/ims_usrloc_pcscf/pcontact.c
@@ -122,25 +122,29 @@ void free_security(security_t* _p)
if (!_p)
return;
- shm_free(_p->sec_header.s);
+ if(_p->sec_header.s)
+ shm_free(_p->sec_header.s);
switch (_p->type)
{
case SECURITY_IPSEC:
- shm_free(_p->data.ipsec->ealg.s);
- shm_free(_p->data.ipsec->r_ealg.s);
- shm_free(_p->data.ipsec->ck.s);
- shm_free(_p->data.ipsec->alg.s);
- shm_free(_p->data.ipsec->r_alg.s);
- shm_free(_p->data.ipsec->ik.s);
- shm_free(_p->data.ipsec->prot.s);
- shm_free(_p->data.ipsec->mod.s);
-
- shm_free(_p->data.ipsec);
+ if(_p->data.ipsec){
+ if(_p->data.ipsec->ealg.s) shm_free(_p->data.ipsec->ealg.s);
+ if(_p->data.ipsec->r_ealg.s) shm_free(_p->data.ipsec->r_ealg.s);
+ if(_p->data.ipsec->ck.s) shm_free(_p->data.ipsec->ck.s);
+ if(_p->data.ipsec->alg.s) shm_free(_p->data.ipsec->alg.s);
+ if(_p->data.ipsec->r_alg.s) shm_free(_p->data.ipsec->r_alg.s);
+ if(_p->data.ipsec->ik.s) shm_free(_p->data.ipsec->ik.s);
+ if(_p->data.ipsec->prot.s) shm_free(_p->data.ipsec->prot.s);
+ if(_p->data.ipsec->mod.s) shm_free(_p->data.ipsec->mod.s);
+
+ shm_free(_p->data.ipsec);
+ }
break;
case SECURITY_TLS:
- shm_free(_p->data.tls);
+ if(_p->data.tls)
+ shm_free(_p->data.tls);
break;
case SECURITY_NONE:
diff --git a/src/modules/ims_usrloc_pcscf/usrloc.c
b/src/modules/ims_usrloc_pcscf/usrloc.c
index c32f84e641..66c37ffe5f 100644
--- a/src/modules/ims_usrloc_pcscf/usrloc.c
+++ b/src/modules/ims_usrloc_pcscf/usrloc.c
@@ -79,6 +79,7 @@ int bind_usrloc(usrloc_api_t* api) {
api->update_security = update_security;
api->update_temp_security = update_temp_security;
api->register_ulcb = register_ulcb;
+ api->get_number_of_contacts = get_number_of_contacts;
return 0;
}
diff --git a/src/modules/ims_usrloc_pcscf/usrloc.h
b/src/modules/ims_usrloc_pcscf/usrloc.h
index 2eaa2e76b7..4de653dd70 100644
--- a/src/modules/ims_usrloc_pcscf/usrloc.h
+++ b/src/modules/ims_usrloc_pcscf/usrloc.h
@@ -257,6 +257,9 @@ typedef int (*get_all_ucontacts_t)(void* buf, int len, unsigned int
flags, unsig
typedef int (*update_security_t)(struct udomain* _d, security_type _t, security_t* _s,
struct pcontact* _c);
typedef int (*update_temp_security_t)(struct udomain* _d, security_type _t, security_t*
_s, struct pcontact* _c);
+/* statistic APIs */
+typedef unsigned long(*get_number_of_contacts_t)();
+
/*! usrloc API export structure */
typedef struct usrloc_api {
int use_domain; /*! use_domain module parameter */
@@ -281,6 +284,8 @@ typedef struct usrloc_api {
update_temp_security_t update_temp_security;
register_ulcb_t register_ulcb;
+
+ get_number_of_contacts_t get_number_of_contacts;
} usrloc_api_t;
/*! usrloc API export bind function */