[sr-dev] git:master:e2994b6a: ims_ipsec_pcscf: Fix memory leaks in cmd.c

Tsvetomir Dimitrov tsv.dimitrov at gmail.com
Thu Aug 23 09:58:20 CEST 2018


Module: kamailio
Branch: master
Commit: e2994b6ac4846c869894a2783304782854f96f57
URL: https://github.com/kamailio/kamailio/commit/e2994b6ac4846c869894a2783304782854f96f57

Author: Tsvetomir Dimitrov <tsv.dimitrov at gmail.com>
Committer: Tsvetomir Dimitrov <tsv.dimitrov at gmail.com>
Date: 2018-08-23T10:57:44+03:00

ims_ipsec_pcscf: Fix memory leaks in cmd.c

---

Modified: src/modules/ims_ipsec_pcscf/cmd.c

---

Diff:  https://github.com/kamailio/kamailio/commit/e2994b6ac4846c869894a2783304782854f96f57.diff
Patch: https://github.com/kamailio/kamailio/commit/e2994b6ac4846c869894a2783304782854f96f57.patch

---

diff --git a/src/modules/ims_ipsec_pcscf/cmd.c b/src/modules/ims_ipsec_pcscf/cmd.c
index b5741e30d8..46056b9214 100644
--- a/src/modules/ims_ipsec_pcscf/cmd.c
+++ b/src/modules/ims_ipsec_pcscf/cmd.c
@@ -161,7 +161,7 @@ static int fill_contact(struct pcontact_info* ci, struct sip_msg* m)
         cb = cscf_parse_contacts(req);
         if (!cb || (!cb->contacts)) {
             LM_ERR("fill_contact(): No contact headers\n");
-            return -3;
+            return -1;
         }
 
         // populate CI with bare minimum
@@ -172,8 +172,11 @@ static int fill_contact(struct pcontact_info* ci, struct sip_msg* m)
     }
 
 
-    char* srcip;
-    srcip = pkg_malloc(50);
+    char* srcip = NULL;
+    if((srcip = pkg_malloc(50)) == NULL) {
+        LM_ERR("Error allocating memory for source IP address\n");
+        return -1;
+    }
 
     ci->received_host.len = ip_addr2sbuf(&req->rcv.src_ip, srcip, 50);
     ci->received_host.s = srcip;
@@ -386,6 +389,7 @@ int add_security_server_header(struct sip_msg* m, ipsec_t* s)
     // copy to the header and add
     if((sec_header->s = pkg_malloc(sec_header->len)) == NULL) {
         LM_ERR("Error allocating pkg memory for security header payload\n");
+        pkg_free(sec_header);
         return -1;
     }
     memcpy(sec_header->s, sec_hdr_buf, sec_header->len);
@@ -393,6 +397,8 @@ int add_security_server_header(struct sip_msg* m, ipsec_t* s)
     // add security-server header in reply
     if(cscf_add_header(m, sec_header, HDR_OTHER_T) != 1) {
         LM_ERR("Error adding security header to reply!\n");
+        pkg_free(sec_header->s);
+        pkg_free(sec_header);
         return -1;
     }
 




More information about the sr-dev mailing list