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.8.0-rc1~553 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=5eb3e5b8f4fcb95f27f43cd2e7ea436937037d0e 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 59946ea4a..aed9eb4da 100644 --- a/src/bin/lttng-relayd/ctf-trace.c +++ b/src/bin/lttng-relayd/ctf-trace.c @@ -39,6 +39,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. * @@ -58,7 +66,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 a554aedbf..2d3714e68 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -1352,7 +1352,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); } @@ -1369,9 +1369,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 6988e0012..17a5bcd4f 100644 --- a/src/bin/lttng-relayd/stream.c +++ b/src/bin/lttng-relayd/stream.c @@ -24,16 +24,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. @@ -150,6 +140,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); }