From: Jérémie Galarneau Date: Thu, 16 Jul 2015 16:58:44 +0000 (-0400) Subject: Fix: Memory leak in relay_add_stream error path X-Git-Tag: v2.5.5~9 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=198d75caf085937dec0aca154e899ea574f9295d;p=lttng-tools.git Fix: Memory leak in relay_add_stream error path Failing to allocate a struct ctf_trace results in the leak of a stream's path and channel name. Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-relayd/ctf-trace.c b/src/bin/lttng-relayd/ctf-trace.c index 9e9a5c69e..ab1610929 100644 --- a/src/bin/lttng-relayd/ctf-trace.c +++ b/src/bin/lttng-relayd/ctf-trace.c @@ -38,6 +38,14 @@ static void rcu_destroy_ctf_trace(struct rcu_head *head) free(trace); } +static void rcu_destroy_stream(struct rcu_head *head) +{ + struct relay_stream *stream = + caa_container_of(head, struct relay_stream, rcu_node); + + stream_destroy(stream); +} + /* * Destroy a ctf trace and all stream contained in it. * @@ -57,7 +65,7 @@ void ctf_trace_destroy(struct ctf_trace *obj) cds_list_for_each_entry_safe(stream, tmp_stream, &obj->stream_list, trace_list) { stream_delete(relay_streams_ht, stream); - stream_destroy(stream); + call_rcu(&stream->rcu_node, rcu_destroy_stream); } call_rcu(&obj->node.head, rcu_destroy_ctf_trace); diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index 178e00234..8ab60d4cd 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -1285,7 +1285,7 @@ end: if (ret < 0) { reply.ret_code = htobe32(LTTNG_ERR_UNK); /* stream was not properly added to the ht, so free it */ - free(stream); + stream_destroy(stream); } else { reply.ret_code = htobe32(LTTNG_OK); } @@ -1302,9 +1302,7 @@ end_no_session: return ret; err_free_stream: - free(stream->path_name); - free(stream->channel_name); - free(stream); + stream_destroy(stream); return ret; } diff --git a/src/bin/lttng-relayd/stream.c b/src/bin/lttng-relayd/stream.c index 410fae861..f3945383a 100644 --- a/src/bin/lttng-relayd/stream.c +++ b/src/bin/lttng-relayd/stream.c @@ -23,16 +23,6 @@ #include "stream.h" #include "viewer-stream.h" -static void rcu_destroy_stream(struct rcu_head *head) -{ - struct relay_stream *stream = - caa_container_of(head, struct relay_stream, rcu_node); - - free(stream->path_name); - free(stream->channel_name); - free(stream); -} - /* * Get stream from stream id from the given hash table. Return stream if found * else NULL. @@ -149,6 +139,7 @@ void stream_delete(struct lttng_ht *ht, struct relay_stream *stream) void stream_destroy(struct relay_stream *stream) { assert(stream); - - call_rcu(&stream->rcu_node, rcu_destroy_stream); + free(stream->path_name); + free(stream->channel_name); + free(stream); }