memory leak fixes

This commit is contained in:
Kapil Gupta 2012-08-22 10:58:13 -04:00
parent fad4444203
commit 4a1c7bcf70
5 changed files with 67 additions and 34 deletions

View File

@ -379,8 +379,8 @@ void megaco_termination_destroy(mg_termination_t *term)
} }
if(term->active_events){ if(term->active_events){
free(term->active_events); mgUtlDelMgMgcoReqEvtDesc(term->active_events);
term->active_events = NULL; MG_STACK_MEM_FREE(term->active_events, sizeof(MgMgcoReqEvtDesc));
} }
term->context = NULL; term->context = NULL;

View File

@ -476,30 +476,32 @@ switch_status_t mg_prc_descriptors(megaco_profile_t* mg_profile, MgMgcoCommand *
{ {
MgMgcoReqEvtDesc* evt = &desc->dl.descs[descId]->u.evts; 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 */ /* 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*/ /* 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){ if(NULL != term->active_events){
mgUtlDelMgMgcoReqEvtDesc(term->active_events); mgUtlDelMgMgcoReqEvtDesc(term->active_events);
free(term->active_events); MG_STACK_MEM_FREE(term->active_events, sizeof(MgMgcoReqEvtDesc));
term->active_events = NULL;
} }
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 */ /* copy requested event */
if(RFAILED == mgUtlCpyMgMgcoReqEvtDesc(term->active_events, evt, NULLP)){ if(RFAILED == mgUtlCpyMgMgcoReqEvtDesc(term->active_events, evt, NULLP)){
free(term->active_events); switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR," copy new events to term->active_events failed \n");
term->active_events = NULL; MG_STACK_MEM_FREE(term->active_events, sizeof(MgMgcoReqEvtDesc));
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
/* print Requested event descriptor */ /* print Requested event descriptor */
mgAccEvntPrntMgMgcoReqEvtDesc(term->active_events, stdout); /*mgAccEvntPrntMgMgcoReqEvtDesc(term->active_events, stdout);*/
/* TODO - We can check for it/ito package*/
break; break;
} }
@ -508,7 +510,7 @@ switch_status_t mg_prc_descriptors(megaco_profile_t* mg_profile, MgMgcoCommand *
MgMgcoSignalsDesc* sig = &desc->dl.descs[descId]->u.sig; MgMgcoSignalsDesc* sig = &desc->dl.descs[descId]->u.sig;
MgMgcoSignalsParm* param = NULL; MgMgcoSignalsParm* param = NULL;
int i = 0x00; 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)){ 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(!is_rtp){
/* IF ADD request is for Physical term then we can simply copy incoming /* IF ADD request is for Physical term then we can simply copy incoming
* termination */ * 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 #ifdef GCP_VER_2_1
out_termId = rsp.u.mgCmdRsp[0]->u.add.termIdLst.terms[0]; out_termId = rsp.u.mgCmdRsp[0]->u.add.termIdLst.terms[0];
@ -1041,6 +1044,7 @@ error:
mg_build_mgco_err_request(&mgErr, txn_id, ctxtId, err_code, &errTxt)) { mg_build_mgco_err_request(&mgErr, txn_id, ctxtId, err_code, &errTxt)) {
sng_mgco_send_err(mg_profile->idx, mgErr); sng_mgco_send_err(mg_profile->idx, mgErr);
} }
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"); switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR," ADD Request failed..releasing context/termination(if allocated) \n");
if(mg_ctxt){ if(mg_ctxt){
megaco_release_context(mg_ctxt); megaco_release_context(mg_ctxt);
@ -1048,6 +1052,7 @@ error:
if(term){ if(term){
megaco_termination_destroy(term); megaco_termination_destroy(term);
} }
}
return SWITCH_STATUS_FALSE; 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.pres = PRSNT_NODEF;
rsp.u.mgCmdRsp[0]->u.mod.termIdLst.num.val = 1; 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 #ifdef GCP_VER_2_1
termId = rsp.u.mgCmdRsp[0]->u.mod.termIdLst.terms[0]; termId = rsp.u.mgCmdRsp[0]->u.mod.termIdLst.terms[0];
@ -1509,7 +1516,8 @@ response:
rsp.u.mgCmdRsp[0]->wild.pres = PRSNT_NODEF; 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 #ifdef GCP_VER_2_1
out_termId = rsp.u.mgCmdRsp[0]->u.add.termIdLst.terms[0]; 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.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->u.add.termIdLst.num.val = 1; 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 #ifdef GCP_VER_2_1
termId = cmd.u.mgCmdRsp[0]->u.add.termIdLst.terms[0]; 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; uint8_t wild = 0x00;
memset(&reply, 0, sizeof(reply)); memset(&reply, 0, sizeof(reply));
memset(&ctxt, 0, sizeof(ctxt));
audit = &auditReq->u.mgCmdReq[0]->cmd.u.aval; audit = &auditReq->u.mgCmdReq[0]->cmd.u.aval;
wild = auditReq->u.mgCmdReq[0]->wild.pres; 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.pres = PRSNT_NODEF;
adtRep->type.val = MGT_TERMAUDIT; adtRep->type.val = MGT_TERMAUDIT;
adtRep->u.other.pres.pres = PRSNT_NODEF; 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 */ /* 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.pres = PRSNT_NODEF;
adtRep->u.other.audit.parms[numOfParms - 1]->type.val = MGT_PKGSDESC; 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; 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->type.val = MGT_TERMAUDIT;
adtRep->u.other.pres.pres = PRSNT_NODEF; adtRep->u.other.pres.pres = PRSNT_NODEF;
adtRep->u.other.audit.num.pres = 0x00; 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..*/ /* 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.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->u.mod.termIdLst.num.val = 1; 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 #ifdef GCP_VER_2_1
termId = cmd.u.mgCmdRsp[0]->u.mod.termIdLst.terms[0]; 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.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->u.sub.termIdLst.num.val = 1; 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 #ifdef GCP_VER_2_1
termId = cmd.u.mgCmdRsp[0]->u.sub.termIdLst.terms[0]; termId = cmd.u.mgCmdRsp[0]->u.sub.termIdLst.terms[0];

View 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 i = 0x00;
uint16_t num_of_pkgs = sizeof(mg_pkg_list)/sizeof(MgPackage_t); 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++) { for (i = 0; i < num_of_pkgs; i++) {
if (mgUtlGrowList((void ***)&pkg->items, 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"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"Package descriptor Grow List failed\n");
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }

View File

@ -113,6 +113,25 @@ typedef enum {
cmMemcpy((U8*) (_dst), (const U8*) (_src), _len) 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) \ #define MG_INIT_TOKEN_VALUE(_tkn, _val) \
{ \ { \
(_tkn)->pres = PRSNT_NODEF; \ (_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); void mg_util_set_term_string ( MgStr *errTxt, MgMgcoTermId *termId);
MgMgcoTermIdLst *mg_get_term_id_list(MgMgcoCommand *cmd); MgMgcoTermIdLst *mg_get_term_id_list(MgMgcoCommand *cmd);
switch_status_t handle_pkg_audit( SuId suId, MgMgcoCommand *auditReq); 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); switch_status_t mg_send_heartbeat_audit_rsp( SuId suId, MgMgcoCommand *auditReq);
void mg_get_time_stamp(MgMgcoTimeStamp *timeStamp); void mg_get_time_stamp(MgMgcoTimeStamp *timeStamp);
switch_status_t mg_fill_svc_change(MgMgcoSvcChgPar *srvPar, uint8_t method, const char *reason,CmMemListCp *memCp); switch_status_t mg_fill_svc_change(MgMgcoSvcChgPar *srvPar, uint8_t method, const char *reason,CmMemListCp *memCp);