nwrap: Use calloc() to allocate addr_list vector
authorAndreas Schneider <asn@samba.org>
Tue, 17 Mar 2020 19:13:19 +0000 (20:13 +0100)
committerAndreas Schneider <asn@samba.org>
Tue, 17 Mar 2020 19:13:19 +0000 (20:13 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
Reviewed-by: Samuel Cabrero <scabrero@suse.de>
src/nss_wrapper.c

index b02e11fd1dd2d12d8151c76a8de4bbc2c783a734..e7b52bbab659b1fe9641696bd6c8920f325d2222 100644 (file)
@@ -3711,7 +3711,7 @@ static int nwrap_files_gethostbyname2_r(struct nwrap_backend *b,
                                        char *buf, size_t buflen,
                                        struct hostent **hedstp)
 {
-       struct nwrap_vector *addr_list = malloc(sizeof(struct nwrap_vector));
+       struct nwrap_vector *addr_list = NULL;
        union {
                char *ptr;
                char **list;
@@ -3721,6 +3721,7 @@ static int nwrap_files_gethostbyname2_r(struct nwrap_backend *b,
        (void) b; /* unused */
        (void) af; /* unused */
 
+       addr_list = calloc(1, sizeof(struct nwrap_vector));
        if (addr_list == NULL) {
                NWRAP_LOG(NWRAP_LOG_ERROR,
                          "Unable to allocate memory for address list");
@@ -3728,8 +3729,6 @@ static int nwrap_files_gethostbyname2_r(struct nwrap_backend *b,
                return -1;
        }
 
-       ZERO_STRUCTP(addr_list);
-
        rc = nwrap_files_internal_gethostbyname(name, AF_UNSPEC, hedst,
                                                addr_list);
        if (rc == -1) {