From dbcd85746ec1ba4a3be1af920dd2b1aad632297e Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Fri, 30 Jun 2017 14:02:20 +0200 Subject: [PATCH] call_control: free pkg memory in case of errors when parsing params --- src/modules/call_control/call_control.c | 29 ++++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/modules/call_control/call_control.c b/src/modules/call_control/call_control.c index a31892c7062..e1776de61a6 100644 --- a/src/modules/call_control/call_control.c +++ b/src/modules/call_control/call_control.c @@ -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; \ } @@ -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; @@ -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); @@ -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; } @@ -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; -} \ No newline at end of file +}