krb5 commit: Fix minor leak in k5_os_hostaddr()

Greg Hudson <[email protected]>
Newsgroups gmane.comp.encryption.kerberos.cvs
Message-ID <[email protected]>
https://github.com/krb5/krb5/commit/0f1ebd3dc612a58e2e3a019ab97965369a354e59
commit 0f1ebd3dc612a58e2e3a019ab97965369a354e59
Author: Greg Hudson <[email protected]>
Date:   Fri Jun 15 11:31:04 2018 -0400

    Fix minor leak in k5_os_hostaddr()
    
    In k5_os_hostaddr(), if allocation of the result array fails, use the
    cleanup handler so that the getaddrinfo() result is freed.  Also
    initialize the pointers which are freed in the cleanup handler for
    safety.  Reported by Bean Zhang.
    
    ticket: 8699

 src/lib/krb5/os/hostaddr.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/lib/krb5/os/hostaddr.c b/src/lib/krb5/os/hostaddr.c
index d7a4a76..129a4ad 100644
--- a/src/lib/krb5/os/hostaddr.c
+++ b/src/lib/krb5/os/hostaddr.c
@@ -34,9 +34,9 @@ k5_os_hostaddr(krb5_context context, const char *name,
                krb5_address ***ret_addrs)
 {
     krb5_error_code     retval;
-    krb5_address        **addrs;
+    krb5_address        **addrs = NULL;
     int                 i, j, r;
-    struct addrinfo hints, *ai, *aip;
+    struct addrinfo hints, *ai = NULL, *aip;
 
     if (!name)
         return KRB5_ERR_BAD_HOSTNAME;
@@ -68,9 +68,9 @@ k5_os_hostaddr(krb5_context context, const char *name,
         }
     }
 
-    addrs = malloc ((i+1) * sizeof(*addrs));
-    if (!addrs)
-        return ENOMEM;
+    addrs = k5calloc(i + 1, sizeof(*addrs), &retval);
+    if (addrs == NULL)
+        goto errout;
 
     for (j = 0; j < i + 1; j++)
         addrs[j] = 0;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.