lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-devel] Bug in altcp_tcp_accept


From: Klaus Breining
Subject: [lwip-devel] Bug in altcp_tcp_accept
Date: Sun, 13 Dec 2020 14:01:39 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1

Hello,

since some time, I try to find out, why at high request-frequencies on a low-performance CPU (TIVA TM4C129) after some time no altcp_pcbs are left and this even does not recover after waiting some time. I am using the mbed_tls implementation with a web-server similar to the one in the apps-directory (heavily modified for some reasons). The version I am using is the git-master around 2 months ago.

What I found out, is that the altcp_alloc() can fail on two different stages due to the fact, that a connection needs 1 tcp_pcb and 2 altcp_pcbs. Failure of the first allocation of the altcp_pcb is handled, the failure of the second one is not. This happens in altcp_tcp.c in function altcp_tcp_accept, causing a memory leak.

This is what I have added - now I works reliably:

static err_t
altcp_tcp_accept(void *arg, struct tcp_pcb *new_tpcb, err_t err)
{
  struct altcp_pcb *listen_conn = (struct altcp_pcb *)arg;
  if (listen_conn && listen_conn->accept) {
    //>>> KB20201030
    if (err != ERR_OK)          // Could be out of memory: new_tpcb is NULL in this case.
      return err;
    //<<<
    /* create a new altcp_conn to pass to the next 'accept' callback */
    struct altcp_pcb *new_conn = altcp_alloc();
    if (new_conn == NULL) {
      return ERR_MEM;
    }
    altcp_tcp_setup(new_conn, new_tpcb);
    return listen_conn->accept(listen_conn->arg, new_conn, err);
  }
  return ERR_ARG;
}


Regards

Klaus




reply via email to

[Prev in Thread] Current Thread [Next in Thread]