nwrap: Fix memory leak on error in nwrap_module_gethostbyname2()
authorAndreas Schneider <asn@samba.org>
Mon, 17 Feb 2020 08:49:54 +0000 (09:49 +0100)
committerAndreas Schneider <asn@samba.org>
Mon, 17 Feb 2020 09:42:41 +0000 (10:42 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Isaac Boukris <iboukris@samba.org>
src/nss_wrapper.c

index 921ecdec44aca03ff25aa9641d825a6ff2b908de..5c4c972819865c06b59d191da6ce625ec7eec517 100644 (file)
@@ -4617,11 +4617,15 @@ again:
        status = b->fns->_nss_gethostbyname2_r(name, af, &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) {