  
      htp->server = evconnlistener_new(htp->evbase, _evhtp_accept_cb, htp,
                                       LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE,
+                                      backlog, fd);
+-    evhtp_errno_assert(htp->server != NULL);
++
++    if (!htp->server)
++    {
++        old_errno = errno;
++        evutil_closesocket(fd);
++        errno = old_errno;
++        return -1;
++    }
+ 
+ #ifndef EVHTP_DISABLE_SSL
+     if (htp->ssl_ctx != NULL) {

 
     fd = socket(sa->sa_family, SOCK_STREAM, 0);
     evhtp_errno_assert(fd != -1);
@@ -3220,7 +3221,13 @@ evhtp_bind_sockaddr(evhtp_t * htp, struct sockaddr * sa, size_t sin_len, int bac
     }
 #endif
 

diff --git a/evhtp.c b/evhtp.c
index 6ff6b90..f0a2a33 100644
--- a/evhtp.c
+++ b/evhtp.c
@@ -3185,6 +3185,7 @@ evhtp_bind_sockaddr(evhtp_t * htp, struct sockaddr * sa, size_t sin_len, int bac
