Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions ixwebsocket/IXSocketAppleSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,12 @@ namespace ix
{
std::lock_guard<std::mutex> lock(_mutex);

if (_sslContext == nullptr) return;

SSLClose(_sslContext);
CFRelease(_sslContext);
_sslContext = nullptr;
if (_sslContext != nullptr)
{
SSLClose(_sslContext);
CFRelease(_sslContext);
_sslContext = nullptr;
}

Socket::close();
}
Expand Down
18 changes: 18 additions & 0 deletions test/IXSocketAppleSSLReadTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
* Copyright (c) 2026 Machine Zone, Inc. All rights reserved.
*/
#include <catch_amalgamated.hpp>
#include <cerrno>
#include <fcntl.h>
#include <ixwebsocket/IXSocketAppleSSL.h>
#include <sys/socket.h>

namespace ix
{
Expand Down Expand Up @@ -48,6 +51,21 @@ namespace ix
};
} // namespace ix

TEST_CASE("SecureTransport closes the native socket without a TLS context", "[socket_apple][close]")
{
const bool contextCreated = GENERATE(false, true);
const int fd = ::socket(AF_INET, SOCK_STREAM, 0);
REQUIRE(fd != -1);
ix::SocketAppleSSL socket(ix::SocketTLSOptions {}, fd);
if (contextCreated) ix::SocketAppleSSLReadTestAccess::install(socket);

socket.close();
errno = 0;
CHECK(fcntl(fd, F_GETFD) == -1);
CHECK(errno == EBADF);
socket.close();
}

TEST_CASE("SecureTransport terminal errors clear a previous wait status", "[socket_apple][read]")
{
const bool reading = GENERATE(false, true);
Expand Down
Loading