From: Julien Desfossez Date: Fri, 9 Jun 2017 19:22:22 +0000 (-0400) Subject: Fix copytrace: check field exists before copy X-Git-Tag: v2.0.0-pre1~9 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=961ec227164cc938a42299071faf63094b2f5ac3 Fix copytrace: check field exists before copy Signed-off-by: Julien Desfossez Signed-off-by: Jérémie Galarneau --- 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;