Fix: replace assert with proper error handling
[babeltrace.git] / formats / lttng-live / lttng-live-functions.c
index 2d923618d2326fa707a32096aad1b80f26f2f744..1f4b4dbc6ff3941bf6d1df767655869ef83daa30 100644 (file)
@@ -230,11 +230,6 @@ int lttng_live_ctf_trace_assign(struct lttng_live_viewer_stream *stream,
                        (gpointer) ctf_trace_id);
        if (!trace) {
                trace = g_new0(struct lttng_live_ctf_trace, 1);
-               if (!trace) {
-                       ret = -1;
-                       fprintf(stderr, "[error] ctf_trace allocation\n");
-                       goto error;
-               }
                trace->ctf_trace_id = ctf_trace_id;
                trace->streams = g_ptr_array_new();
                g_hash_table_insert(stream->session->ctf_traces,
@@ -247,7 +242,6 @@ int lttng_live_ctf_trace_assign(struct lttng_live_viewer_stream *stream,
        stream->ctf_trace = trace;
        g_ptr_array_add(trace->streams, stream);
 
-error:
        return ret;
 }
 
@@ -343,11 +337,6 @@ int lttng_live_attach_session(struct lttng_live_ctx *ctx, uint64_t id)
                ctx->session->stream_count);
        ctx->session->streams = g_new0(struct lttng_live_viewer_stream,
                        ctx->session->stream_count);
-       if (!ctx->session->streams) {
-               ret = -1;
-               goto error;
-       }
-
        for (i = 0; i < be32toh(rp.streams_count); i++) {
                do {
                        ret_len = recv(ctx->control_sock, &stream, sizeof(stream), 0);
@@ -374,7 +363,17 @@ int lttng_live_attach_session(struct lttng_live_ctx *ctx, uint64_t id)
                        char *path;
 
                        path = strdup(LTTNG_METADATA_PATH_TEMPLATE);
-                       path = mkdtemp(path);
+                       if (!path) {
+                               perror("strdup");
+                               ret = -1;
+                               goto error;
+                       }
+                       if (!mkdtemp(path)) {
+                               perror("mkdtemp");
+                               free(path);
+                               ret = -1;
+                               goto error;
+                       }
                        ctx->session->streams[i].metadata_flag = 1;
                        snprintf(ctx->session->streams[i].path,
                                        sizeof(ctx->session->streams[i].path),
@@ -385,9 +384,11 @@ int lttng_live_attach_session(struct lttng_live_ctx *ctx, uint64_t id)
                                        S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
                        if (ret < 0) {
                                perror("open");
+                               free(path);
                                goto error;
                        }
                        ctx->session->streams[i].fd = ret;
+                       free(path);
                }
                ret = lttng_live_ctf_trace_assign(&ctx->session->streams[i],
                                be64toh(stream.ctf_trace_id));
@@ -453,7 +454,13 @@ int get_data_packet(struct lttng_live_ctx *ctx,
                ret = ret_len;
                goto error;
        }
-       assert(ret_len == sizeof(rp));
+       if (ret_len != sizeof(rp)) {
+               fprintf(stderr, "[error] get_data_packet: expected %" PRId64
+                               ", received %" PRId64 "\n", ret_len,
+                               sizeof(rp));
+               ret = -1;
+               goto error;
+       }
 
        rp.flags = be32toh(rp.flags);
 
This page took 0.024563 seconds and 4 git commands to generate.