From db15dbfd66acaba17d525a391c0973d3fa8a7b4a Mon Sep 17 00:00:00 2001 From: Alex Hermann Date: Mon, 5 Nov 2012 12:40:07 +0100 Subject: [PATCH 1/9] dispatcher: free memory on shutdown Debugging memleaks is easier when the list of alloc'ed shmem is shorter. --- modules/dispatcher/dispatcher.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/dispatcher/dispatcher.c b/modules/dispatcher/dispatcher.c index 478c96f24b2..892ec18b280 100644 --- a/modules/dispatcher/dispatcher.c +++ b/modules/dispatcher/dispatcher.c @@ -596,7 +596,8 @@ static void destroy(void) ds_hash_load_destroy(); if(ds_ping_reply_codes) shm_free(ds_ping_reply_codes); - + if(ds_ping_reply_codes_cnt) + shm_free(ds_ping_reply_codes_cnt); } #define GET_VALUE(param_name,param,i_value,s_value,value_flags) do{ \ From fa11a6bd50aa00994c71561b8de8b0dc8659fe55 Mon Sep 17 00:00:00 2001 From: Alex Hermann Date: Mon, 27 Oct 2014 14:38:03 +0100 Subject: [PATCH 2/9] pv: xavp: log error message when memory allocation fails --- modules/pv/pv_xavp.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/pv/pv_xavp.c b/modules/pv/pv_xavp.c index 67ffd45d9e2..e4e94f3c963 100644 --- a/modules/pv/pv_xavp.c +++ b/modules/pv/pv_xavp.c @@ -506,8 +506,10 @@ int pv_parse_xavp_name(pv_spec_p sp, str *in) return -1; xname = (pv_xavp_name_t*)pkg_malloc(sizeof(pv_xavp_name_t)); - if(xname==NULL) + if(xname==NULL) { + LM_ERR("not enough pkg mem\n"); return -1; + } memset(xname, 0, sizeof(pv_xavp_name_t)); @@ -530,9 +532,10 @@ int pv_parse_xavp_name(pv_spec_p sp, str *in) xname->name.s, s.len, s.s); xname->next = (pv_xavp_name_t*)pkg_malloc(sizeof(pv_xavp_name_t)); - if(xname->next==NULL) + if(xname->next==NULL) { + LM_ERR("not enough pkg mem\n"); goto error; - + } memset(xname->next, 0, sizeof(pv_xavp_name_t)); p = pv_xavp_fill_ni(&s, xname->next); From cf085a870e33bcdef5dad91a3de92f25e159e669 Mon Sep 17 00:00:00 2001 From: Alex Hermann Date: Wed, 5 Nov 2014 22:14:21 +0100 Subject: [PATCH 3/9] core: Enable SIGUSR1 for child processes Allow dumping of memory statistics during runtime --- main.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 7993590abd3..887a58a25a5 100644 --- a/main.c +++ b/main.c @@ -833,7 +833,20 @@ void sig_usr(int signo) _exit(0); break; case SIGUSR1: - /* statistics, do nothing, printed only from the main proc */ +#ifdef PKG_MALLOC + cfg_update_no_cbs(); + memlog=cfg_get(core, core_cfg, memlog); + if (memlog <= cfg_get(core, core_cfg, debug)){ + if (cfg_get(core, core_cfg, mem_summary) & 1) { + LOG(memlog, "Memory status (pkg):\n"); + pkg_status(); + } + if (cfg_get(core, core_cfg, mem_summary) & 2) { + LOG(memlog, "Memory still-in-use summary (pkg):\n"); + pkg_sums(); + } + } +#endif break; /* ignored*/ case SIGUSR2: From d33e8efc93446c1d5a092740b5a2387dea5de1fc Mon Sep 17 00:00:00 2001 From: Alex Hermann Date: Thu, 13 Nov 2014 10:55:29 +0100 Subject: [PATCH 4/9] mqueu: Convert items to single linked list The doubly-lined feature is not used as the prev attribute was write-only-memory. --- modules/mqueue/mqueue_api.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/modules/mqueue/mqueue_api.c b/modules/mqueue/mqueue_api.c index d9a85362ca1..85ddf7e18ad 100644 --- a/modules/mqueue/mqueue_api.c +++ b/modules/mqueue/mqueue_api.c @@ -44,7 +44,6 @@ typedef struct _mq_item { str key; str val; - struct _mq_item *prev; struct _mq_item *next; } mq_item_t; @@ -266,8 +265,6 @@ int mq_head_fetch(str *name) mh->ifirst = mh->ifirst->next; if(mh->ifirst==NULL) { mh->ilast = NULL; - } else { - mh->ifirst->prev = NULL; } mh->csize--; @@ -332,7 +329,6 @@ int mq_item_add(str *qname, str *key, str *val) mh->ilast = mi; } else { mh->ilast->next = mi; - mi->prev = mh->ilast; mh->ilast = mi; } mh->csize++; @@ -341,9 +337,9 @@ int mq_item_add(str *qname, str *key, str *val) mi = mh->ifirst; mh->ifirst = mh->ifirst->next; if(mh->ifirst==NULL) + { mh->ilast = NULL; - else - mh->ifirst->prev = NULL; + } mh->csize--; shm_free(mi); } From 72ae9283fa969c13ba1c6d599c2844e1473883f4 Mon Sep 17 00:00:00 2001 From: Alex Hermann Date: Thu, 12 May 2016 16:05:29 +0200 Subject: [PATCH 5/9] tmx: Try to get branch_index for all replies Just check if the tm context is set and return its branch_index. The check for CORE_ONREPLY_ROUTE is flawed as the transaction may have been set anyway (by t_check_trans() for example). --- modules/tmx/t_var.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/tmx/t_var.c b/modules/tmx/t_var.c index 6e83761127a..83cd8c68d4a 100644 --- a/modules/tmx/t_var.c +++ b/modules/tmx/t_var.c @@ -396,7 +396,7 @@ int pv_get_tm_branch_idx(struct sip_msg *msg, pv_param_t *param, return -1; /* statefull replies have the branch_index set */ - if(msg->first_line.type == SIP_REPLY && route_type != CORE_ONREPLY_ROUTE) { + if(msg->first_line.type == SIP_REPLY) { tcx = _tmx_tmb.tm_ctx_get(); if(tcx != NULL) idx = tcx->branch_index; From bbacab495841ef270f98b743352ad8aca9649b47 Mon Sep 17 00:00:00 2001 From: Alex Hermann Date: Mon, 4 Jul 2016 16:41:18 +0200 Subject: [PATCH 6/9] jsonrpc_s: Return an error when JSON parsing fails --- modules/jsonrpc-s/jsonrpc-s_mod.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/jsonrpc-s/jsonrpc-s_mod.c b/modules/jsonrpc-s/jsonrpc-s_mod.c index 62f25064a6e..9c0fc723bed 100644 --- a/modules/jsonrpc-s/jsonrpc-s_mod.c +++ b/modules/jsonrpc-s/jsonrpc-s_mod.c @@ -571,7 +571,7 @@ static int jsonrpc_scan(jsonrpc_ctx_t* ctx, char* fmt, ...) case '{': case '[': LM_ERR("Unsupported param type '%c'\n", *fmt); - jsonrpc_fault(ctx, 500, "Unsupported param type"); + jsonrpc_fault(ctx, 400, "Unsupported param type"); goto error; default: LM_ERR("Invalid param type in formatting string: [%c]\n", *fmt); @@ -1041,7 +1041,7 @@ static int jsonrpc_dispatch(sip_msg_t* msg, char* s1, char* s2) ctx->jreq = srjson_NewDoc(NULL); if(ctx->jreq==NULL) { LM_ERR("Failed to init the json document\n"); - return NONSIP_MSG_PASS; + return NONSIP_MSG_ERROR; } ctx->jreq->buf.s = get_body(msg); @@ -1050,7 +1050,7 @@ static int jsonrpc_dispatch(sip_msg_t* msg, char* s1, char* s2) if(ctx->jreq->root == NULL) { LM_ERR("invalid json doc [[%s]]\n", ctx->jreq->buf.s); - return NONSIP_MSG_PASS; + return NONSIP_MSG_ERROR; } if (jsonrpc_init_reply(ctx) < 0) goto send_reply; From 8102ca5f67de979a3597a97f96a05c99d13fb29d Mon Sep 17 00:00:00 2001 From: Alex Hermann Date: Thu, 21 Jul 2016 13:29:38 +0200 Subject: [PATCH 7/9] core: Don't bind to IPv6 addresses if auto_bind_ipv6 is disabled With the following listen statement: listen=udp:eth0:5060 Kamailio would try to bind to the IPv6 address(es) on that interface and fail with: ERROR: [udp_server.c:369]: udp_init(): might be caused by using a link local address, try site local or global --- socket_info.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/socket_info.c b/socket_info.c index aa8928aac62..ee48e11d8e6 100644 --- a/socket_info.c +++ b/socket_info.c @@ -1406,8 +1406,8 @@ static int fix_socket_list(struct socket_info **list, int* type_flags) for (si=*list;si;){ next=si->next; ai_lst=0; - if (add_interfaces(si->name.s, 0, si->port_no, - si->proto, &ai_lst)!=-1){ + if (add_interfaces(si->name.s, auto_bind_ipv6 ? 0 : AF_INET, + si->port_no, si->proto, &ai_lst)!=-1){ if (si->flags & SI_IS_MHOMED){ if((new_si=new_sock2list_after(ai_lst->name.s, 0, si->port_no, si->proto, si->useinfo.name.s, From d2f695d63266a5e1762db2e762396e7943687180 Mon Sep 17 00:00:00 2001 From: Alex Hermann Date: Fri, 5 Aug 2016 14:40:01 +0200 Subject: [PATCH 8/9] sl: Reset timeout before sending the message Fix a common race where the reply would arrive before resetting the timeout. --- modules/sl/sl_funcs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/sl/sl_funcs.c b/modules/sl/sl_funcs.c index a65a7b84bf5..ec5a2baa4cb 100644 --- a/modules/sl/sl_funcs.c +++ b/modules/sl/sl_funcs.c @@ -182,6 +182,8 @@ int sl_reply_helper(struct sip_msg *msg, int code, char *reason, str *tag) sl_run_callbacks(SLCB_REPLY_READY, msg, code, reason, &buf, &dst); + *(sl_timeout) = get_ticks() + SL_RPL_WAIT_TIME; + /* supress multhoming support when sending a reply back -- that makes sure that replies will come from where requests came in; good for NATs (there is no known use for mhomed for locally generated replies; @@ -286,8 +288,6 @@ int sl_reply_helper(struct sip_msg *msg, int code, char *reason, str *tag) if (ret<0) { goto error; } - - *(sl_timeout) = get_ticks() + SL_RPL_WAIT_TIME; update_sl_stats(code); return 1; From 28224ba2da2cc111239c173bedfcc4a7c295f394 Mon Sep 17 00:00:00 2001 From: Alex Hermann Date: Fri, 5 Aug 2016 14:53:31 +0200 Subject: [PATCH 9/9] sl: Convert get_ticks() to the somewhat faster get_ticks_raw() Avoid a multiplication on every call. --- modules/sl/sl_funcs.c | 6 +++--- modules/sl/sl_funcs.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/sl/sl_funcs.c b/modules/sl/sl_funcs.c index ec5a2baa4cb..ac7701c83c1 100644 --- a/modules/sl/sl_funcs.c +++ b/modules/sl/sl_funcs.c @@ -86,7 +86,7 @@ int sl_startup() LOG(L_ERR,"ERROR:sl_startup: no more free memory!\n"); return -1; } - *(sl_timeout)=get_ticks(); + *(sl_timeout)=get_ticks_raw(); return 1; } @@ -182,7 +182,7 @@ int sl_reply_helper(struct sip_msg *msg, int code, char *reason, str *tag) sl_run_callbacks(SLCB_REPLY_READY, msg, code, reason, &buf, &dst); - *(sl_timeout) = get_ticks() + SL_RPL_WAIT_TIME; + *(sl_timeout) = get_ticks_raw() + SL_RPL_WAIT_TIME; /* supress multhoming support when sending a reply back -- that makes sure that replies will come from where requests came in; good for NATs @@ -383,7 +383,7 @@ int sl_filter_ACK(struct sip_msg *msg, unsigned int flags, void *bar ) goto pass_it; /*check the timeout value*/ - if ( *(sl_timeout)<= get_ticks() ) + if ( *(sl_timeout)<= get_ticks_raw() ) { DBG("DEBUG : sl_filter_ACK: to late to be a local ACK!\n"); goto pass_it; diff --git a/modules/sl/sl_funcs.h b/modules/sl/sl_funcs.h index 4928fc9cf37..077ad93a102 100644 --- a/modules/sl/sl_funcs.h +++ b/modules/sl/sl_funcs.h @@ -24,8 +24,9 @@ #include "../../sr_module.h" #include "../../parser/msg_parser.h" +#include "../../timer_ticks.h" -#define SL_RPL_WAIT_TIME 2 /* in sec */ +#define SL_RPL_WAIT_TIME S_TO_TICKS(2) /* in sec */ #define SL_TOTAG_SEPARATOR '.'