khoih-prog/MySQL_MariaDB_Generic

memory leak on 'server_version'

pabloandresm opened this issue · 1 comments

If you use .connect() with the correct database server, but wrong user credentials, the .connect() does "server_version=malloc()" when it calls parse_handshake_packet(), but as the user is wrong, it exits, without calling the "free(server_version)".

This free(server_version) is only called at the end of the .connect().

So the bug is when the .connect() exists after parse_handshake_packet(), missing the correspondent free(server_version) at all possible exits.

A workaround for this is:
MySQL_Connection->server_version=NULL;
bool res = MySQL_Connection->connect(...);
if (res==false)
if (MySQL_Connection->server_version)
free(MySQL_Connection->server_version);

To reproduce is easy. Perform a .connect() in a loop, pointing to a correct mariadb, but with unknown user/password.
In that loop show ESP.getFreeHeap(), and you will see the memory leak.

Hi @pabloandresm

The new MySQL_MariaDB_Generic releases v1.6.0 has just been published. Your contribution is noted in Contributions and Thanks

Please have some more tests to verify the bugs have been squashed and if there is any more bug.

With the contributions from users like you, the library is better and better everyday.

Best Regards,


Release v1.6.0

  1. Fix memory leak bugs. Check memory leak on 'server_version' #17 and memory leak on MySQL_Connection.MySQL_Packet.buffer #18
  2. Optimize library code by using reference-passing instead of value-passing
  3. Update RP2040 Ethernet-related examples to use the same SS/CS pin GP17 for ArduinoCore-mbed mbed_rp2040 core as arduino-pico rp2040 core
  4. Update Packages' Patches