From 812fc520cd9efcb845a0d0f50b430b61e460f85d Mon Sep 17 00:00:00 2001 From: dongheng Date: Thu, 23 May 2019 17:05:03 +0800 Subject: [PATCH] lwip: fix reenter lwip_close --- .../lwip/apps/multi-threads/sockets_mt.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/components/lwip/apps/multi-threads/sockets_mt.c b/components/lwip/apps/multi-threads/sockets_mt.c index b6561912..e339251a 100644 --- a/components/lwip/apps/multi-threads/sockets_mt.c +++ b/components/lwip/apps/multi-threads/sockets_mt.c @@ -661,6 +661,9 @@ int lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optl { int ret; + if (tryget_socket(s) == NULL) + return -1; + if (optname == SO_ERROR) { int retval = 0; @@ -772,6 +775,19 @@ int lwip_shutdown(int s, int how) int lwip_close(int s) { int ret; + SYS_ARCH_DECL_PROTECT(lev); + + if (tryget_socket(s) == NULL) + return -1; + + SYS_ARCH_PROTECT(lev); + if (_sock_is_opened(s)) { + _sock_set_open(s, 0); + SYS_ARCH_UNPROTECT(lev); + } else { + SYS_ARCH_UNPROTECT(lev); + return -1; + } #if ESP_UDP struct lwip_sock *sock = get_socket(s); @@ -779,8 +795,6 @@ int lwip_close(int s) udp_sync_close_netconn(sock->conn); #endif - _sock_set_open(s, 0); - lwip_sync_mt(s, SHUT_RDWR); ret = lwip_close_esp(s);