diff --git a/UNITTESTS/features/netsocket/InternetSocket/test_InternetSocket.cpp b/UNITTESTS/features/netsocket/InternetSocket/test_InternetSocket.cpp index 859f1eb964..bf3424869f 100644 --- a/UNITTESTS/features/netsocket/InternetSocket/test_InternetSocket.cpp +++ b/UNITTESTS/features/netsocket/InternetSocket/test_InternetSocket.cpp @@ -222,6 +222,7 @@ TEST_F(TestInternetSocket, getsockopt) TEST_F(TestInternetSocket, sigio) { callback_is_called = false; + socket->open((NetworkStack *)&stack); socket->sigio(mbed::callback(my_callback)); socket->close(); // Trigger event; EXPECT_EQ(callback_is_called, true); diff --git a/features/netsocket/InternetSocket.cpp b/features/netsocket/InternetSocket.cpp index 948e25374a..cc793450a2 100644 --- a/features/netsocket/InternetSocket.cpp +++ b/features/netsocket/InternetSocket.cpp @@ -56,6 +56,10 @@ nsapi_error_t InternetSocket::close() _lock.lock(); nsapi_error_t ret = NSAPI_ERROR_OK; + if (!_stack) { + return ret; + } + if (_socket) { _stack->socket_attach(_socket, 0, 0); nsapi_socket_t socket = _socket;