Add type-checked versions of allocation and deallocations functions
[lttng-tools.git] / src / bin / lttng-relayd / viewer-stream.cpp
index ca0be9a62d200136972ac6922a692a6bb5917526..2790903adb7962d706eeb8bb0e660b7229c17d26 100644 (file)
@@ -8,21 +8,38 @@
  */
 
 #define _LGPL_SOURCE
-#include <common/common.h>
-#include <common/index/index.h>
-#include <common/compat/string.h>
-#include <common/utils.h>
+#include <common/common.hpp>
+#include <common/index/index.hpp>
+#include <common/compat/string.hpp>
+#include <common/utils.hpp>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <algorithm>
 
-#include "lttng-relayd.h"
-#include "viewer-stream.h"
+#include "lttng-relayd.hpp"
+#include "viewer-stream.hpp"
 
-static void viewer_stream_destroy(struct relay_viewer_stream *vstream)
+static void viewer_stream_release_composite_objects(struct relay_viewer_stream *vstream)
 {
+       if (vstream->stream_file.handle) {
+               fs_handle_close(vstream->stream_file.handle);
+               vstream->stream_file.handle = NULL;
+       }
+       if (vstream->index_file) {
+               lttng_index_file_put(vstream->index_file);
+               vstream->index_file = NULL;
+       }
+       if (vstream->stream) {
+               stream_put(vstream->stream);
+               vstream->stream = NULL;
+       }
        lttng_trace_chunk_put(vstream->stream_file.trace_chunk);
+       vstream->stream_file.trace_chunk = NULL;
+}
+
+static void viewer_stream_destroy(struct relay_viewer_stream *vstream)
+{
        free(vstream->path_name);
        free(vstream->channel_name);
        free(vstream);
@@ -45,7 +62,7 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream,
 
        ASSERT_LOCKED(stream->lock);
 
-       vstream = (relay_viewer_stream *) zmalloc(sizeof(*vstream));
+       vstream = zmalloc<relay_viewer_stream>();
        if (!vstream) {
                PERROR("relay viewer stream zmalloc");
                goto error;
@@ -198,6 +215,8 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream,
 
 error:
        if (vstream) {
+               /* Not using `put` since vstream is assumed to be published. */
+               viewer_stream_release_composite_objects(vstream);
                viewer_stream_destroy(vstream);
        }
        return NULL;
@@ -221,23 +240,8 @@ static void viewer_stream_release(struct urcu_ref *ref)
        if (vstream->stream->is_metadata) {
                rcu_assign_pointer(vstream->stream->trace->viewer_metadata_stream, NULL);
        }
-
        viewer_stream_unpublish(vstream);
-
-       if (vstream->stream_file.handle) {
-               fs_handle_close(vstream->stream_file.handle);
-               vstream->stream_file.handle = NULL;
-       }
-       if (vstream->index_file) {
-               lttng_index_file_put(vstream->index_file);
-               vstream->index_file = NULL;
-       }
-       if (vstream->stream) {
-               stream_put(vstream->stream);
-               vstream->stream = NULL;
-       }
-       lttng_trace_chunk_put(vstream->stream_file.trace_chunk);
-       vstream->stream_file.trace_chunk = NULL;
+       viewer_stream_release_composite_objects(vstream);
        call_rcu(&vstream->rcu_node, viewer_stream_destroy_rcu);
 }
 
This page took 0.027403 seconds and 4 git commands to generate.