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.
pull/8336/head
Sławek Piotrowski 2018-10-06 09:29:30 +02:00
parent 3df898daae
commit 9b89ad2fa9
2 changed files with 5 additions and 0 deletions

View File

@ -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);

View File

@ -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;