Skip to content

Commit

Permalink
Fix hard-fault when socket created using accept() is closed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sentinelt committed Oct 6, 2018
1 parent 3df898d commit 9b89ad2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,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);
Expand Down
4 changes: 4 additions & 0 deletions features/netsocket/InternetSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9b89ad2

Please sign in to comment.