Skip to content

Commit 67d845b

Browse files
committed
add nullpointer check in LWIP::socket_close
1 parent f9c0cd2 commit 67d845b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

connectivity/lwipstack/source/LWIPStack.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,9 @@ nsapi_error_t LWIP::socket_close(nsapi_socket_t handle)
287287
/* Check if TCP FSM is in ESTABLISHED state.
288288
* Then give extra time for connection close handshaking until TIME_WAIT state.
289289
* The purpose is to prevent eth/wifi driver stop and FIN ACK corrupt.
290-
* This may happend if network interface disconnect follows immediately after socket_close.*/
291-
if (NETCONNTYPE_GROUP(s->conn->type) == NETCONN_TCP && s->conn->pcb.tcp->state == ESTABLISHED) {
290+
* This may happend if network interface disconnect follows immediately after socket_close.
291+
* In case of a TCP RESET flag, the pcb structure is already deleted, therefore check for nullpointer.*/
292+
if (NETCONNTYPE_GROUP(s->conn->type) == NETCONN_TCP && (nullptr == s->conn->pcb.tcp || s->conn->pcb.tcp->state == ESTABLISHED)) {
292293
_event_flag.clear(TCP_CLOSED_FLAG);
293294
netconn_shutdown(s->conn, false, true);
294295
_event_flag.wait_any(TCP_CLOSED_FLAG, TCP_CLOSE_TIMEOUT);

0 commit comments

Comments
 (0)