Fix: Memory leak in relay_add_stream error path
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 16 Jul 2015 16:58:44 +0000 (12:58 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 3 Aug 2015 16:05:48 +0000 (12:05 -0400)
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 <jeremie.galarneau@efficios.com>
src/bin/lttng-relayd/ctf-trace.c
src/bin/lttng-relayd/main.c
src/bin/lttng-relayd/stream.c

index 9e9a5c69eb87a1f802fd0fc75bd5ea0f2a7a0151..ab1610929aa5da6e0424749ee9c28eb968356fc7 100644 (file)
@@ -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);
index cc684109cd9c3f5219d325f020606722f4d1a16b..ba92da87d2920028a47076c92f56a77d27ddff99 100644 (file)
@@ -1287,7 +1287,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);
        }
@@ -1304,9 +1304,7 @@ end_no_session:
        return ret;
 
 err_free_stream:
-       free(stream->path_name);
-       free(stream->channel_name);
-       free(stream);
+       stream_destroy(stream);
        return ret;
 }
 
index 410fae86146048bab2ea975f43b2fa434eb62623..f3945383a85d5c4f0d6f27303491a42437eb971c 100644 (file)
 #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);
 }
This page took 0.029134 seconds and 4 git commands to generate.