Skip to content

Commit

Permalink
qrouting/drouting: Fix shm/pkg memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuchircu committed Feb 6, 2020
1 parent 46a8e50 commit abede7d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
25 changes: 9 additions & 16 deletions modules/drouting/drouting.c
Expand Up @@ -2566,38 +2566,31 @@ static inline int get_pgwl_params(struct dr_sort_params *sort_params,
#define DR_MAX_GWLIST 64

static int sort_rt_dst(rt_info_t *dr_rule, unsigned short dst_id,
unsigned short *idx) {
struct dr_sort_params * sort_params;
unsigned short *idx)
{
struct dr_sort_params sort_params;
pgw_list_t * pgwl;
int i;
int size;
unsigned short *tmp;
unsigned char sort_alg;

memset(&sort_params, 0, sizeof sort_params);
sort_params.dr_rule = dr_rule;
sort_params.dst_id = dst_id;
sort_params.sorted_dst = idx;


sort_params = (struct dr_sort_params *)pkg_malloc(
sizeof(struct dr_sort_params));
if(sort_params == NULL) {
LM_ERR("no more pkg memory\n");
if (get_pgwl_params(&sort_params, &pgwl, &size, &tmp) < 0)
return -1;
}
memset(sort_params, 0, sizeof(struct dr_sort_params));
sort_params->dr_rule = dr_rule;
sort_params->dst_id = dst_id;
sort_params->sorted_dst = idx;

if(get_pgwl_params(sort_params, &pgwl, &size, &tmp) < 0) {
return -1;
}
/* extract the sorting algorithm */
if(dst_id != (unsigned short)-1) { /* if destionation is carrier */
sort_alg = dr_rule->pgwl[dst_id].dst.carrier->sort_alg;
} else { /* if destionation is gw */
sort_alg = dr_rule->sort_alg;
}

run_dr_sort_cbs(sort_alg, sort_params);
run_dr_sort_cbs(sort_alg, &sort_params);

LM_DBG("Sorted destination list:\n");
for(i = 0; i < size; i++) {
Expand Down
1 change: 1 addition & 0 deletions modules/qrouting/qr_stats.c
Expand Up @@ -197,6 +197,7 @@ void free_qr_list(qr_partitions_t *qr_parts)
lock_destroy_rw(qr_parts->rw_lock);

shm_free(qr_parts->qr_rules_start);
shm_free(qr_parts->part_name);
shm_free(qr_parts);
}

Expand Down
4 changes: 2 additions & 2 deletions ut.h
Expand Up @@ -142,7 +142,7 @@ struct sip_msg;
#define pkg_free_all(things) \
do { \
typeof(things) pos = NULL, head = things; \
while (things && (!pos || things != head)) \
while (things && (things != head || !pos)) \
{ pos = (things); (things) = (things)->next; pkg_free(pos); } \
} while (0)

Expand All @@ -155,7 +155,7 @@ struct sip_msg;
#define shm_free_all(things) \
do { \
typeof(things) pos = NULL, head = things; \
while (things && (!pos || things != head)) \
while (things && (things != head || !pos)) \
{ pos = (things); (things) = (things)->next; shm_free(pos); } \
} while (0)

Expand Down

0 comments on commit abede7d

Please sign in to comment.