@@ -64,7 +64,8 @@ socketConnection s = do
6464 connSendMany = Sock.sendMany s
6565 , connSendAll = sendall
6666 , connSendFile = sendFile s writeBuf bufferSize sendall
67− , connClose = close s >> freeBuffer writeBuf
67+ , connClose = close s
68+ , connFree = freeBuffer writeBuf
6869 , connRecv = receive s bufferPool
6970 , connRecvBuf = receiveBuf s
7071 , connWriteBuffer = writeBuf
@@ -277,7 +278,8 @@ fork set mkConn addr app counter ii0 = settingsFork set $ \ unmask ->
277278 -- We grab the connection before registering timeouts since the
278279 -- timeouts will be useless during connection creation, due to the
279280 -- fact that async exceptions are still masked.
280− bracket mkConn (closeConn ref . fst) $ \(conn, transport) ->
281+ bracket mkConn (\(conn, _) -> closeConn ref conn `finally` connFree conn)
282+ $ \(conn, transport) ->
281283
282284 -- We need to register a timeout handler for this thread, and
283285 -- cancel that handler as soon as we exit. We additionally close