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);
}