summaryrefslogtreecommitdiffstats
path: root/libfreerdp/core/transport.c
diff options
context:
space:
mode:
Diffstat (limited to 'libfreerdp/core/transport.c')
-rw-r--r--libfreerdp/core/transport.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c
index e4cc570..a2a899b 100644
--- a/libfreerdp/core/transport.c
+++ b/libfreerdp/core/transport.c
@@ -197,8 +197,6 @@ static BOOL transport_default_attach(rdpTransport* transport, int sockfd)
if (!socketBio)
goto fail;
-
- BIO_set_fd(socketBio, sockfd, BIO_CLOSE);
}
bufferedBio = BIO_new(BIO_s_buffered_socket());
@@ -206,8 +204,18 @@ static BOOL transport_default_attach(rdpTransport* transport, int sockfd)
goto fail;
if (socketBio)
+ {
bufferedBio = BIO_push(bufferedBio, socketBio);
- WINPR_ASSERT(bufferedBio);
+ if (!bufferedBio)
+ goto fail;
+
+ /* Attach the socket only when this function can no longer fail.
+ * This ensures solid ownership:
+ * - if this function fails, the caller is responsible to clean up
+ * - if this function is successful, the caller MUST NOT close the socket any more.
+ */
+ BIO_set_fd(socketBio, sockfd, BIO_CLOSE);
+ }
transport->frontBio = bufferedBio;
return TRUE;
fail: