espressif / esp-modbus

ESP-Modbus - the officially suppported library for Modbus protocol (serial RS485 + TCP over WiFi or Ethernet).
Apache License 2.0
85 stars 46 forks source link

Memory leak in Modbus master initialization/teardown (IDFGH-9110) #14

Closed nicksenva closed 1 year ago

nicksenva commented 1 year ago

Calling mbc_master_init() creates a binary semaphore for the receive buffer in xMBMasterPortRxSemaInit(), which makes a dynamic memory allocation. mbc_master_destroy() does not destroy this semaphore, resulting in a memory leak each time the Modbus master is re-initialized. This could be resolved by calling vSemaphoreDelete() in the destroy function, or by creating a statically allocated semaphore.

alisitsyn commented 1 year ago

@nicksenva ,

Thank you for this issue. The originally it supposed to be static semaphore. The code is updated as in the patch below and will be merged ASAP. 0001-fix-rx-sema-destroy.patch

nicksenva commented 1 year ago

Thank you for your quick response. For now we have applied a patch by moving our esp-modbus component out of our project's managed components folder. Is there any estimate when the next official release will include this patch?

alisitsyn commented 1 year ago

I can not give you the concrete date of merge. However it will be merged as soon as other pending MRs are tested. I will try to do it ASAP. I will inform you once it is ready for merge.

alisitsyn commented 1 year ago

The fix has been merged in commit 3f6537fc940c932884db43c9d62608e982461a70. The issue will be closed. Feel free to reopen.