Reuse previously allocated string when setting value
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 29 Jul 2014 20:57:21 +0000 (16:57 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 29 Jul 2014 21:26:32 +0000 (17:26 -0400)
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 <jeremie.galarneau@efficios.com>
formats/ctf/ir/event-fields.c

index 17c597ac183d5d70e1a6682797ac1a1414f6e656..ed2cf489fc4e82b535c27885793afe8ecb30ee57 100644 (file)
@@ -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;
This page took 0.025387 seconds and 4 git commands to generate.