summaryrefslogtreecommitdiff
path: root/extmod/modlwip.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2021-08-12 15:57:17 +1000
committerDamien George <damien@micropython.org>2021-08-13 23:46:11 +1000
commit8fcdb5490c482dc11f3be70f8ab0cf844b600fb9 (patch)
treecfbf5e374c8d7b47b2e6ecdda103840c40e70e61 /extmod/modlwip.c
parent90d47ee34de707c4a138f3bfe2d434b13e1e6db8 (diff)
extmod/modlwip: Fix close and clean up of UDP and raw sockets.
The correct callback-deregister functions must be called dependent on the socket type, otherwise resources may not be freed correctly. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'extmod/modlwip.c')
-rw-r--r--extmod/modlwip.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/extmod/modlwip.c b/extmod/modlwip.c
index 00fd10964..8811742d6 100644
--- a/extmod/modlwip.c
+++ b/extmod/modlwip.c
@@ -1502,16 +1502,16 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
return 0;
}
- // Deregister callback (pcb.tcp is set to NULL below so must deregister now)
- tcp_arg(socket->pcb.tcp, NULL);
- 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: {
+ // Deregister callback (pcb.tcp is set to NULL below so must deregister now)
+ tcp_arg(socket->pcb.tcp, NULL);
+ tcp_err(socket->pcb.tcp, NULL);
+ tcp_recv(socket->pcb.tcp, NULL);
+
if (socket->pcb.tcp->state != LISTEN) {
// Schedule a callback to abort the connection if it's not cleanly closed after
// the given timeout. The callback must be set before calling tcp_close since
@@ -1525,10 +1525,12 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
break;
}
case MOD_NETWORK_SOCK_DGRAM:
+ udp_recv(socket->pcb.udp, NULL, NULL);
udp_remove(socket->pcb.udp);
break;
#if MICROPY_PY_LWIP_SOCK_RAW
case MOD_NETWORK_SOCK_RAW:
+ raw_recv(socket->pcb.raw, NULL, NULL);
raw_remove(socket->pcb.raw);
break;
#endif