vfs/lwip: prevent pbuf leakage on ENOTCONN

Issue #3766
This commit is contained in:
Christian Helmuth 2020-07-30 09:19:35 +02:00 committed by Norman Feske
parent 7996fc45f3
commit 5a2ac73b69

View File

@ -1305,6 +1305,12 @@ class Lwip::Tcp_socket_dir final :
case Lwip_file_handle::DATA:
{
if (_recv_pbuf == nullptr) {
if (!_pcb || _pcb->state == CLOSE_WAIT) {
shutdown();
out_count = 0;
return Read_result::READ_OK;
}
/*
* queue the read if the PCB is active and
* there is nothing to read, otherwise return
@ -1645,11 +1651,14 @@ err_t tcp_delayed_recv_callback(void *arg, struct tcp_pcb *pcb, struct pbuf *buf
Lwip::Tcp_socket_dir::Pcb_pending *pending =
static_cast<Lwip::Tcp_socket_dir::Pcb_pending *>(arg);
if (pending->buf && buf) {
/* XXX buf == nullptr means ENOTCONN */
if (buf) {
if (pending->buf) {
pbuf_cat(pending->buf, buf);
} else {
pending->buf = buf;
}
}
return ERR_OK;
};