diff --git a/src/modules/drouting/dr_load.c b/src/modules/drouting/dr_load.c index ec943d0699b..754e9b285a5 100644 --- a/src/modules/drouting/dr_load.c +++ b/src/modules/drouting/dr_load.c @@ -138,7 +138,7 @@ static int add_tmp_gw_list(unsigned int id, char *list) list_len = strlen(list) + 1; tmp = (struct dr_gwl_tmp *)pkg_malloc(sizeof(struct dr_gwl_tmp) + list_len); if(tmp == NULL) { - LM_ERR("no more pkg mem\n"); + PKG_MEM_ERROR; return -1; } tmp->id = id; @@ -183,7 +183,7 @@ static inline dr_tmrec_t *parse_time_def(char *time_str) time_rec = (dr_tmrec_t *)shm_malloc(sizeof(dr_tmrec_t)); if(time_rec == 0) { - LM_ERR("no more pkg mem\n"); + PKG_MEM_ERROR; goto error; } memset(time_rec, 0, sizeof(dr_tmrec_t)); diff --git a/src/modules/drouting/dr_time.c b/src/modules/drouting/dr_time.c index dd601c3c4a4..535dbd0b1bd 100644 --- a/src/modules/drouting/dr_time.c +++ b/src/modules/drouting/dr_time.c @@ -74,7 +74,10 @@ dr_ac_tm_p dr_ac_tm_new(void) dr_ac_tm_p _atp = NULL; _atp = (dr_ac_tm_p)shm_malloc(sizeof(dr_ac_tm_t)); if(!_atp) + { + SHM_MEM_ERROR; return NULL; + } memset(_atp, 0, sizeof(dr_ac_tm_t)); return _atp; @@ -190,7 +193,10 @@ dr_ac_maxval_p dr_ac_get_maxval(dr_ac_tm_p _atp, int mode) if(mode==1) { _amp = (dr_ac_maxval_p)shm_malloc(sizeof(dr_ac_maxval_t)); if(!_amp) + { + SHM_MEM_ERROR; return NULL; + } } else { _amp = &_amv; } @@ -270,7 +276,10 @@ dr_tr_byxxx_p dr_tr_byxxx_new(void) dr_tr_byxxx_p _bxp = NULL; _bxp = (dr_tr_byxxx_p)shm_malloc(sizeof(dr_tr_byxxx_t)); if(!_bxp) + { + SHM_MEM_ERROR; return NULL; + } memset(_bxp, 0, sizeof(dr_tr_byxxx_t)); return _bxp; } @@ -282,9 +291,13 @@ int dr_tr_byxxx_init(dr_tr_byxxx_p _bxp, int _nr) _bxp->nr = _nr; _bxp->xxx = (int *)shm_malloc(_nr * sizeof(int)); if(!_bxp->xxx) + { + SHM_MEM_ERROR; return -1; + } _bxp->req = (int *)shm_malloc(_nr * sizeof(int)); if(!_bxp->req) { + SHM_MEM_ERROR; shm_free(_bxp->xxx); return -1; } @@ -313,7 +326,10 @@ dr_tmrec_p dr_tmrec_new(void) dr_tmrec_p _trp = NULL; _trp = (dr_tmrec_p)shm_malloc(sizeof(dr_tmrec_t)); if(!_trp) + { + SHM_MEM_ERROR; return NULL; + } memset(_trp, 0, sizeof(dr_tmrec_t)); localtime_r(&_trp->dtstart, &(_trp->ts)); return _trp; diff --git a/src/modules/drouting/drouting.c b/src/modules/drouting/drouting.c index df068d06681..cdf75cac985 100644 --- a/src/modules/drouting/drouting.c +++ b/src/modules/drouting/drouting.c @@ -346,7 +346,7 @@ static int dr_init(void) /* data pointer in shm */ rdata = (rt_data_t **)shm_malloc(sizeof(rt_data_t *)); if(rdata == 0) { - LM_CRIT("failed to get shm mem for data ptr\n"); + SHM_MEM_CRITICAL_FMT("for data ptr\n"); goto error; } *rdata = 0; @@ -363,7 +363,9 @@ static int dr_init(void) data_refcnt = (int *)shm_malloc(sizeof(int)); reload_flag = (int *)shm_malloc(sizeof(int)); if(!data_refcnt || !reload_flag) { - LM_ERR("no more shared memory\n"); + SHM_MEM_ERROR; + if(data_refcnt) shm_free(data_refcnt); + if(reload_flag) shm_free(reload_flag); goto error; } *data_refcnt = 0; diff --git a/src/modules/drouting/routing.c b/src/modules/drouting/routing.c index 08a0fc1ed4c..4d162b9cac4 100644 --- a/src/modules/drouting/routing.c +++ b/src/modules/drouting/routing.c @@ -43,7 +43,7 @@ rt_data_t *build_rt_data(void) rt_data_t *rdata; if(NULL == (rdata = shm_malloc(sizeof(rt_data_t)))) { - LM_ERR("no more shm mem\n"); + SHM_MEM_ERROR; goto err_exit; } memset(rdata, 0, sizeof(rt_data_t)); @@ -71,14 +71,14 @@ rt_info_t *build_rt_info(int priority, dr_tmrec_t *trec, pgw_t *pgw = NULL; if(NULL == (rt = (rt_info_t *)shm_malloc(sizeof(rt_info_t)))) { - LM_ERR("no more shm mem(1)\n"); + SHM_MEM_ERROR_FMT("1\n"); goto err_exit; } memset(rt, 0, sizeof(rt_info_t)); idx_size = IDX_SIZE; if(NULL == (idx = (int *)shm_malloc(2 * idx_size * sizeof(int)))) { - LM_ERR("no more shm mem(2)\n"); + SHM_MEM_ERROR_FMT("2\n"); goto err_exit; } memset(idx, 0, 2 * idx_size * sizeof(int)); @@ -137,6 +137,7 @@ rt_info_t *build_rt_info(int priority, dr_tmrec_t *trec, rt->pgwa_len = n; if(NULL == (rt->pgwl = (pgw_list_t *)shm_malloc( rt->pgwa_len * sizeof(pgw_list_t)))) { + SHM_MEM_ERROR; goto err_exit; } memset(rt->pgwl, 0, rt->pgwa_len * sizeof(pgw_list_t)); @@ -176,7 +177,7 @@ int add_rt_info(ptree_node_t *pn, rt_info_t *r, unsigned int rgid) goto err_exit; if(NULL == (rtl_wrp = (rt_info_wrp_t *)shm_malloc(sizeof(rt_info_wrp_t)))) { - LM_ERR("no more shm mem\n"); + SHM_MEM_ERROR; goto err_exit; } memset(rtl_wrp, 0, sizeof(rt_info_wrp_t)); @@ -188,6 +189,7 @@ int add_rt_info(ptree_node_t *pn, rt_info_t *r, unsigned int rgid) if(NULL == (pn->rg = (rg_entry_t *)shm_malloc( pn->rg_len * sizeof(rg_entry_t)))) { /* recover the old pointer to be able to shm_free mem */ + SHM_MEM_ERROR; goto err_exit; } memset(pn->rg, 0, pn->rg_len * sizeof(rg_entry_t)); @@ -202,6 +204,7 @@ int add_rt_info(ptree_node_t *pn, rt_info_t *r, unsigned int rgid) if(NULL == (pn->rg = (rg_entry_t *)shm_malloc( 2 * pn->rg_len * sizeof(rg_entry_t)))) { /* recover the old pointer to be able to shm_free mem */ + SHM_MEM_ERROR; pn->rg = trg; goto err_exit; } @@ -281,8 +284,8 @@ int add_dst(rt_data_t *r, pgw = (pgw_t *)shm_malloc(sizeof(pgw_t) + l_ip + l_pri + l_attrs); if(NULL == pgw) { - LM_ERR("no more shm mem (%u)\n", - (unsigned int)(sizeof(pgw_t) + l_ip + l_pri + l_attrs)); + SHM_MEM_ERROR_FMT("missing (%u)\n", +- (unsigned int)(sizeof(pgw_t) + l_ip + l_pri + l_attrs));; goto err_exit; } memset(pgw, 0, sizeof(pgw_t)); @@ -359,7 +362,7 @@ int add_dst(rt_data_t *r, LM_DBG("new gw ip addr [%s]\n", ip); tmpa = (pgw_addr_t *)shm_malloc(sizeof(pgw_addr_t)); if(tmpa == NULL) { - LM_ERR("no more shm mem (%u)\n", (unsigned int)sizeof(pgw_addr_t)); + SHM_MEM_ERROR_FMT("missing (%u)\n", (unsigned int)sizeof(pgw_addr_t)); goto err_exit; } memset(tmpa, 0, sizeof(pgw_addr_t));