Skip to content

Commit 2d55027

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 2d55027

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

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)