netsock_shutdown(): prevent socket use after TX and RX shutdown
If close() is called on a TCP socket after having called shutdown()
with SHUT_RDWR argument, the underlying lwIP structure should not
be touched in the close() function, because it has been deallocated
(or is about to be deallocated) due to the call to tcp_shutdown().
@@ -706,6 +706,11 @@ static sysreturn netsock_shutdown(struct sock *sock, int how)
return -ENOTCONN;
}
tcp_shutdown(s->info.tcp.lw, shut_rx, shut_tx);
+ if (shut_rx && shut_tx) {
+ /* Shutting down both TX and RX is equivalent to calling
+ * tcp_close(), so the pcb should not be referenced anymore. */
+ s->info.tcp.lw = 0;
+ }
break;
case SOCK_DGRAM:
return -ENOTCONN;
