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);