]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
memory leak fixes
authorKapil Gupta <kgupta@sangoma.com>
Wed, 22 Aug 2012 14:58:13 +0000 (10:58 -0400)
committerKapil Gupta <kgupta@sangoma.com>
Wed, 22 Aug 2012 14:58:13 +0000 (10:58 -0400)
src/mod/endpoints/mod_media_gateway/media_gateway.c
src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c
src/mod/endpoints/mod_media_gateway/media_gateway_packages.c
src/mod/endpoints/mod_media_gateway/media_gateway_stack.h
src/mod/endpoints/mod_media_gateway/media_gateway_utils.c

index f501d43c3ad38f8e7158b88709ae2220cddbffdc..54a8fbe3fb693b9b8c3f9cbeeb611cab469a0212 100644 (file)
@@ -379,8 +379,8 @@ void megaco_termination_destroy(mg_termination_t *term)
     }
 
     if(term->active_events){
-        free(term->active_events);
-        term->active_events = NULL;
+           mgUtlDelMgMgcoReqEvtDesc(term->active_events);
+           MG_STACK_MEM_FREE(term->active_events, sizeof(MgMgcoReqEvtDesc));
     }
     term->context = NULL;
 
index 2c30bc6bd06783a9ac81c267313060fca10791a4..a1712fc6723dc598b723ba6b378314105cceea28 100644 (file)
@@ -476,31 +476,33 @@ switch_status_t mg_prc_descriptors(megaco_profile_t* mg_profile, MgMgcoCommand *
                 {
                     MgMgcoReqEvtDesc* evt = &desc->dl.descs[descId]->u.evts; 
 
-                    switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR," Requested Event descriptor\n");
+                    switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG," Requested Event descriptor\n");
             
                     /* If we receive events from MGC , means clear any ongoing events */
                     /* as such we dont apply any events to term, so for us (as of now) clear events means clear active_events structure*/
 
                     if(NULL != term->active_events){
-                        mgUtlDelMgMgcoReqEvtDesc(term->active_events);
-                        free(term->active_events);
-                        term->active_events = NULL;
+                       mgUtlDelMgMgcoReqEvtDesc(term->active_events);
+                       MG_STACK_MEM_FREE(term->active_events, sizeof(MgMgcoReqEvtDesc));
                     }
 
-                    term->active_events = malloc(sizeof(*term->active_events));
-                    
+                   MG_STACK_MEM_ALLOC(&term->active_events, sizeof(MgMgcoReqEvtDesc));
+
+                   if(NULL == term->active_events){
+                           switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR," term->active_events Memory Alloc failed \n");
+                           return SWITCH_STATUS_FALSE;
+                   }
+
                     /* copy requested event */
                     if(RFAILED == mgUtlCpyMgMgcoReqEvtDesc(term->active_events, evt, NULLP)){
-                        free(term->active_events);
-                        term->active_events = NULL;
+                       switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR," copy new events to term->active_events failed \n");
+                       MG_STACK_MEM_FREE(term->active_events, sizeof(MgMgcoReqEvtDesc));
                         return SWITCH_STATUS_FALSE;
                     }
 
                     /* print Requested event descriptor */
-                    mgAccEvntPrntMgMgcoReqEvtDesc(term->active_events, stdout);
+                    /*mgAccEvntPrntMgMgcoReqEvtDesc(term->active_events, stdout);*/
                     
-                    /* TODO - We can check for it/ito package*/
-
                     break;
                 }
             case MGT_SIGNALSDESC:
@@ -508,7 +510,7 @@ switch_status_t mg_prc_descriptors(megaco_profile_t* mg_profile, MgMgcoCommand *
                     MgMgcoSignalsDesc* sig = &desc->dl.descs[descId]->u.sig; 
                     MgMgcoSignalsParm* param = NULL;
                     int i = 0x00;
-                    switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR," Requested Signal descriptor\n");
+                    switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG," Requested Signal descriptor\n");
 
                     if((NOTPRSNT != sig->pres.pres) && (NOTPRSNT != sig->num.pres) && (0 != sig->num.val)){
 
@@ -760,7 +762,8 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i
         if(!is_rtp){
             /* IF ADD request is for Physical term then we can simply copy incoming
              * termination */
-            mgUtlAllocMgMgcoTermIdLst(&rsp.u.mgCmdRsp[0]->u.add.termIdLst, &inc_cmd->u.mgCmdReq[0]->cmd.u.add.termIdLst);
+            //mgUtlAllocMgMgcoTermIdLst(&rsp.u.mgCmdRsp[0]->u.add.termIdLst, &inc_cmd->u.mgCmdReq[0]->cmd.u.add.termIdLst);
+           mgUtlCpyMgMgcoTermIdLst(&rsp.u.mgCmdRsp[0]->u.add.termIdLst, &inc_cmd->u.mgCmdReq[0]->cmd.u.add.termIdLst, &rsp.u.mgCmdRsp[0]->memCp);
 
 #ifdef GCP_VER_2_1
             out_termId = rsp.u.mgCmdRsp[0]->u.add.termIdLst.terms[0];
@@ -1041,12 +1044,14 @@ error:
             mg_build_mgco_err_request(&mgErr, txn_id, ctxtId, err_code, &errTxt)) {
         sng_mgco_send_err(mg_profile->idx, mgErr);
     }
-    switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR," ADD Request failed..releasing context/termination(if allocated) \n"); 
-    if(mg_ctxt){
-           megaco_release_context(mg_ctxt);
-    }
-    if(term){
-           megaco_termination_destroy(term);
+    if(err_code != MGT_MGCO_RSP_CODE_DUP_TERM_CTXT){
+           switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR," ADD Request failed..releasing context/termination(if allocated) \n"); 
+           if(mg_ctxt){
+                   megaco_release_context(mg_ctxt);
+           }
+           if(term){
+                   megaco_termination_destroy(term);
+           }
     }
     return SWITCH_STATUS_FALSE;        
 }
@@ -1252,7 +1257,9 @@ response:
                rsp.u.mgCmdRsp[0]->u.mod.termIdLst.num.pres = PRSNT_NODEF;
                rsp.u.mgCmdRsp[0]->u.mod.termIdLst.num.val  = 1;
 
-               mgUtlAllocMgMgcoTermIdLst(&rsp.u.mgCmdRsp[0]->u.mod.termIdLst, &inc_cmd->u.mgCmdReq[0]->cmd.u.mod.termIdLst);
+               //mgUtlAllocMgMgcoTermIdLst(&rsp.u.mgCmdRsp[0]->u.mod.termIdLst, &inc_cmd->u.mgCmdReq[0]->cmd.u.mod.termIdLst);
+
+               mgUtlCpyMgMgcoTermIdLst(&rsp.u.mgCmdRsp[0]->u.mod.termIdLst, &inc_cmd->u.mgCmdReq[0]->cmd.u.mod.termIdLst, &rsp.u.mgCmdRsp[0]->memCp);
 
 #ifdef GCP_VER_2_1
                termId = rsp.u.mgCmdRsp[0]->u.mod.termIdLst.terms[0];
@@ -1509,7 +1516,8 @@ response:
             rsp.u.mgCmdRsp[0]->wild.pres = PRSNT_NODEF;
         }
 
-        mgUtlAllocMgMgcoTermIdLst(&rsp.u.mgCmdRsp[0]->u.add.termIdLst, &inc_cmd->u.mgCmdReq[0]->cmd.u.add.termIdLst);
+        //mgUtlAllocMgMgcoTermIdLst(&rsp.u.mgCmdRsp[0]->u.add.termIdLst, &inc_cmd->u.mgCmdReq[0]->cmd.u.add.termIdLst);
+       mgUtlCpyMgMgcoTermIdLst(&rsp.u.mgCmdRsp[0]->u.add.termIdLst, &inc_cmd->u.mgCmdReq[0]->cmd.u.add.termIdLst, &rsp.u.mgCmdRsp[0]->memCp);
 
 #ifdef GCP_VER_2_1
         out_termId = rsp.u.mgCmdRsp[0]->u.add.termIdLst.terms[0];
@@ -1582,7 +1590,8 @@ switch_status_t mg_send_add_rsp(SuId suId, MgMgcoCommand *req)
        cmd.u.mgCmdRsp[0]->u.add.termIdLst.num.pres = PRSNT_NODEF;
        cmd.u.mgCmdRsp[0]->u.add.termIdLst.num.val  = 1;
 
-       mgUtlAllocMgMgcoTermIdLst(&cmd.u.mgCmdRsp[0]->u.add.termIdLst, &req->u.mgCmdReq[0]->cmd.u.add.termIdLst);
+       //mgUtlAllocMgMgcoTermIdLst(&cmd.u.mgCmdRsp[0]->u.add.termIdLst, &req->u.mgCmdReq[0]->cmd.u.add.termIdLst);
+       mgUtlCpyMgMgcoTermIdLst(&cmd.u.mgCmdRsp[0]->u.add.termIdLst, &req->u.mgCmdReq[0]->cmd.u.add.termIdLst, &cmd.u.mgCmdRsp[0]->memCp);
 
 #ifdef GCP_VER_2_1
        termId = cmd.u.mgCmdRsp[0]->u.add.termIdLst.terms[0];
@@ -1724,6 +1733,7 @@ switch_status_t handle_mg_audit_cmd( megaco_profile_t* mg_profile, MgMgcoCommand
        uint8_t          wild = 0x00;
 
        memset(&reply, 0, sizeof(reply));
+       memset(&ctxt, 0, sizeof(ctxt));
 
        audit      = &auditReq->u.mgCmdReq[0]->cmd.u.aval;
        wild       = auditReq->u.mgCmdReq[0]->wild.pres;
@@ -1818,7 +1828,8 @@ switch_status_t handle_mg_audit_cmd( megaco_profile_t* mg_profile, MgMgcoCommand
        adtRep->type.pres = PRSNT_NODEF;
        adtRep->type.val = MGT_TERMAUDIT;
        adtRep->u.other.pres.pres = PRSNT_NODEF;
-       mgUtlAllocMgMgcoTermIdLst(&adtRep->u.other.termIdLst, term_list);
+       
+       mgUtlCpyMgMgcoTermIdLst(&adtRep->u.other.termIdLst, term_list, &reply.u.mgCmdRsp[0]->memCp);
 
        /* NOW for each requested AUDIT descriptor we need to add entry to adtRep->u.other.audit.parms list */
 
@@ -1920,7 +1931,7 @@ switch_status_t handle_mg_audit_cmd( megaco_profile_t* mg_profile, MgMgcoCommand
                                                adtRep->u.other.audit.parms[numOfParms - 1]->type.pres = PRSNT_NODEF;
                                                adtRep->u.other.audit.parms[numOfParms - 1]->type.val  = MGT_PKGSDESC;
 
-                                               if(SWITCH_STATUS_FALSE == mg_build_pkg_desc(&adtRep->u.other.audit.parms[numOfParms - 1]->u.pkgs)){
+                                               if(SWITCH_STATUS_FALSE == mg_build_pkg_desc(&adtRep->u.other.audit.parms[numOfParms - 1]->u.pkgs, &reply.u.mgCmdRsp[0]->memCp)){
                                                        return SWITCH_STATUS_FALSE;
                                                }
 
@@ -2023,7 +2034,8 @@ switch_status_t mg_send_heartbeat_audit_rsp( SuId suId, MgMgcoCommand *auditReq)
        adtRep->type.val = MGT_TERMAUDIT;
        adtRep->u.other.pres.pres = PRSNT_NODEF;
        adtRep->u.other.audit.num.pres = 0x00;
-       mgUtlAllocMgMgcoTermIdLst(&adtRep->u.other.termIdLst, term_list);
+
+       mgUtlCpyMgMgcoTermIdLst(&adtRep->u.other.termIdLst, term_list, &reply.u.mgCmdRsp[0]->memCp);
 
 
        /* We will always send one command at a time..*/
@@ -2359,7 +2371,8 @@ switch_status_t mg_send_modify_rsp(SuId suId, MgMgcoCommand *req)
        cmd.u.mgCmdRsp[0]->u.mod.termIdLst.num.pres = PRSNT_NODEF;
        cmd.u.mgCmdRsp[0]->u.mod.termIdLst.num.val  = 1;
 
-       mgUtlAllocMgMgcoTermIdLst(&cmd.u.mgCmdRsp[0]->u.mod.termIdLst, &req->u.mgCmdReq[0]->cmd.u.mod.termIdLst);
+       //mgUtlAllocMgMgcoTermIdLst(&cmd.u.mgCmdRsp[0]->u.mod.termIdLst, &req->u.mgCmdReq[0]->cmd.u.mod.termIdLst);
+       mgUtlCpyMgMgcoTermIdLst(&cmd.u.mgCmdRsp[0]->u.mod.termIdLst, &req->u.mgCmdReq[0]->cmd.u.mod.termIdLst, &cmd.u.mgCmdRsp[0]->memCp);
 
 #ifdef GCP_VER_2_1
        termId = cmd.u.mgCmdRsp[0]->u.mod.termIdLst.terms[0];
@@ -2427,7 +2440,8 @@ switch_status_t mg_send_subtract_rsp(SuId suId, MgMgcoCommand *req)
        cmd.u.mgCmdRsp[0]->u.sub.termIdLst.num.pres = PRSNT_NODEF;
        cmd.u.mgCmdRsp[0]->u.sub.termIdLst.num.val  = 1;
 
-       mgUtlAllocMgMgcoTermIdLst(&cmd.u.mgCmdRsp[0]->u.sub.termIdLst, &req->u.mgCmdReq[0]->cmd.u.sub.termIdLst);
+       //mgUtlAllocMgMgcoTermIdLst(&cmd.u.mgCmdRsp[0]->u.sub.termIdLst, &req->u.mgCmdReq[0]->cmd.u.sub.termIdLst);
+       mgUtlCpyMgMgcoTermIdLst(&cmd.u.mgCmdRsp[0]->u.sub.termIdLst, &req->u.mgCmdReq[0]->cmd.u.sub.termIdLst, &cmd.u.mgCmdRsp[0]->memCp);
 
 #ifdef GCP_VER_2_1
        termId = cmd.u.mgCmdRsp[0]->u.sub.termIdLst.terms[0];
@@ -2630,7 +2644,7 @@ switch_status_t  mg_send_ito_notify(megaco_profile_t* mg_profile )
 {
     MgMgcoObsEvt *oevt;
 
-       switch_assert(mg_profile);
+    switch_assert(mg_profile);
 
     mg_stack_alloc_mem((Ptr*)&oevt, sizeof(MgMgcoObsEvt));
 
index febc587f76a3a6ea7690969dd762b48e95f34356..fc86096335d0e482e13e279c4f76bf1ca33b0104 100644 (file)
@@ -147,7 +147,7 @@ MgPackage_t mg_pkg_list [] =
 };
 
 /***************************************************************************************/
-switch_status_t mg_build_pkg_desc(MgMgcoPkgsDesc* pkg)
+switch_status_t mg_build_pkg_desc(MgMgcoPkgsDesc* pkg, CmMemListCp  *memCp)
 {
        uint16_t i = 0x00;
        uint16_t num_of_pkgs = sizeof(mg_pkg_list)/sizeof(MgPackage_t);
@@ -157,7 +157,7 @@ switch_status_t mg_build_pkg_desc(MgMgcoPkgsDesc* pkg)
        for (i = 0; i < num_of_pkgs; i++) {
 
                if (mgUtlGrowList((void ***)&pkg->items,
-                                       sizeof(MgMgcoPkgsItem), &pkg->num, NULLP) != ROK) {
+                                       sizeof(MgMgcoPkgsItem), &pkg->num, memCp) != ROK) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"Package descriptor Grow List failed\n");
                        return SWITCH_STATUS_FALSE;
                }
index 39431012858e5befb8835acc60338f11c28defc0..0b8c5746e106b6be047c49c782547a55e96e6df1 100644 (file)
@@ -113,6 +113,25 @@ typedef enum {
        cmMemcpy((U8*) (_dst), (const U8*) (_src), _len)
 
 
+#define MG_STACK_MEM_ALLOC(_buf, _size)\
+{\
+       if (SGetSBuf(S_REG, S_POOL, (Data**) _buf, (Size) _size) == ROK){   \
+        cmMemset((U8 *) *(_buf), 0, _size);                                \
+       } else {                                                            \
+               *(_buf) = NULLP;                                            \
+       }                                                                   \
+}
+
+#define MG_STACK_MEM_FREE(_buf, _size)\
+{\
+       if(_buf != NULL){                                                   \
+               (Void) SPutSBuf(S_REG, S_POOL, (Data *) _buf, (Size) _size);\
+               (_buf) = NULL;                                              \
+       }                                                                   \
+}
+
+
+
 #define MG_INIT_TOKEN_VALUE(_tkn, _val)                               \
 {                                                                         \
    (_tkn)->pres = PRSNT_NODEF;                                            \
@@ -204,7 +223,7 @@ switch_status_t mg_send_subtract_rsp(SuId suId, MgMgcoCommand *req);
 void mg_util_set_term_string ( MgStr  *errTxt, MgMgcoTermId   *termId); 
 MgMgcoTermIdLst *mg_get_term_id_list(MgMgcoCommand *cmd);
 switch_status_t handle_pkg_audit( SuId suId, MgMgcoCommand *auditReq);
-switch_status_t mg_build_pkg_desc(MgMgcoPkgsDesc* pkg);
+switch_status_t mg_build_pkg_desc(MgMgcoPkgsDesc* pkg, CmMemListCp  *memCp);
 switch_status_t mg_send_heartbeat_audit_rsp( SuId suId, MgMgcoCommand *auditReq);
 void mg_get_time_stamp(MgMgcoTimeStamp *timeStamp);
 switch_status_t  mg_fill_svc_change(MgMgcoSvcChgPar  *srvPar, uint8_t  method, const char  *reason,CmMemListCp   *memCp);
index dc6312ca91941ca355ab475db62a3667d1b7c02e..c032ab43d87541dd541a99d9e3b0260b9c99faf7 100644 (file)
@@ -961,7 +961,7 @@ const char* mg_get_codec_name(megaco_profile_t* mg_profile, int iana_code)
        return name;
 }
 
-void mgco_handle_sdp_media_param(CmSdpMedPar *s, mg_termination_t* term, mgco_sdp_types_e sdp_type, megaco_profile_t* mg_profile, CmSdpAttrSet  *attrSet, CmMemListCp     *memCp)
+void mgco_handle_sdp_media_param(CmSdpMedPar *s, mg_termination_t* term, mgco_sdp_types_e sdp_type, megaco_profile_t* mg_profile, CmSdpAttrSet  *attrSet, CmMemListCp  *memCp)
 {
     int i=0x00;
     switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "***** Media Parameter *********** \n");