Fix avrorouter memory leaks

The loading of the JSON schemas leaked memory as functions that increment
the reference count were used.
This commit is contained in:
Markus Mäkelä
2017-06-02 10:55:45 +03:00
parent d5a72d1b75
commit 4c78e2c99a
3 changed files with 20 additions and 17 deletions

View File

@ -414,6 +414,7 @@ createInstance(SERVICE *service, char **options)
inst->gtid.seq = 0; inst->gtid.seq = 0;
inst->gtid.server_id = 0; inst->gtid.server_id = 0;
inst->gtid.timestamp = 0; inst->gtid.timestamp = 0;
memset(&inst->active_maps, 0, sizeof(inst->active_maps));
bool err = false; bool err = false;
if (param) if (param)

View File

@ -140,6 +140,7 @@ void avro_index_file(AVRO_INSTANCE *router, const char* filename)
errmsg = NULL; errmsg = NULL;
prev_gtid = gtid; prev_gtid = gtid;
} }
json_decref(row);
} }
else else
{ {

View File

@ -102,16 +102,16 @@ char* json_new_schema_from_table(TABLE_MAP *map)
json_object_set_new(schema, "name", json_string("ChangeRecord")); json_object_set_new(schema, "name", json_string("ChangeRecord"));
json_t *array = json_array(); json_t *array = json_array();
json_array_append(array, json_pack_ex(&err, 0, "{s:s, s:s}", "name", json_array_append_new(array, json_pack_ex(&err, 0, "{s:s, s:s}", "name",
avro_domain, "type", "int")); avro_domain, "type", "int"));
json_array_append(array, json_pack_ex(&err, 0, "{s:s, s:s}", "name", json_array_append_new(array, json_pack_ex(&err, 0, "{s:s, s:s}", "name",
avro_server_id, "type", "int")); avro_server_id, "type", "int"));
json_array_append(array, json_pack_ex(&err, 0, "{s:s, s:s}", "name", json_array_append_new(array, json_pack_ex(&err, 0, "{s:s, s:s}", "name",
avro_sequence, "type", "int")); avro_sequence, "type", "int"));
json_array_append(array, json_pack_ex(&err, 0, "{s:s, s:s}", "name", json_array_append_new(array, json_pack_ex(&err, 0, "{s:s, s:s}", "name",
avro_event_number, "type", "int")); avro_event_number, "type", "int"));
json_array_append(array, json_pack_ex(&err, 0, "{s:s, s:s}", "name", json_array_append_new(array, json_pack_ex(&err, 0, "{s:s, s:s}", "name",
avro_timestamp, "type", "int")); avro_timestamp, "type", "int"));
/** Enums and other complex types are defined with complete JSON objects /** Enums and other complex types are defined with complete JSON objects
* instead of string values */ * instead of string values */
@ -119,18 +119,19 @@ char* json_new_schema_from_table(TABLE_MAP *map)
"name", "EVENT_TYPES", "symbols", "insert", "name", "EVENT_TYPES", "symbols", "insert",
"update_before", "update_after", "delete"); "update_before", "update_after", "delete");
json_array_append(array, json_pack_ex(&err, 0, "{s:s, s:o}", "name", avro_event_type, // Ownership of `event_types` is stolen when using the `o` format
"type", event_types)); json_array_append_new(array, json_pack_ex(&err, 0, "{s:s, s:o}", "name", avro_event_type,
"type", event_types));
for (uint64_t i = 0; i < map->columns; i++) for (uint64_t i = 0; i < map->columns; i++)
{ {
ss_info_dassert(create->column_names[i] && *create->column_names[i], ss_info_dassert(create->column_names[i] && *create->column_names[i],
"Column name should not be empty or NULL"); "Column name should not be empty or NULL");
json_array_append(array, json_pack_ex(&err, 0, "{s:s, s:s, s:s, s:i}", json_array_append_new(array, json_pack_ex(&err, 0, "{s:s, s:s, s:s, s:i}",
"name", create->column_names[i], "name", create->column_names[i],
"type", column_type_to_avro_type(map->column_types[i]), "type", column_type_to_avro_type(map->column_types[i]),
"real_type", create->column_types[i], "real_type", create->column_types[i],
"length", create->column_lengths[i])); "length", create->column_lengths[i]));
} }
json_object_set_new(schema, "fields", array); json_object_set_new(schema, "fields", array);
char* rval = json_dumps(schema, JSON_PRESERVE_ORDER); char* rval = json_dumps(schema, JSON_PRESERVE_ORDER);