[asterisk-commits] rmudgett: trunk r433058 - in /trunk: ./ apps/ main/ res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Mar 17 16:52:50 CDT 2015


Author: rmudgett
Date: Tue Mar 17 16:52:47 2015
New Revision: 433058

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=433058
Log:
Audit ast_sockaddr_resolve() usage for memory leaks.

Valgrind found some memory leaks associated with ast_sockaddr_resolve().
Most of the leaks had already been fixed by earlier memory leak hunt
patches.  This patch performs an audit of ast_sockaddr_resolve() and found
one more.

* Fix ast_sockaddr_resolve() memory leak in
apps/app_externalivr.c:app_exec().

* Made main/netsock2.c:ast_sockaddr_resolve() always set the addrs
parameter for safety so the pointer will never be uninitialized on return.
The same goes for res/res_pjsip_acl.c:extract_contact_addr().

* Made functions that call ast_sockaddr_resolve() with RAII_VAR()
controlling the addrs variable use ast_free instead of ast_free_ptr to
provide better MALLOC_DEBUG information.

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

Merged revisions 433056 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 433057 from http://svn.asterisk.org/svn/asterisk/branches/13

Modified:
    trunk/   (props changed)
    trunk/apps/app_externalivr.c
    trunk/main/netsock2.c
    trunk/res/res_pjsip_acl.c
    trunk/res/res_pjsip_sdp_rtp.c
    trunk/res/res_pjsip_t38.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-13-merged' - no diff available.

Modified: trunk/apps/app_externalivr.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/app_externalivr.c?view=diff&rev=433058&r1=433057&r2=433058
==============================================================================
--- trunk/apps/app_externalivr.c (original)
+++ trunk/apps/app_externalivr.c Tue Mar 17 16:52:47 2015
@@ -518,6 +518,8 @@
 			}
 			break;
 		}
+
+		ast_free(addrs);
 
 		if (i == num_addrs) {
 			ast_chan_log(LOG_ERROR, chan, "Could not connect to any host.  ExternalIVR failed.\n");

Modified: trunk/main/netsock2.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/netsock2.c?view=diff&rev=433058&r1=433057&r2=433058
==============================================================================
--- trunk/main/netsock2.c (original)
+++ trunk/main/netsock2.c Tue Mar 17 16:52:47 2015
@@ -287,11 +287,13 @@
 	int	e, i, res_cnt;
 
 	if (!str) {
+		*addrs = NULL;
 		return 0;
 	}
 
 	s = ast_strdupa(str);
 	if (!ast_sockaddr_split_hostport(s, &host, &port, flags)) {
+		*addrs = NULL;
 		return 0;
 	}
 
@@ -302,6 +304,7 @@
 	if ((e = getaddrinfo(host, port, &hints, &res))) {
 		ast_log(LOG_ERROR, "getaddrinfo(\"%s\", \"%s\", ...): %s\n",
 			host, S_OR(port, "(null)"), gai_strerror(e));
+		*addrs = NULL;
 		return 0;
 	}
 
@@ -311,6 +314,7 @@
 	}
 
 	if (res_cnt == 0) {
+		*addrs = NULL;
 		goto cleanup;
 	}
 

Modified: trunk/res/res_pjsip_acl.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_acl.c?view=diff&rev=433058&r1=433057&r2=433058
==============================================================================
--- trunk/res/res_pjsip_acl.c (original)
+++ trunk/res/res_pjsip_acl.c Tue Mar 17 16:52:47 2015
@@ -139,9 +139,11 @@
 	char host[256];
 
 	if (!contact || contact->star) {
+		*addrs = NULL;
 		return 0;
 	}
 	if (!PJSIP_URI_SCHEME_IS_SIP(contact->uri) && !PJSIP_URI_SCHEME_IS_SIPS(contact->uri)) {
+		*addrs = NULL;
 		return 0;
 	}
 	sip_uri = pjsip_uri_get_uri(contact->uri);

Modified: trunk/res/res_pjsip_sdp_rtp.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_sdp_rtp.c?view=diff&rev=433058&r1=433057&r2=433058
==============================================================================
--- trunk/res/res_pjsip_sdp_rtp.c (original)
+++ trunk/res/res_pjsip_sdp_rtp.c Tue Mar 17 16:52:47 2015
@@ -758,7 +758,7 @@
 					 const struct pjmedia_sdp_session *sdp, const struct pjmedia_sdp_media *stream)
 {
 	char host[NI_MAXHOST];
-	RAII_VAR(struct ast_sockaddr *, addrs, NULL, ast_free_ptr);
+	RAII_VAR(struct ast_sockaddr *, addrs, NULL, ast_free);
 	enum ast_media_type media_type = stream_to_media_type(session_media->stream_type);
 	enum ast_sip_session_media_encryption encryption = AST_SIP_MEDIA_ENCRYPT_NONE;
 	int res;
@@ -1116,7 +1116,7 @@
 				       const struct pjmedia_sdp_session *local, const struct pjmedia_sdp_media *local_stream,
 				       const struct pjmedia_sdp_session *remote, const struct pjmedia_sdp_media *remote_stream)
 {
-	RAII_VAR(struct ast_sockaddr *, addrs, NULL, ast_free_ptr);
+	RAII_VAR(struct ast_sockaddr *, addrs, NULL, ast_free);
 	enum ast_media_type media_type = stream_to_media_type(session_media->stream_type);
 	char host[NI_MAXHOST];
 	int fdno, res;

Modified: trunk/res/res_pjsip_t38.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_t38.c?view=diff&rev=433058&r1=433057&r2=433058
==============================================================================
--- trunk/res/res_pjsip_t38.c (original)
+++ trunk/res/res_pjsip_t38.c Tue Mar 17 16:52:47 2015
@@ -619,7 +619,7 @@
 {
 	struct t38_state *state;
 	char host[NI_MAXHOST];
-	RAII_VAR(struct ast_sockaddr *, addrs, NULL, ast_free_ptr);
+	RAII_VAR(struct ast_sockaddr *, addrs, NULL, ast_free);
 
 	if (!session->endpoint->media.t38.enabled) {
 		return -1;
@@ -762,7 +762,7 @@
 				       const struct pjmedia_sdp_session *local, const struct pjmedia_sdp_media *local_stream,
 				       const struct pjmedia_sdp_session *remote, const struct pjmedia_sdp_media *remote_stream)
 {
-	RAII_VAR(struct ast_sockaddr *, addrs, NULL, ast_free_ptr);
+	RAII_VAR(struct ast_sockaddr *, addrs, NULL, ast_free);
 	char host[NI_MAXHOST];
 	struct t38_state *state;
 




More information about the asterisk-commits mailing list