From: Jérémie Galarneau Date: Tue, 29 Jul 2014 20:57:21 +0000 (-0400) Subject: Reuse previously allocated string when setting value X-Git-Tag: v2.0.0-pre1~1510 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=9773681407e4e8fce40f247132dc99fabe306bfe Reuse previously allocated string when setting value bt_ctf_field_string_set_value() frees and reallocates a new g_string object if the value is changed. This change ensures that the previous string is used if possible. Signed-off-by: Jérémie Galarneau --- diff --git a/formats/ctf/ir/event-fields.c b/formats/ctf/ir/event-fields.c index 17c597ac..ed2cf489 100644 --- a/formats/ctf/ir/event-fields.c +++ b/formats/ctf/ir/event-fields.c @@ -851,10 +851,11 @@ int bt_ctf_field_string_set_value(struct bt_ctf_field *field, string = container_of(field, struct bt_ctf_field_string, parent); if (string->payload) { - g_string_free(string->payload, TRUE); + g_string_assign(string->payload, value); + } else { + string->payload = g_string_new(value); } - string->payload = g_string_new(value); string->parent.payload_set = 1; end: return ret;