[asterisk-commits] rmudgett: branch 13 r433222 - in /branches/13/res: ./ res_pjsip/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 20 14:52:34 CDT 2015


Author: rmudgett
Date: Fri Mar 20 14:52:30 2015
New Revision: 433222

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=433222
Log:
Audit ast_pjsip_rdata_get_endpoint() usage for ref leaks.

Valgrind found some memory leaks associated with
ast_pjsip_rdata_get_endpoint().  The leaks would manifest when sending
responses to OPTIONS requests, processing MESSAGE requests, and
res_pjsip supplements implementing the incoming_request callback.

* Fix ast_pjsip_rdata_get_endpoint() endpoint ref leaks in
res/res_pjsip.c:supplement_on_rx_request(),
res/res_pjsip/pjsip_options.c:send_options_response(),
res/res_pjsip_messaging.c:rx_data_to_ast_msg(), and
res/res_pjsip_messaging.c:send_response().

* Eliminated RAII_VAR() use with ast_pjsip_rdata_get_endpoint() in
res/res_pjsip_nat.c:nat_on_rx_message().

* Fixed inconsistent but benign return value in
res/res_pjsip/pjsip_options.c:options_on_rx_request().

Review: https://reviewboard.asterisk.org/r/4511/

Modified:
    branches/13/res/res_pjsip.c
    branches/13/res/res_pjsip/pjsip_options.c
    branches/13/res/res_pjsip_messaging.c
    branches/13/res/res_pjsip_nat.c

Modified: branches/13/res/res_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/res/res_pjsip.c?view=diff&rev=433222&r1=433221&r2=433222
==============================================================================
--- branches/13/res/res_pjsip.c (original)
+++ branches/13/res/res_pjsip.c Fri Mar 20 14:52:30 2015
@@ -3257,8 +3257,13 @@
 
 	AST_RWLIST_RDLOCK(&supplements);
 	AST_LIST_TRAVERSE(&supplements, supplement, next) {
-		if (supplement->incoming_request && does_method_match(&rdata->msg_info.msg->line.req.method.name, supplement->method)) {
-			supplement->incoming_request(ast_pjsip_rdata_get_endpoint(rdata), rdata);
+		if (supplement->incoming_request
+			&& does_method_match(&rdata->msg_info.msg->line.req.method.name, supplement->method)) {
+			struct ast_sip_endpoint *endpoint;
+
+			endpoint = ast_pjsip_rdata_get_endpoint(rdata);
+			supplement->incoming_request(endpoint, rdata);
+			ao2_cleanup(endpoint);
 		}
 	}
 	AST_RWLIST_UNLOCK(&supplements);
@@ -3274,7 +3279,8 @@
 
 	AST_RWLIST_RDLOCK(&supplements);
 	AST_LIST_TRAVERSE(&supplements, supplement, next) {
-		if (supplement->outgoing_response && does_method_match(&cseq->method.name, supplement->method)) {
+		if (supplement->outgoing_response
+			&& does_method_match(&cseq->method.name, supplement->method)) {
 			supplement->outgoing_response(sip_endpoint, contact, tdata);
 		}
 	}

Modified: branches/13/res/res_pjsip/pjsip_options.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/res/res_pjsip/pjsip_options.c?view=diff&rev=433222&r1=433221&r2=433222
==============================================================================
--- branches/13/res/res_pjsip/pjsip_options.c (original)
+++ branches/13/res/res_pjsip/pjsip_options.c Fri Mar 20 14:52:30 2015
@@ -609,17 +609,20 @@
 	if (dlg && trans) {
 		status = pjsip_dlg_send_response(dlg, trans, tdata);
 	} else {
-		/* Get where to send request. */
-		if ((status = pjsip_get_response_addr(
-			     tdata->pool, rdata, &res_addr)) != PJ_SUCCESS) {
-			ast_log(LOG_ERROR, "Unable to get response address (%d)\n",
-				status);
+		struct ast_sip_endpoint *endpoint;
+
+		/* Get where to send response. */
+		status = pjsip_get_response_addr(tdata->pool, rdata, &res_addr);
+		if (status != PJ_SUCCESS) {
+			ast_log(LOG_ERROR, "Unable to get response address (%d)\n", status);
 
 			pjsip_tx_data_dec_ref(tdata);
 			return status;
 		}
-		status = ast_sip_send_response(&res_addr, tdata,
-						   ast_pjsip_rdata_get_endpoint(rdata));
+
+		endpoint = ast_pjsip_rdata_get_endpoint(rdata);
+		status = ast_sip_send_response(&res_addr, tdata, endpoint);
+		ao2_cleanup(endpoint);
 	}
 
 	if (status != PJ_SUCCESS) {
@@ -648,7 +651,7 @@
 	ruri = rdata->msg_info.msg->line.req.uri;
 	if (!PJSIP_URI_SCHEME_IS_SIP(ruri) && !PJSIP_URI_SCHEME_IS_SIPS(ruri)) {
 		send_options_response(rdata, 416);
-		return -1;
+		return PJ_TRUE;
 	}
 
 	sip_ruri = pjsip_uri_get_uri(ruri);

Modified: branches/13/res/res_pjsip_messaging.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/res/res_pjsip_messaging.c?view=diff&rev=433222&r1=433221&r2=433222
==============================================================================
--- branches/13/res/res_pjsip_messaging.c (original)
+++ branches/13/res/res_pjsip_messaging.c Fri Mar 20 14:52:30 2015
@@ -427,13 +427,13 @@
  */
 static enum pjsip_status_code rx_data_to_ast_msg(pjsip_rx_data *rdata, struct ast_msg *msg)
 {
-	struct ast_sip_endpoint *endpt = ast_pjsip_rdata_get_endpoint(rdata);
+	RAII_VAR(struct ast_sip_endpoint *, endpt, NULL, ao2_cleanup);
 	pjsip_uri *ruri = rdata->msg_info.msg->line.req.uri;
 	pjsip_sip_uri *sip_ruri;
 	pjsip_name_addr *name_addr;
 	char buf[MAX_BODY_SIZE];
 	const char *field;
-	const char *context = S_OR(endpt->message_context, endpt->context);
+	const char *context;
 	char exten[AST_MAX_EXTENSION];
 	int res = 0;
 	int size;
@@ -445,6 +445,10 @@
 	sip_ruri = pjsip_uri_get_uri(ruri);
 	ast_copy_pj_str(exten, &sip_ruri->user, AST_MAX_EXTENSION);
 
+	endpt = ast_pjsip_rdata_get_endpoint(rdata);
+	ast_assert(endpt != NULL);
+
+	context = S_OR(endpt->message_context, endpt->context);
 	res |= ast_msg_set_context(msg, "%s", context);
 	res |= ast_msg_set_exten(msg, "%s", exten);
 
@@ -617,13 +621,18 @@
 	if (dlg && tsx) {
 		status = pjsip_dlg_send_response(dlg, tsx, tdata);
 	} else {
-		/* Get where to send request. */
+		struct ast_sip_endpoint *endpoint;
+
+		/* Get where to send response. */
 		status = pjsip_get_response_addr(tdata->pool, rdata, &res_addr);
 		if (status != PJ_SUCCESS) {
 			ast_log(LOG_ERROR, "Unable to get response address (%d)\n", status);
 			return status;
 		}
-		status = ast_sip_send_response(&res_addr, tdata, ast_pjsip_rdata_get_endpoint(rdata));
+
+		endpoint = ast_pjsip_rdata_get_endpoint(rdata);
+		status = ast_sip_send_response(&res_addr, tdata, endpoint);
+		ao2_cleanup(endpoint);
 	}
 
 	if (status != PJ_SUCCESS) {

Modified: branches/13/res/res_pjsip_nat.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/res/res_pjsip_nat.c?view=diff&rev=433222&r1=433221&r2=433222
==============================================================================
--- branches/13/res/res_pjsip_nat.c (original)
+++ branches/13/res/res_pjsip_nat.c Fri Mar 20 14:52:30 2015
@@ -72,8 +72,13 @@
 
 static pj_bool_t nat_on_rx_message(pjsip_rx_data *rdata)
 {
-	RAII_VAR(struct ast_sip_endpoint *, endpoint, ast_pjsip_rdata_get_endpoint(rdata), ao2_cleanup);
-	return handle_rx_message(endpoint, rdata);
+	pj_bool_t res;
+	struct ast_sip_endpoint *endpoint;
+
+	endpoint = ast_pjsip_rdata_get_endpoint(rdata);
+	res = handle_rx_message(endpoint, rdata);
+	ao2_cleanup(endpoint);
+	return res;
 }
 
 /*! \brief Structure which contains information about a transport */




More information about the asterisk-commits mailing list