Skip to content

Commit 9b89ad2

Browse files
committed
Fix hard-fault when socket created using accept() is closed
When socket created using accept() is closed by calling the close() method, "delete this" is executed which triggers the destructor call on TCPSocket which in turn calls close() once again. Because _stack is already 0 this results in a hard-fault. Add a check that skips the rest of the close() method is the _stack is already 0.
1 parent 3df898d commit 9b89ad2

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

UNITTESTS/features/netsocket/InternetSocket/test_InternetSocket.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ TEST_F(TestInternetSocket, getsockopt)
204204
TEST_F(TestInternetSocket, sigio)
205205
{
206206
callback_is_called = false;
207+
socket->open((NetworkStack *)&stack);
207208
socket->sigio(mbed::callback(my_callback));
208209
socket->close(); // Trigger event;
209210
EXPECT_EQ(callback_is_called, true);

features/netsocket/InternetSocket.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ nsapi_error_t InternetSocket::close()
5656
_lock.lock();
5757

5858
nsapi_error_t ret = NSAPI_ERROR_OK;
59+
if (!_stack) {
60+
return ret;
61+
}
62+
5963
if (_socket) {
6064
_stack->socket_attach(_socket, 0, 0);
6165
nsapi_socket_t socket = _socket;

0 commit comments

Comments
 (0)