Skip to content

Commit 25b6814

Browse files
Merge pull request #592 from arybczak/async-exception-safe-free
Make call to c_free async exception safe
2 parents 74ae9b7 + ed5d588 commit 25b6814

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Network/Socket/Syscall.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import System.IO.Error (catchIOError)
1111
#endif
1212

1313
#if defined(mingw32_HOST_OS)
14+
import Control.Exception (bracket)
1415
import Foreign (FunPtr)
1516
import GHC.Conc (asyncDoProc)
1617
#else
@@ -202,13 +203,12 @@ accept listing_sock = withNewSocketAddress $ \new_sa sz ->
202203
throwSocketErrorIfMinus1Retry "Network.Socket.accept" $
203204
c_accept_safe fd sa ptr_len
204205
| otherwise = do
205-
paramData <- c_newAcceptParams fd (fromIntegral sz) sa
206-
rc <- asyncDoProc c_acceptDoProc paramData
207-
new_fd <- c_acceptNewSock paramData
208-
c_free paramData
209-
when (rc /= 0) $
210-
throwSocketErrorCode "Network.Socket.accept" (fromIntegral rc)
211-
return new_fd
206+
bracket (c_newAcceptParams fd (fromIntegral sz) sa) c_free $ \paramData -> do
207+
rc <- asyncDoProc c_acceptDoProc paramData
208+
new_fd <- c_acceptNewSock paramData
209+
when (rc /= 0) $
210+
throwSocketErrorCode "Network.Socket.accept" (fromIntegral rc)
211+
return new_fd
212212
#else
213213
callAccept fd sa sz = with (fromIntegral sz) $ \ ptr_len -> do
214214
# ifdef HAVE_ADVANCED_SOCKET_FLAGS

0 commit comments

Comments
 (0)