]> granicus.if.org Git - libevent/commitdiff
listener: Preserve last error in evconnlistener_new_bind() before close
authorkenping <kenpingliu@users.noreply.github.com>
Thu, 21 Apr 2022 07:59:28 +0000 (15:59 +0800)
committerAzat Khuzhin <azat@libevent.org>
Sat, 9 Jul 2022 17:20:58 +0000 (20:20 +0300)
In function evconnlistener_new_bind() after go to "err:", The
evutil_closesocket() would clear the error code( I found this under
Windows ). User can not use EVUTIL_SOCKET_ERROR() to get the
evconnlistener_new_bind()'s failing error.

I add a err_code variable to store and restore the last error code.

v2: rebased by azat to make the patch simpler

listener.c

index 125c7286f09141abcb58248776f2f2eeeae3176b..fc7c2c583c49a7f6afa21f3dbb5168bd6d38a6c5 100644 (file)
@@ -275,8 +275,13 @@ evconnlistener_new_bind(struct event_base *base, evconnlistener_cb cb,
 
        return listener;
 err:
-       evutil_closesocket(fd);
-       return NULL;
+       {
+               int saved_errno = EVUTIL_SOCKET_ERROR();
+               evutil_closesocket(fd);
+               if (saved_errno)
+                       EVUTIL_SET_SOCKET_ERROR(saved_errno);
+               return NULL;
+       }
 }
 
 void