Skip to content

Commit

Permalink
[dispatcher] multiple fixes
Browse files Browse the repository at this point in the history
* use pkg memory instead of shm for fixup variables
* fix int list building - avoid building a circular list
  • Loading branch information
ionutrazvanionita committed May 19, 2016
1 parent a41b6c4 commit dea3a12
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
4 changes: 3 additions & 1 deletion modules/dispatcher/dispatcher.c
Expand Up @@ -458,12 +458,14 @@ static ds_partition_t* find_partition_by_name (const str *partition_name)
/* Load setids this proxy is responsible for probing into list */
static int set_probing_list(unsigned int type, void *val) {
str input = {(char*)val, strlen(val)};

if (set_list_from_string(input, &ds_probing_list) != 0 ||
ds_probing_list == NULL)
{
LM_ERR("Invalid set_probing_list input\n");
return -1;
}

return 0;
}

Expand Down Expand Up @@ -1066,7 +1068,7 @@ static int w_ds_select(struct sip_msg* msg, char* part_set, char* alg,
max_list = max_list->next;

if (max_param->type == MAX_LIST_TYPE_PV)
shm_free(max_list_free);
pkg_free(max_list_free);
}

TRY_FREE_EXPANDED_LIST(set_list);
Expand Down
28 changes: 15 additions & 13 deletions modules/dispatcher/ds_fixups.c
Expand Up @@ -143,7 +143,7 @@ int set_list_from_string(str input, int_list_t **result)

if (str2sint(&input, &uset) == 0) {
/* Just one set in the list */
*result = shm_malloc(sizeof(int_list_t));
*result = pkg_malloc(sizeof(int_list_t));
if (*result == NULL)
goto no_memory;
(*result)->v.ival = uset;
Expand Down Expand Up @@ -194,7 +194,7 @@ int set_list_from_string(str input, int_list_t **result)
s_tok.s += flg_tok.len +1;
s_tok.len -= (flg_tok.len +1);

new_el = shm_malloc(sizeof(int_list_t));
new_el = pkg_malloc(sizeof(int_list_t));
if (new_el == NULL)
goto no_memory;

Expand Down Expand Up @@ -223,26 +223,27 @@ int set_list_from_string(str input, int_list_t **result)
}
else if (s_tok.s[0] == PV_MARKER) {
if (new_el == NULL) {
new_el = shm_malloc(sizeof(int_list_t));
new_el = pkg_malloc(sizeof(int_list_t));
if (new_el == NULL)
goto no_memory;
}

new_el->type = GPARAM_TYPE_PVS;
new_el->v.pvs = shm_malloc(sizeof(pv_spec_t));
new_el->v.pvs = pkg_malloc(sizeof(pv_spec_t));
if (new_el->v.pvs == NULL) {
shm_free(new_el);
pkg_free(new_el);
goto no_memory;
}

if ((pvdelim = pv_parse_spec(&s_tok, new_el->v.pvs)) == NULL) {
shm_free(new_el->v.pvs);
shm_free(new_el);
pkg_free(new_el->v.pvs);
pkg_free(new_el);
goto wrong_value;
}

new_el->next = *result;
*result = new_el;
new_el = NULL;

if (delim)
if (delim != pvdelim)
Expand All @@ -264,7 +265,7 @@ int set_list_from_string(str input, int_list_t **result)
*
*/
if (new_el == NULL) {
new_el = shm_malloc(sizeof(int_list_t));
new_el = pkg_malloc(sizeof(int_list_t));
if (new_el == NULL)
goto no_memory;
}
Expand All @@ -276,6 +277,7 @@ int set_list_from_string(str input, int_list_t **result)
new_el->flags = flags;
new_el->next = *result;
*result = new_el;
new_el = NULL;

input.len -= full_tok_len + 1;
input.s = delim + 1;
Expand All @@ -291,21 +293,21 @@ int set_list_from_string(str input, int_list_t **result)
no_memory:
while(*result) {
if ((*result)->type == GPARAM_TYPE_PVS)
shm_free((*result)->v.pvs);
pkg_free((*result)->v.pvs);
int_list_t *aux = *result;
*result = (*result)->next;
shm_free(aux);
pkg_free(aux);
}
LM_ERR("no more shared memory\n");
return -1;

wrong_value:
while(*result) {
if ((*result)->type == GPARAM_TYPE_PVS)
shm_free((*result)->v.pvs);
pkg_free((*result)->v.pvs);
int_list_t *aux = *result;
*result = (*result)->next;
shm_free(aux);
pkg_free(aux);
}
LM_ERR("wrong format for set/set list. Token <%.*s>\n", original_input.len, original_input.s);
return -1;
Expand Down Expand Up @@ -725,7 +727,7 @@ int ds_select_fixup(void** param, int param_no)
(char*)(*param), param_no);
}

maxlst = shm_malloc(sizeof(max_list_param_t));
maxlst = pkg_malloc(sizeof(max_list_param_t));
if (maxlst == NULL) {
LM_ERR("no mem\n");
return -1;
Expand Down

0 comments on commit dea3a12

Please sign in to comment.