Index: src/OFTLSSocket.h ================================================================== --- src/OFTLSSocket.h +++ src/OFTLSSocket.h @@ -64,10 +64,13 @@ @property (nonatomic) bool verifiesCertificates; /** * @brief Initializes the TLS socket with the specified TCP socket as its * underlying socket. + * + * The passed socket will become invalid, as the internal socket handle gets + * moved from the specified socket to the OFTLSSocket. * * @param socket The TCP socket to use as underlying socket */ - (instancetype)initWithSocket: (OFTCPSocket *)socket; Index: src/OFTLSSocket.m ================================================================== --- src/OFTLSSocket.m +++ src/OFTLSSocket.m @@ -129,12 +129,12 @@ @try { if ([socket isKindOfClass: [OFTLSSocket class]]) @throw [OFInvalidArgumentException exception]; - if ((_socket = dup(socket->_socket)) == OFInvalidSocketHandle) - @throw [OFInitializationFailedException exception]; + _socket = socket->_socket; + socket->_socket = OFInvalidSocketHandle; _verifiesCertificates = true; } @catch (id e) { [self release]; @throw e;