MXS-2183: Fix memory leaks

Under heavy load some of the basic network operations could fail which led
to some of the allocated memory to leak.

Also the backend protocol never freed the current protocol command if it
was not completed. This would happen if a user executed a session command
as the first command but backend authentication would fail.
This commit is contained in:
Markus Mäkelä 2018-11-28 01:33:16 +02:00
parent 24d1876ed4
commit 6451b1f21a
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
2 changed files with 16 additions and 3 deletions

View File

@ -1021,8 +1021,6 @@ int open_network_socket(enum mxs_socket_type type, struct sockaddr_storage *addr
memcpy(addr, ai->ai_addr, ai->ai_addrlen);
set_port(addr, port);
freeaddrinfo(ai);
if ((type == MXS_SOCKET_NETWORK && !configure_network_socket(so, addr->ss_family)) ||
(type == MXS_SOCKET_LISTENER && !configure_listener_socket(so)))
{
@ -1042,12 +1040,15 @@ int open_network_socket(enum mxs_socket_type type, struct sockaddr_storage *addr
if (config->local_address)
{
freeaddrinfo(ai);
ai = NULL;
if ((rc = getaddrinfo(config->local_address, NULL, &hint, &ai)) == 0)
{
struct sockaddr_storage local_address = {};
memcpy(&local_address, ai->ai_addr, ai->ai_addrlen);
freeaddrinfo(ai);
if (bind(so, (struct sockaddr*)&local_address, sizeof(local_address)) == 0)
{
@ -1069,6 +1070,8 @@ int open_network_socket(enum mxs_socket_type type, struct sockaddr_storage *addr
}
}
}
freeaddrinfo(ai);
}
return so;

View File

@ -105,6 +105,16 @@ bool mysql_protocol_done(DCB* dcb)
gwbuf_free(p->stored_query);
server_command_t* s = &p->protocol_command;
while (s->scom_next)
{
server_command_t tmp = *(s->scom_next);
MXS_FREE(s->scom_next);
p->protocol_command = tmp;
s = &p->protocol_command;
}
p->protocol_state = MYSQL_PROTOCOL_DONE;
rval = true;
}