From 961ec227164cc938a42299071faf63094b2f5ac3 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Fri, 9 Jun 2017 15:22:22 -0400 Subject: [PATCH] Fix copytrace: check field exists before copy MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Julien Desfossez Signed-off-by: Jérémie Galarneau --- plugins/libctfcopytrace/ctfcopytrace.c | 44 ++++++++++++++++---------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/plugins/libctfcopytrace/ctfcopytrace.c b/plugins/libctfcopytrace/ctfcopytrace.c index b8e28135..28aa5e5c 100644 --- a/plugins/libctfcopytrace/ctfcopytrace.c +++ b/plugins/libctfcopytrace/ctfcopytrace.c @@ -761,8 +761,13 @@ struct bt_ctf_event *ctf_copy_event(FILE *err, struct bt_ctf_event *event, /* Optional field, so it can fail silently. */ field = bt_ctf_event_get_stream_event_context(event); - copy_field = bt_ctf_field_copy(field); - if (copy_field) { + if (field) { + copy_field = bt_ctf_field_copy(field); + if (!copy_field) { + fprintf(err, "[error] %s in %s:%d\n", __func__, + __FILE__, __LINE__); + goto error; + } ret = bt_ctf_event_set_stream_event_context(writer_event, copy_field); if (ret < 0) { @@ -770,41 +775,46 @@ struct bt_ctf_event *ctf_copy_event(FILE *err, struct bt_ctf_event *event, __FILE__, __LINE__); goto error; } + BT_PUT(field); + BT_PUT(copy_field); } - BT_PUT(field); - BT_PUT(copy_field); /* Optional field, so it can fail silently. */ field = bt_ctf_event_get_event_context(event); - copy_field = bt_ctf_field_copy(field); - if (copy_field) { + if (field) { + copy_field = bt_ctf_field_copy(field); + if (!copy_field) { + fprintf(err, "[error] %s in %s:%d\n", __func__, + __FILE__, __LINE__); + goto error; + } ret = bt_ctf_event_set_event_context(writer_event, copy_field); if (ret < 0) { fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__); goto error; } + BT_PUT(field); + BT_PUT(copy_field); } - BT_PUT(field); - BT_PUT(copy_field); field = bt_ctf_event_get_event_payload(event); - if (!field) { - fprintf(err, "[error] %s in %s:%d\n", __func__, - __FILE__, __LINE__); - goto error; - } - copy_field = bt_ctf_field_copy(field); - if (copy_field) { + if (field) { + copy_field = bt_ctf_field_copy(field); + if (!copy_field) { + fprintf(err, "[error] %s in %s:%d\n", __func__, + __FILE__, __LINE__); + goto error; + } ret = bt_ctf_event_set_event_payload(writer_event, copy_field); if (ret < 0) { fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__); goto error; } + BT_PUT(field); + BT_PUT(copy_field); } - BT_PUT(field); - BT_PUT(copy_field); goto end; -- 2.34.1