nwrap: Fix memory leak on error in nwrap_module_gethostbyname()
authorAndreas Schneider <asn@samba.org>
Mon, 17 Feb 2020 08:48:44 +0000 (09:48 +0100)
committerAndreas Schneider <asn@samba.org>
Mon, 17 Feb 2020 08:50:27 +0000 (09:50 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Isaac Boukris <iboukris@samba.org>
src/nss_wrapper.c

index f3e3af67cdf1e1adee2753cf186296b1d7a44c6b..921ecdec44aca03ff25aa9641d825a6ff2b908de 100644 (file)
@@ -4571,11 +4571,15 @@ again:
        status = b->fns->_nss_gethostbyname2_r(name, AF_UNSPEC, &he,
                                               buf, buflen, &errno, &h_errno);
        if (status == NSS_STATUS_TRYAGAIN) {
+               char *p = NULL;
+
                buflen *= 2;
-               buf = (char *)realloc(buf, buflen);
-               if (buf == NULL) {
+               p = (char *)realloc(buf, buflen);
+               if (p == NULL) {
+                       SAFE_FREE(buf);
                        return NULL;
                }
+               buf = p;
                goto again;
        }
        if (status == NSS_STATUS_NOTFOUND) {