fixed memleak and potential call of mysql_num_rows with NULL

This commit is contained in:
Daniel 2016-03-17 16:43:12 +01:00 committed by Markus Makela
parent 73c974c286
commit 48456833da

View File

@ -1433,6 +1433,8 @@ static void set_master_heartbeat(MYSQL_MONITOR *handle, MONITOR_SERVERS *databas
time_t purge_time;
char heartbeat_insert_query[512] = "";
char heartbeat_purge_query[512] = "";
MYSQL_RES *result;
long returned_rows;
if (handle->master == NULL)
{
@ -1440,14 +1442,26 @@ static void set_master_heartbeat(MYSQL_MONITOR *handle, MONITOR_SERVERS *databas
return;
}
/* create the maxscale_schema database */
/* check if the maxscale_schema database and replication_heartbeat table exist */
if (mysql_query(database->con, "SELECT table_name FROM information_schema.tables WHERE table_schema = 'maxscale_schema' AND table_name = 'replication_heartbeat'")) {
MXS_ERROR( "[mysql_mon]: Error checking for replication_heartbeat in Master server"
": %s", mysql_error(database->con));
database->server->rlag = -1;
}
if (0 == mysql_num_rows(mysql_store_result(database->con)))
result = mysql_store_result(database->con);
if (result == NULL)
{
returned_rows = 0;
}
else
{
returned_rows = mysql_num_rows(result);
mysql_free_result(result);
}
if (0 == returned_rows)
{
/* create repl_heartbeat table in maxscale_schema database */
if (mysql_query(database->con, "CREATE TABLE IF NOT EXISTS "