Răsfoiți Sursa

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.
Aleksandar Yosifov 6 ani în urmă
părinte
comite
91c5ca7517

+ 16 - 12
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:

+ 1 - 0
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;
 }

+ 5 - 0
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 */