Fix copytrace: check field exists before copy
authorJulien Desfossez <jdesfossez@efficios.com>
Fri, 9 Jun 2017 19:22:22 +0000 (15:22 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 9 Jun 2017 22:18:04 +0000 (18:18 -0400)
Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
plugins/libctfcopytrace/ctfcopytrace.c

index b8e281355b05abc44d798b8c337586719f28127e..28aa5e5c6d07d8eb42711db15aed896183e18a98 100644 (file)
@@ -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;
 
This page took 0.02529 seconds and 4 git commands to generate.