Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

fix server_version memory management #21

Merged
merged 1 commit into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/MySQL_Generic_Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ class MySQL_Connection : public MySQL_Packet

virtual ~MySQL_Connection()
{
if (server_version)
{
MYSQL_LOGDEBUG("Free server_version");

free(server_version);
}
this->close();
};

bool connect(const IPAddress& server, const uint16_t& port, char *user, char *password, char *db = NULL);
Expand Down
10 changes: 8 additions & 2 deletions src/MySQL_Generic_Connection_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ bool MySQL_Connection::connect(const char *hostname, const uint16_t& port, char
}

if (server_version)
free(server_version); // don't need it anymore
{
free(server_version); // don't need it anymore
server_version = NULL;
}

return returnVal;
}
Expand Down Expand Up @@ -236,7 +239,10 @@ Connection_Result MySQL_Connection::connectNonBlocking(const char *hostname, con
}

if (server_version)
free(server_version); // don't need it anymore
{
free(server_version); // don't need it anymore
server_version = NULL;
}

return returnVal;
}
Expand Down
6 changes: 6 additions & 0 deletions src/MySQL_Generic_Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ class MySQL_Packet

free(buffer);
}
if (server_version)
{
MYSQL_LOGDEBUG("Free server_version");

free(server_version);
}
};

bool complete_handshake(char *user, char *password);
Expand Down
12 changes: 10 additions & 2 deletions src/MySQL_Generic_Packet_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
MySQL_Packet::MySQL_Packet(Client *client_instance)
{
buffer = NULL;
server_version = NULL;
client = client_instance;
}

Expand Down Expand Up @@ -441,8 +442,15 @@ void MySQL_Packet::parse_handshake_packet()
i++;
} while (buffer[i - 1] != 0x00);

server_version = (char *) malloc(i - 5);
strncpy(server_version, (char *) &buffer[5], i - 5);
if (i>5)
{
server_version = (char *) malloc(i - 5);
if (server_version)
{
strncpy(server_version, (char *) &buffer[5], i - 5);
server_version[i-5-1]=0;
}
}

// Capture the first 8 characters of seed
i += 4; // Skip thread id
Expand Down