stm32duino / STM32Ethernet

Arduino library to support Ethernet for STM32 based board
151 stars 42 forks source link

EthernetClient memory consumption #75

Closed jeremyB01 closed 9 months ago

jeremyB01 commented 9 months ago

In the EthernetClient::connect(IPAddress ip, uint16_t port) function there is memory allocated for the _tcp_client variable. In the EthernetClient::stop() the allocated memory is not freed up. Am I missing some part where allocated memory is freed up after usage or does this have an other specific reason? I stumbled over that issue by trying to keep me footprint as small as possible and only generating a EthernetClient object if needed and closing it afterwards.

fpistm commented 9 months ago

Hi @jeremyB01 You probably right.

void EthernetClient::stop()
{
  if (_tcp_client == NULL) {
    return;
  }

  // close tcp connection if not closed yet
  if (status() != TCP_CLOSING) {
    tcp_connection_close(_tcp_client->pcb, _tcp_client);
  }
+ mem_free(_tcp_client);
}

Could you submit a PR and test? Thanks in advance.

jeremyB01 commented 9 months ago

Created PR. The bug seems to be resolved. Thanks a lot.