diff --git a/server/core/httpresponse.cc b/server/core/httpresponse.cc index 89a28b28b..414a6710e 100644 --- a/server/core/httpresponse.cc +++ b/server/core/httpresponse.cc @@ -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; } diff --git a/server/core/server.cc b/server/core/server.cc index 479382671..74341ff9a 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -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); diff --git a/server/core/session.cc b/server/core/session.cc index f30d02be3..b05e02ece 100644 --- a/server/core/session.cc +++ b/server/core/session.cc @@ -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); diff --git a/server/core/users.cc b/server/core/users.cc index 6a119c63d..a5e5db868 100644 --- a/server/core/users.cc +++ b/server/core/users.cc @@ -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); diff --git a/server/modules/authenticator/MySQLAuth/mysql_auth.c b/server/modules/authenticator/MySQLAuth/mysql_auth.c index c3ef0f964..2a79d3b50 100644 --- a/server/modules/authenticator/MySQLAuth/mysql_auth.c +++ b/server/modules/authenticator/MySQLAuth/mysql_auth.c @@ -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; } diff --git a/server/modules/filter/ccrfilter/ccrfilter.c b/server/modules/filter/ccrfilter/ccrfilter.c index 6ea2e7853..51f3b2b58 100644 --- a/server/modules/filter/ccrfilter/ccrfilter.c +++ b/server/modules/filter/ccrfilter/ccrfilter.c @@ -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; } diff --git a/server/modules/filter/dbfwfilter/dbfwfilter.c b/server/modules/filter/dbfwfilter/dbfwfilter.c index 6fd542d1c..22bb392e0 100644 --- a/server/modules/filter/dbfwfilter/dbfwfilter.c +++ b/server/modules/filter/dbfwfilter/dbfwfilter.c @@ -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; diff --git a/server/modules/filter/namedserverfilter/namedserverfilter.cc b/server/modules/filter/namedserverfilter/namedserverfilter.cc index a5a6891e2..4b16ec99a 100644 --- a/server/modules/filter/namedserverfilter/namedserverfilter.cc +++ b/server/modules/filter/namedserverfilter/namedserverfilter.cc @@ -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())); diff --git a/server/modules/filter/topfilter/topfilter.c b/server/modules/filter/topfilter/topfilter.c index 1876f1537..56b0ea5a4 100644 --- a/server/modules/filter/topfilter/topfilter.c +++ b/server/modules/filter/topfilter/topfilter.c @@ -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); } } diff --git a/server/modules/monitor/mysqlmon/mysql_mon.c b/server/modules/monitor/mysqlmon/mysql_mon.c index 56e50c2a7..c961bc5b1 100644 --- a/server/modules/monitor/mysqlmon/mysql_mon.c +++ b/server/modules/monitor/mysqlmon/mysql_mon.c @@ -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); diff --git a/server/modules/routing/avrorouter/avro.c b/server/modules/routing/avrorouter/avro.c index 9a401bbe1..2807eb90d 100644 --- a/server/modules/routing/avrorouter/avro.c +++ b/server/modules/routing/avrorouter/avro.c @@ -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); diff --git a/server/modules/routing/binlogrouter/blr.c b/server/modules/routing/binlogrouter/blr.c index b83fae692..c83268c7a 100644 --- a/server/modules/routing/binlogrouter/blr.c +++ b/server/modules/routing/binlogrouter/blr.c @@ -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); diff --git a/server/modules/routing/hintrouter/hintrouter.cc b/server/modules/routing/hintrouter/hintrouter.cc index c699e162e..5e932de76 100644 --- a/server/modules/routing/hintrouter/hintrouter.cc +++ b/server/modules/routing/hintrouter/hintrouter.cc @@ -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)); } }