diff options
author | Damien George <damien.p.george@gmail.com> | 2019-03-12 22:35:52 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2019-03-12 22:35:52 +1100 |
commit | 68a5d6fe7746850ce049b8bf295bfce1382383f3 (patch) | |
tree | 9973ab12d07c295c98230cb77cba1e6c41793e56 | |
parent | 493ee7df1875f3b15eac1a725e933fa7a386bd71 (diff) |
extmod/modlwip: Fix case where concurrency lock isn't released on error.
-rw-r--r-- | extmod/modlwip.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 1b8caa894..c7e050129 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -536,6 +536,15 @@ STATIC mp_uint_t lwip_udp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_ } \ assert(socket->pcb.tcp); +// Version of above for use when lock is held +#define STREAM_ERROR_CHECK_WITH_LOCK(socket) \ + if (socket->state < 0) { \ + *_errno = error_lookup_table[-socket->state]; \ + MICROPY_PY_LWIP_EXIT \ + return MP_STREAM_ERROR; \ + } \ + assert(socket->pcb.tcp); + // Helper function for send/sendto to handle TCP packets STATIC mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno) { @@ -572,7 +581,7 @@ STATIC mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_ui } // While we waited, something could happen - STREAM_ERROR_CHECK(socket); + STREAM_ERROR_CHECK_WITH_LOCK(socket); } u16_t write_len = MIN(available, len); |