Skip to content

Commit

Permalink
debugger: convert to memory error logging helper, add missing mem err…
Browse files Browse the repository at this point in the history
…or handling
  • Loading branch information
pantelisk98 authored and henningw committed Apr 29, 2023
1 parent 1183156 commit db8258b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/modules/debugger/debugger_api.c
Expand Up @@ -557,7 +557,10 @@ int dbg_init_bp_list(void)
return -1;
_dbg_bp_list = (dbg_bp_t*)shm_malloc(sizeof(dbg_bp_t));
if(_dbg_bp_list==NULL)
{
SHM_MEM_ERROR;
return -1;
}
memset(_dbg_bp_list, 0, sizeof(dbg_bp_t));
if(_dbg_breakpoint==1)
_dbg_bp_list->set |= DBG_ABKPOINT_ON;
Expand All @@ -580,7 +583,10 @@ int dbg_add_breakpoint(struct action *a, int bpon)
len += sizeof(dbg_bp_t) + 1;
nbp = (dbg_bp_t*)shm_malloc(len);
if(nbp==NULL)
{
SHM_MEM_ERROR;
return -1;
}
memset(nbp, 0, len);
nbp->set |= (bpon)?DBG_ABKPOINT_ON:0;
nbp->cline = a->cline;
Expand All @@ -605,7 +611,10 @@ int dbg_init_pid_list(void)
return -1;
_dbg_pid_list = (dbg_pid_t*)shm_malloc(_dbg_pid_no*sizeof(dbg_pid_t));
if(_dbg_pid_list==NULL)
{
SHM_MEM_ERROR;
return -1;
}
memset(_dbg_pid_list, 0, _dbg_pid_no*sizeof(dbg_pid_t));
return 0;
}
Expand Down Expand Up @@ -1202,7 +1211,7 @@ int dbg_init_mod_levels(int dbg_mod_hash_size)
_dbg_mod_table = (dbg_mod_slot_t*)shm_malloc(_dbg_mod_table_size*sizeof(dbg_mod_slot_t));
if(_dbg_mod_table==NULL)
{
LM_ERR("no more shm.\n");
SHM_MEM_ERROR;
return -1;
}
memset(_dbg_mod_table, 0, _dbg_mod_table_size*sizeof(dbg_mod_slot_t));
Expand Down Expand Up @@ -1367,8 +1376,9 @@ int dbg_set_mod_debug_level(char *mname, int mnlen, int *mlevel)
return 0;
}
itn = (dbg_mod_level_t*)shm_malloc(sizeof(dbg_mod_level_t) + (mnlen+1)*sizeof(char));
if(itn==NULL) {
LM_ERR("no more shm\n");
if(itn==NULL)
{
SHM_MEM_ERROR;
return -1;
}
memset(itn, 0, sizeof(dbg_mod_level_t) + (mnlen+1)*sizeof(char));
Expand Down Expand Up @@ -1444,7 +1454,7 @@ int dbg_set_mod_debug_facility(char *mname, int mnlen, int *mfacility)
}
itn = (dbg_mod_facility_t*)shm_malloc(sizeof(dbg_mod_facility_t) + (mnlen+1)*sizeof(char));
if(itn==NULL) {
LM_ERR("no more shm\n");
SHM_MEM_ERROR;
return -1;
}
memset(itn, 0, sizeof(dbg_mod_facility_t) + (mnlen+1)*sizeof(char));
Expand Down Expand Up @@ -1594,7 +1604,7 @@ int dbg_init_pvcache()
_dbg_pvcache = (dbg_pvcache_t**)pkg_malloc(sizeof(dbg_pvcache_t*)*DBG_PVCACHE_SIZE);
if(_dbg_pvcache==NULL)
{
LM_ERR("no more memory.\n");
SHM_MEM_ERROR;
return -1;
}
memset(_dbg_pvcache, 0, sizeof(dbg_pvcache_t*)*DBG_PVCACHE_SIZE);
Expand All @@ -1616,7 +1626,7 @@ int dbg_assign_add(str *name, pv_spec_t *spec)
pvn = (dbg_pvcache_t*)pkg_malloc(sizeof(dbg_pvcache_t));
if(pvn==NULL)
{
LM_ERR("no more memory\n");
SHM_MEM_ERROR;
return -1;
}
memset(pvn, 0, sizeof(dbg_pvcache_t));
Expand Down
11 changes: 11 additions & 0 deletions src/modules/debugger/debugger_mod.c
Expand Up @@ -556,7 +556,18 @@ static int w_dbg_sip_msg(struct sip_msg* msg, char *level, char *facility)

/* alloc private mem and copy lumps */
hdr_lumps = pkg_malloc(BUF_SIZE);
if(hdr_lumps==NULL)
{
PKG_MEM_ERROR;
return -1;
}
bdy_lumps = pkg_malloc(BUF_SIZE);
if(hdr_lumps==NULL)
{
pkg_free(hdr_lumps);
PKG_MEM_ERROR;
return -1;
}

new_buf_offs = 0;
process_lumps(msg, msg->add_rm, hdr_lumps, &new_buf_offs, &orig_offs, &send_info, flag);
Expand Down

0 comments on commit db8258b

Please sign in to comment.