nwrap: Fix memory leak on error in nwrap_module_gethostbyaddr()
authorAndreas Schneider <asn@samba.org>
Mon, 17 Feb 2020 08:46:56 +0000 (09:46 +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 ff41eebd55b275ae10959b503fb1cc24f2ea9edc..f3e3af67cdf1e1adee2753cf186296b1d7a44c6b 100644 (file)
@@ -4487,11 +4487,15 @@ again:
        status = b->fns->_nss_gethostbyaddr_r(addr, len, type, &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) {