Description

I think that a memory leak accur when call get_uri_params function to get the params in Invite RURI. If RURI haven't params I don't see memory leaking, but yes if RURI have one or more params.

Troubleshooting

Reproduction

  1. In kamailio script load siputils module;
  2. Invoke get_uri_params in request_route;
  3. Make call traffic with params in Invite RURI;
  4. Check memory using pkg_stat kamcmd command during call traffic.

Possible Solutions

Looking the source code, it seems that the function doesn't free the memory allocated during parsing params (parse_params function), infact invoke the free procedure always with null value in params pointer.

I trying a simple modify saving the params poiter after parsing e use it in free function, than the memory don't accur!

int get_uri_param(struct sip_msg* _msg, char* _param, char* _value)
{
	str *param, t;
	pv_spec_t* dst;
	pv_value_t val;

	param_hooks_t hooks;
	param_t* params;
	param_t* parsed_params; // ----------------------> pointer declaretion

	param = (str*)_param;
	dst = (pv_spec_t *) _value;

	if (parse_sip_msg_uri(_msg) < 0) {
		LM_ERR("ruri parsing failed\n");
		return -1;
	}

	t = _msg->parsed_uri.params;

	if (parse_params(&t, CLASS_ANY, &hooks, &params) < 0) {
		LM_ERR("ruri parameter parsing failed\n");
		return -1;
	}
	parsed_params = params; // ---------------------> pointer assignment

	while (params) {
		if ((params->name.len == param->len)
				&& (strncmp(params->name.s, param->s, param->len) == 0)) {
			memset(&val, 0, sizeof(pv_value_t));
			val.rs.s = params->body.s;
			val.rs.len = params->body.len;
			val.flags = PV_VAL_STR;
			dst->setf(_msg, &dst->pvp, (int)EQ_T, &val);
			goto found;
		} else {
			params = params->next;
		}
	}
	
	free_params(parsed_params); // -----------------------> use parsed_pointer to free memory
	return -1;

found:
	free_params(parsed_params); // --------------------> use parsed_pointer to free memory
	return 1;
}

Additional Information

version: kamailio 5.3.1 (x86_64/linux) 
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, DBG_QM_MALLOC, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES
ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <kamailio/kamailio/issues/3857@github.com>