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 15:59:16 +0000 (11:59 -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 59946ea4a8810bde2edc67414d782f34fc4032cb..aed9eb4da68a1fe702c8b8546ad0b06f3f190f84 100644 (file)
@@ -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);
index a554aedbfd3c0412e10c46cb6d519d9effddae44..2d3714e684bccab1deba3b522de7b7de3333faa0 100644 (file)
@@ -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;
 }
 
index 6988e0012406417672351eea36a1804d2d04af20..17a5bcd4f791f508fd2b349635af904e2cf7f057 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.
@@ -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);
 }
This page took 0.028697 seconds and 4 git commands to generate.