s-pms / melsec_mc_net

Melsec PLC MC-Binary protocol
http://wqliceman.top/melsec_mc_net/
MIT License
42 stars 21 forks source link

Memory leaking in melsec_mc_bin.c #1

Closed reyanvaldes closed 3 months ago

reyanvaldes commented 3 months ago

Thanks for excellent work and sharing with community. Please it sounds there is a little memory leaking in some functions of melsec_mc_bin.c, for example: read_bool_value, read_address_data, write_bool_value, write_address_data in case would like to correct in source code:

Here are some section of code: /////////////////////////////////////////////////////////////// if (!mc_analysis_address(address, length, &address_data)) { RELEASE_DATA(in_bytes.data); // Added on 6/14/2024 to avoid memory leak return MC_ERROR_CODE_PARSE_ADDRESS_FAILED; } /////////////////////////////////////////////////////////////// if (!mc_try_send_msg(fd, &cmd)) { RELEASE_DATA(cmd.data); // Added on 6/14/2024 to avoid memory Leak return MC_ERROR_CODE_SOCKET_SEND_FAILED; } /////////////////////////////////////////////////////////////// if (!mc_try_send_msg(fd, &cmd)) { RELEASE_DATA(cmd.data); // Added on 6/14/2024 to avoid memory Leak return MC_ERROR_CODE_SOCKET_SEND_FAILED; }

RELEASE_DATA(cmd.data); // Added on 6/14/2024 to avoid memory Leak

///////////////////////////////////////////////////////////////

Thanks

wqliceman commented 3 months ago

Thank you for reporting the memory leak bug. This issue has been fixed in the latest version.