lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] UDP send memory leaking: Not sure why


From: Luciano Moretti
Subject: [lwip-users] UDP send memory leaking: Not sure why
Date: Fri, 22 Oct 2021 14:56:39 -0500

Hi:
I've got a pretty simple UDP send (code below) that appears to be leaking memory: It fails after about 45 minutes of sending packets every 10ms.
I added some logging to my code and I see that I allocate a pbuff with the pbuf_alloc() call of size 1, but my call to pbuf_free() returns 0. Why is it not deallocating my pbuf and how can I ensure that the memory ends up properly deallocated?

Thanks,
Luciano


sendUDP(ip4_addr_t DestinationIP, uint16_t port, uint8_t *data, uint16_t length)
{
  err_t err;
  pbuf *p;

  udp_pcb *upcb = udp_new();
  err = udp_connect( upcb, &DestinationIP, port );
  p = pbuf_alloc( PBUF_TRANSPORT, length, PBUF_RAM );
  if(nullptr == p)
  {
    // Memory alloc failed
    dprintf("Error: sendUDP out of Memory\r\n");
    return ERR_MEM;
  }
  dprintf("Allocated pbuff with length %d\r\n", pbuf_clen(p));
  memcpy(p->payload, data, length);
  err = udp_send( upcb, p );
  udp_disconnect( upcb );
  uint8_t deallocated = pbuf_free(p);
  dprintf("Deallocated pbuff with length %d\r\n", deallocated);
  udp_remove(upcb);
  return (ERR_OK == err);
}


reply via email to

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