From c88940308665ca4616aa54505e61bddf868ad1f0 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Sun, 27 Mar 2011 13:54:52 +0000 Subject: [PATCH] In the IPv6-aware connect_to(), allocate http->host_ip_addr_str outside the loop and reuse the buffer in case of errors I think this also fixes an unlikely memory leak, but I haven't actually verified it. --- jbsockets.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/jbsockets.c b/jbsockets.c index 81befe35..933b9992 100644 --- a/jbsockets.c +++ b/jbsockets.c @@ -1,4 +1,4 @@ -const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.83 2011/03/27 13:53:25 fabiankeil Exp $"; +const char jbsockets_rcs[] = "$Id: jbsockets.c,v 1.84 2011/03/27 13:53:49 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jbsockets.c,v $ @@ -212,6 +212,14 @@ static jb_socket rfc2553_connect_to(const char *host, int portnum, struct client return(JB_INVALID_SOCKET); } + csp->http->host_ip_addr_str = malloc(NI_MAXHOST); + if (NULL == csp->http->host_ip_addr_str) + { + log_error(LOG_LEVEL_ERROR, + "Out of memory while getting the server IP address."); + return JB_INVALID_SOCKET; + } + for (rp = result; rp != NULL; rp = rp->ai_next) { @@ -229,13 +237,6 @@ static jb_socket rfc2553_connect_to(const char *host, int portnum, struct client } #endif /* def FEATURE_ACL */ - csp->http->host_ip_addr_str = malloc(NI_MAXHOST); - if (NULL == csp->http->host_ip_addr_str) - { - log_error(LOG_LEVEL_ERROR, - "Out of memory while getting the server IP address."); - return JB_INVALID_SOCKET; - } retval = getnameinfo(rp->ai_addr, rp->ai_addrlen, csp->http->host_ip_addr_str, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); if (retval) @@ -243,7 +244,6 @@ static jb_socket rfc2553_connect_to(const char *host, int portnum, struct client log_error(LOG_LEVEL_ERROR, "Can not save csp->http->host_ip_addr_str: %s", gai_strerror(retval)); - freez(csp->http->host_ip_addr_str); continue; } -- 2.39.2