aboutsummaryrefslogtreecommitdiff
path: root/extmod/modlwip.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-05-29 01:24:43 +1000
committerDamien George <damien.p.george@gmail.com>2019-05-29 01:24:43 +1000
commit734ada3e2980d1bbf5c7a1ea5c624b34be16dfa9 (patch)
treeb9c9447e265610d6c8c52b45a993403782d79290 /extmod/modlwip.c
parent883e987b90e82f0a9ab223910890da2c5d50b9d3 (diff)
extmod/modlwip: Free any incoming bufs/connections before closing PCB.
Commit 2848a613ac61fce209962354c2698ee587a2c26a introduced a bug where lwip_socket_free_incoming() accessed pcb.tcp->state after the PCB was closed. The state may have changed due to that close call, or the PCB may be freed and therefore invalid. This commit fixes that by calling lwip_socket_free_incoming() before the PCB is closed.
Diffstat (limited to 'extmod/modlwip.c')
-rw-r--r--extmod/modlwip.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/extmod/modlwip.c b/extmod/modlwip.c
index e0bf17db8..06ed764b5 100644
--- a/extmod/modlwip.c
+++ b/extmod/modlwip.c
@@ -1416,6 +1416,9 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
tcp_err(socket->pcb.tcp, NULL);
tcp_recv(socket->pcb.tcp, NULL);
+ // Free any incoming buffers or connections that are stored
+ lwip_socket_free_incoming(socket);
+
switch (socket->type) {
case MOD_NETWORK_SOCK_STREAM: {
if (tcp_close(socket->pcb.tcp) != ERR_OK) {
@@ -1430,7 +1433,7 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
case MOD_NETWORK_SOCK_DGRAM: udp_remove(socket->pcb.udp); break;
//case MOD_NETWORK_SOCK_RAW: raw_remove(socket->pcb.raw); break;
}
- lwip_socket_free_incoming(socket);
+
socket->pcb.tcp = NULL;
socket->state = _ERR_BADF;
ret = 0;