Author: rmudgett
Date: Tue Mar 17 16:49:30 2015
New Revision: 433057

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=433057
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

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

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

Modified: branches/13/apps/app_externalivr.c
URL: 
http://svnview.digium.com/svn/asterisk/branches/13/apps/app_externalivr.c?view=diff&rev=433057&r1=433056&r2=433057
==============================================================================
--- branches/13/apps/app_externalivr.c (original)
+++ branches/13/apps/app_externalivr.c Tue Mar 17 16:49:30 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: branches/13/main/netsock2.c
URL: 
http://svnview.digium.com/svn/asterisk/branches/13/main/netsock2.c?view=diff&rev=433057&r1=433056&r2=433057
==============================================================================
--- branches/13/main/netsock2.c (original)
+++ branches/13/main/netsock2.c Tue Mar 17 16:49:30 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: branches/13/res/res_pjsip_acl.c
URL: 
http://svnview.digium.com/svn/asterisk/branches/13/res/res_pjsip_acl.c?view=diff&rev=433057&r1=433056&r2=433057
==============================================================================
--- branches/13/res/res_pjsip_acl.c (original)
+++ branches/13/res/res_pjsip_acl.c Tue Mar 17 16:49:30 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: branches/13/res/res_pjsip_sdp_rtp.c
URL: 
http://svnview.digium.com/svn/asterisk/branches/13/res/res_pjsip_sdp_rtp.c?view=diff&rev=433057&r1=433056&r2=433057
==============================================================================
--- branches/13/res/res_pjsip_sdp_rtp.c (original)
+++ branches/13/res/res_pjsip_sdp_rtp.c Tue Mar 17 16:49:30 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;
@@ -1115,7 +1115,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: branches/13/res/res_pjsip_t38.c
URL: 
http://svnview.digium.com/svn/asterisk/branches/13/res/res_pjsip_t38.c?view=diff&rev=433057&r1=433056&r2=433057
==============================================================================
--- branches/13/res/res_pjsip_t38.c (original)
+++ branches/13/res/res_pjsip_t38.c Tue Mar 17 16:49:30 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;
 


-- 
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

svn-commits mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/svn-commits

Reply via email to