From 3af4fc482abd4a97ef3334536b8f8a43d46632fd Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Sat, 14 Dec 2013 10:38:31 -0500 Subject: [PATCH] Remove null checks on g_new0 g_new0 never returns NULL. We need to either always check for NULL, or never. Remove all NULL checks on pointers returned by g_new0. Coverity was complaining because we were dereferencing a pointer in an error path after checking it against NULL, which is certainly never OK. Found by coverity: ** CID 1136988: Dereference after null check (FORWARD_NULL) /formats/lttng-live/lttng-live.c: 152 in lttng_live_open_trace_read() Signed-off-by: Mathieu Desnoyers --- formats/lttng-live/lttng-live-functions.c | 11 ----------- formats/lttng-live/lttng-live.c | 6 +----- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/formats/lttng-live/lttng-live-functions.c b/formats/lttng-live/lttng-live-functions.c index b1bc2840..aee78cbf 100644 --- a/formats/lttng-live/lttng-live-functions.c +++ b/formats/lttng-live/lttng-live-functions.c @@ -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); diff --git a/formats/lttng-live/lttng-live.c b/formats/lttng-live/lttng-live.c index c44d02c7..831877ab 100644 --- a/formats/lttng-live/lttng-live.c +++ b/formats/lttng-live/lttng-live.c @@ -106,10 +106,7 @@ static int lttng_live_open_trace_read(const char *path) opt_payload_field_names = 1; ctx.session = g_new0(struct lttng_live_session, 1); - if (!ctx.session) { - ret = -1; - goto end; - } + /* We need a pointer to the context from the packet_seek function. */ ctx.session->ctx = &ctx; @@ -148,7 +145,6 @@ static int lttng_live_open_trace_read(const char *path) end_free: g_hash_table_destroy(ctx.session->ctf_traces); g_free(ctx.session); -end: g_free(ctx.session->streams); return ret; } -- 2.34.1