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>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user