Skip to content

Commit

Permalink
call_control: free pkg memory in case of errors when parsing params
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Jun 30, 2017
1 parent e5134e8 commit dbcd857
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/modules/call_control/call_control.c
Expand Up @@ -218,13 +218,13 @@ typedef struct CallInfo {
#define CHECK_COND(cond) \
if ((cond) == 0) { \
LM_ERR("malformed modparam\n"); \
return -1; \
goto error; \
}

#define CHECK_ALLOC(p) \
if (!(p)) { \
LM_ERR("no memory left\n"); \
return -1; \
goto error; \
}


Expand All @@ -242,9 +242,9 @@ destroy_list(AVP_List *list) {


int
parse_param(void *val, AVP_List** avps) {
cc_parse_param(void *val, AVP_List** avps) {

char *p;
char *p = NULL;
str s, content;
AVP_List *mp = NULL;

Expand All @@ -253,6 +253,10 @@ parse_param(void *val, AVP_List** avps) {
content.s = (char*) val;
content.len = strlen(content.s);

if(content.len==0) {
LM_ERR("empty parameter\n");
return -1;
}

p = (char*) pkg_malloc (content.len + 1);
CHECK_ALLOC(p);
Expand Down Expand Up @@ -298,26 +302,35 @@ parse_param(void *val, AVP_List** avps) {
}

return 0;

error:
if(mp) {
if(mp->pv) {
pkg_free(mp->pv);
}
pkg_free(mp);
}
return -1;
}


int
parse_param_init(unsigned int type, void *val) {
if (parse_param(val, &cc_init_avps) == -1)
if (cc_parse_param(val, &cc_init_avps) == -1)
return E_CFG;
return 0;
}

int
parse_param_start(unsigned int type, void *val) {
if (parse_param(val, &cc_start_avps) == -1)
if (cc_parse_param(val, &cc_start_avps) == -1)
return E_CFG;
return 0;
}

int
parse_param_stop(unsigned int type, void *val) {
if (parse_param(val, &cc_stop_avps) == -1)
if (cc_parse_param(val, &cc_stop_avps) == -1)
return E_CFG;
return 0;
}
Expand Down Expand Up @@ -1233,4 +1246,4 @@ int mod_register(char *path, int *dlflags, void *p1, void *p2)
{
sr_kemi_modules_add(sr_kemi_call_control_exports);
return 0;
}
}

0 comments on commit dbcd857

Please sign in to comment.