diff --git a/lib/hostip.c b/lib/hostip.c
index 89ac57462e8b44a7c3dfe61dad28430e7ff9da3e..dc2ed0aecdd6334be2bad010e3f447e07ee59023 100644
--- a/lib/hostip.c
+++ b/lib/hostip.c
@@ -187,12 +187,14 @@ struct hostent *GetHost(struct UrlData *data,
       infof(data, "gethostbyname_r(2) failed for %s\n", hostname);
       h = NULL; /* set return code to NULL */
       free(buf);
+      *bufp=NULL;
     }
 #else
   else {
     if ((h = gethostbyname(hostname)) == NULL ) {
       infof(data, "gethostbyname(2) failed for %s\n", hostname);
       free(buf);
+      *bufp=NULL;
     }
 #endif
   }