From 00e87078302dcfca3b6ad04fd5af5d8f473171a9 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 2 Mar 2018 23:33:05 +0100 Subject: [PATCH] Cygwin: accept4: Fix resource leak The new implementation neglected to release the file descriptor in case of error. Signed-off-by: Corinna Vinschen --- winsup/cygwin/fhandler_socket_inet.cc | 2 ++ winsup/cygwin/fhandler_socket_local.cc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/winsup/cygwin/fhandler_socket_inet.cc b/winsup/cygwin/fhandler_socket_inet.cc index a3aeccc82..e65acffdf 100644 --- a/winsup/cygwin/fhandler_socket_inet.cc +++ b/winsup/cygwin/fhandler_socket_inet.cc @@ -895,6 +895,8 @@ fhandler_socket_inet::accept4 (struct sockaddr *peer, int *len, int flags) *len = llen; } } + else + fd.release (); } if (ret == -1) ::closesocket (res); diff --git a/winsup/cygwin/fhandler_socket_local.cc b/winsup/cygwin/fhandler_socket_local.cc index 844cb9d11..11f2c209e 100644 --- a/winsup/cygwin/fhandler_socket_local.cc +++ b/winsup/cygwin/fhandler_socket_local.cc @@ -1012,6 +1012,8 @@ fhandler_socket_local::accept4 (struct sockaddr *peer, int *len, int flags) *len = (int) sizeof (un.sun_family); } } + else + fd.release (); } if (ret == -1) ::closesocket (res);