MXS-1220: Fix memory leaks

Some of the JSON objects created in the diagnostic functions leaked
memory.
This commit is contained in:
Markus Mäkelä
2017-04-19 19:49:12 +03:00
committed by Markus Mäkelä
parent ebc9e4bd3b
commit bc3cfe0221
13 changed files with 20 additions and 18 deletions

View File

@ -39,8 +39,10 @@ HttpResponse::HttpResponse(const HttpResponse& response):
HttpResponse& HttpResponse::operator=(const HttpResponse& response)
{
json_t* body = m_body;
m_body = json_incref(response.m_body);
m_code = response.m_code;
json_decref(body);
return *this;
}

View File

@ -1427,7 +1427,7 @@ json_t* server_to_json(const SERVER* server, const char* host)
for (int i = 0; server->slaves[i]; i++)
{
json_array_append(slaves, json_integer(server->slaves[i]));
json_array_append_new(slaves, json_integer(server->slaves[i]));
}
json_object_set_new(rval, "slaves", slaves);

View File

@ -1017,7 +1017,7 @@ json_t* session_to_json(const MXS_SESSION *session, const char *host)
svc += "/services/";
svc += session->service->name;
json_array_append(arr, json_string(svc.c_str()));
json_array_append_new(arr, json_string(svc.c_str()));
json_object_set_new(rel, "services", arr);
json_object_set_new(rval, "relationships", rel);

View File

@ -123,7 +123,7 @@ json_t* users_default_diagnostic(SERV_LISTENER *port)
while ((user = (char*)hashtable_next(iter)))
{
json_array_append(rval, json_string(user));
json_array_append_new(rval, json_string(user));
}
hashtable_iterator_free(iter);

View File

@ -687,7 +687,7 @@ int diag_cb(void *data, int columns, char **row, char **field_names)
json_object_set_new(obj, "host", json_string(row[1]));
json_t* arr = (json_t*)data;
json_array_append(arr, obj);
json_array_append_new(arr, obj);
return 0;
}

View File

@ -363,22 +363,22 @@ static json_t* diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession)
CCR_INSTANCE *my_instance = (CCR_INSTANCE *)instance;
json_t* rval = json_object();
json_object_set(rval, "count", json_integer(my_instance->count));
json_object_set(rval, "time", json_integer(my_instance->time));
json_object_set_new(rval, "count", json_integer(my_instance->count));
json_object_set_new(rval, "time", json_integer(my_instance->time));
if (my_instance->match)
{
json_object_set(rval, "match", json_string(my_instance->match));
json_object_set_new(rval, "match", json_string(my_instance->match));
}
if (my_instance->nomatch)
{
json_object_set(rval, "nomatch", json_string(my_instance->nomatch));
json_object_set_new(rval, "nomatch", json_string(my_instance->nomatch));
}
json_object_set(rval, "data_modifications", json_integer(my_instance->stats.n_modified));
json_object_set(rval, "hints_added_count", json_integer(my_instance->stats.n_add_count));
json_object_set(rval, "hints_added_time", json_integer(my_instance->stats.n_add_time));
json_object_set_new(rval, "data_modifications", json_integer(my_instance->stats.n_modified));
json_object_set_new(rval, "hints_added_count", json_integer(my_instance->stats.n_add_count));
json_object_set_new(rval, "hints_added_time", json_integer(my_instance->stats.n_add_time));
return rval;
}

View File

@ -298,7 +298,7 @@ static json_t* rules_to_json(RULE *rules)
for (RULE *rule = rules; rule; rule = rule->next)
{
json_array_append(rval, rule_to_json(rule));
json_array_append_new(rval, rule_to_json(rule));
}
return rval;

View File

@ -347,7 +347,7 @@ json_t* RegexHintFilter::diagnostics()
for (StringArray::iterator it2 = it->m_targets.begin(); it2 != it->m_targets.end(); it2++)
{
json_array_append(targets, json_string(it2->c_str()));
json_array_append_new(targets, json_string(it2->c_str()));
}
json_object_set_new(obj, "match", json_string(it->m_match.c_str()));

View File

@ -621,7 +621,7 @@ static json_t* diagnostic(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession)
json_object_set_new(obj, "time", json_real(exec_time));
json_object_set_new(obj, "sql", json_string(my_session->top[i]->sql));
json_array_append(arr, obj);
json_array_append_new(arr, obj);
}
}

View File

@ -361,7 +361,7 @@ static json_t* diagnostics(const MXS_MONITOR *mon)
json_object_set_new(srv, "master_group", json_integer(serv_info->group));
}
json_array_append(arr, srv);
json_array_append_new(arr, srv);
}
json_object_set_new(rval, "server_info", arr);

View File

@ -860,7 +860,7 @@ static json_t* diagnostics(MXS_ROUTER *router)
snprintf(pathbuf, sizeof(pathbuf), "%lu-%lu-%lu", session->gtid.domain,
session->gtid.server_id, session->gtid.seq);
json_object_set_new(client, "current_gtid", json_string(pathbuf));
json_array_append(arr, client);
json_array_append_new(arr, client);
}
spinlock_release(&router_inst->lock);

View File

@ -1603,7 +1603,7 @@ static json_t* diagnostics(MXS_ROUTER *router)
json_object_set_new(slave, "mode", json_string(mode));
json_array_append(arr, slave);
json_array_append_new(arr, slave);
}
spinlock_release(&router_inst->lock);

View File

@ -155,7 +155,7 @@ json_t* HintRouter::diagnostics()
{
if (default_action_values[i].enum_value == (uint64_t)m_default_action)
{
json_array_append(arr, json_string(default_action_values[i].name));
json_array_append_new(arr, json_string(default_action_values[i].name));
}
}