Add type-checked versions of allocation and deallocations functions
[lttng-tools.git] / src / bin / lttng-sessiond / ust-app.cpp
index 1ae2bbac3e0c278b38b961aec677b98726907103..fcc4267ad5ea8360ae6e139bada338f6f1dff83e 100644 (file)
 #include <urcu/compiler.h>
 #include <signal.h>
 
-#include <common/bytecode/bytecode.h>
-#include <common/compat/errno.h>
-#include <common/common.h>
-#include <common/hashtable/utils.h>
+#include <common/bytecode/bytecode.hpp>
+#include <common/compat/errno.hpp>
+#include <common/common.hpp>
+#include <common/hashtable/utils.hpp>
 #include <lttng/event-rule/event-rule.h>
-#include <lttng/event-rule/event-rule-internal.h>
+#include <lttng/event-rule/event-rule-internal.hpp>
 #include <lttng/event-rule/user-tracepoint.h>
 #include <lttng/condition/condition.h>
-#include <lttng/condition/event-rule-matches-internal.h>
+#include <lttng/condition/event-rule-matches-internal.hpp>
 #include <lttng/condition/event-rule-matches.h>
-#include <lttng/trigger/trigger-internal.h>
-#include <common/sessiond-comm/sessiond-comm.h>
-
-#include "buffer-registry.h"
-#include "condition-internal.h"
-#include "fd-limit.h"
-#include "health-sessiond.h"
-#include "ust-app.h"
-#include "ust-consumer.h"
-#include "lttng-ust-ctl.h"
-#include "lttng-ust-error.h"
-#include "utils.h"
-#include "session.h"
-#include "lttng-sessiond.h"
-#include "notification-thread-commands.h"
-#include "rotate.h"
-#include "event.h"
-#include "event-notifier-error-accounting.h"
-#include "ust-field-utils.h"
+#include <lttng/trigger/trigger-internal.hpp>
+#include <common/sessiond-comm/sessiond-comm.hpp>
+
+#include "buffer-registry.hpp"
+#include "condition-internal.hpp"
+#include "fd-limit.hpp"
+#include "health-sessiond.hpp"
+#include "ust-app.hpp"
+#include "ust-consumer.hpp"
+#include "lttng-ust-ctl.hpp"
+#include "lttng-ust-error.hpp"
+#include "utils.hpp"
+#include "session.hpp"
+#include "lttng-sessiond.hpp"
+#include "notification-thread-commands.hpp"
+#include "rotate.hpp"
+#include "event.hpp"
+#include "event-notifier-error-accounting.hpp"
+#include "ust-field-utils.hpp"
 
 struct lttng_ht *ust_app_ht;
 struct lttng_ht *ust_app_ht_by_sock;
@@ -696,7 +696,7 @@ ssize_t ust_app_push_metadata(struct ust_registry_session *registry,
        }
 
        /* Allocate only what we have to send. */
-       metadata_str = (char *) zmalloc(len);
+       metadata_str = calloc<char>(len);
        if (!metadata_str) {
                PERROR("zmalloc ust app metadata string");
                ret_val = -ENOMEM;
@@ -1160,7 +1160,7 @@ struct ust_app_session *alloc_ust_app_session(void)
        struct ust_app_session *ua_sess;
 
        /* Init most of the default value by allocating and zeroing */
-       ua_sess = (ust_app_session *) zmalloc(sizeof(struct ust_app_session));
+       ua_sess = zmalloc<ust_app_session>();
        if (ua_sess == NULL) {
                PERROR("malloc");
                goto error_free;
@@ -1188,7 +1188,7 @@ struct ust_app_channel *alloc_ust_app_channel(const char *name,
        struct ust_app_channel *ua_chan;
 
        /* Init most of the default value by allocating and zeroing */
-       ua_chan = (ust_app_channel *) zmalloc(sizeof(struct ust_app_channel));
+       ua_chan = zmalloc<ust_app_channel>();
        if (ua_chan == NULL) {
                PERROR("malloc");
                goto error;
@@ -1240,7 +1240,7 @@ struct ust_app_stream *ust_app_alloc_stream(void)
 {
        struct ust_app_stream *stream = NULL;
 
-       stream = (ust_app_stream *) zmalloc(sizeof(*stream));
+       stream = zmalloc<ust_app_stream>();
        if (stream == NULL) {
                PERROR("zmalloc ust app stream");
                goto error;
@@ -1263,7 +1263,7 @@ struct ust_app_event *alloc_ust_app_event(char *name,
        struct ust_app_event *ua_event;
 
        /* Init most of the default value by allocating and zeroing */
-       ua_event = (ust_app_event *) zmalloc(sizeof(struct ust_app_event));
+       ua_event = zmalloc<ust_app_event>();
        if (ua_event == NULL) {
                PERROR("Failed to allocate ust_app_event structure");
                goto error;
@@ -1300,7 +1300,7 @@ static struct ust_app_event_notifier_rule *alloc_ust_app_event_notifier_rule(
        struct lttng_condition *condition = NULL;
        const struct lttng_event_rule *event_rule = NULL;
 
-       ua_event_notifier_rule = (ust_app_event_notifier_rule *) zmalloc(sizeof(struct ust_app_event_notifier_rule));
+       ua_event_notifier_rule = zmalloc<ust_app_event_notifier_rule>();
        if (ua_event_notifier_rule == NULL) {
                PERROR("Failed to allocate ust_app_event_notifier_rule structure");
                goto error;
@@ -1360,7 +1360,7 @@ struct ust_app_ctx *alloc_ust_app_ctx(struct lttng_ust_context_attr *uctx)
 {
        struct ust_app_ctx *ua_ctx;
 
-       ua_ctx = (ust_app_ctx *) zmalloc(sizeof(struct ust_app_ctx));
+       ua_ctx = zmalloc<ust_app_ctx>();
        if (ua_ctx == NULL) {
                goto error;
        }
@@ -1403,7 +1403,7 @@ static struct lttng_ust_abi_filter_bytecode *create_ust_filter_bytecode_from_byt
        struct lttng_ust_abi_filter_bytecode *filter = NULL;
 
        /* Copy filter bytecode. */
-       filter = (lttng_ust_abi_filter_bytecode *) zmalloc(sizeof(*filter) + orig_f->len);
+       filter = zmalloc<lttng_ust_abi_filter_bytecode>(sizeof(*filter) + orig_f->len);
        if (!filter) {
                PERROR("Failed to allocate lttng_ust_filter_bytecode: bytecode len = %" PRIu32 " bytes", orig_f->len);
                goto error;
@@ -1427,7 +1427,7 @@ create_ust_capture_bytecode_from_bytecode(const struct lttng_bytecode *orig_f)
        struct lttng_ust_abi_capture_bytecode *capture = NULL;
 
        /* Copy capture bytecode. */
-       capture = (lttng_ust_abi_capture_bytecode *) zmalloc(sizeof(*capture) + orig_f->len);
+       capture = zmalloc<lttng_ust_abi_capture_bytecode>(sizeof(*capture) + orig_f->len);
        if (!capture) {
                PERROR("Failed to allocate lttng_ust_abi_capture_bytecode: bytecode len = %" PRIu32 " bytes", orig_f->len);
                goto error;
@@ -1711,7 +1711,7 @@ struct lttng_ust_abi_event_exclusion *create_ust_exclusion_from_exclusion(
        size_t exclusion_alloc_size = sizeof(struct lttng_ust_abi_event_exclusion) +
                LTTNG_UST_ABI_SYM_NAME_LEN * exclusion->count;
 
-       ust_exclusion = (lttng_ust_abi_event_exclusion *) zmalloc(exclusion_alloc_size);
+       ust_exclusion = zmalloc<lttng_ust_abi_event_exclusion>(exclusion_alloc_size);
        if (!ust_exclusion) {
                PERROR("malloc");
                goto end;
@@ -2331,7 +2331,7 @@ static void shadow_copy_event(struct ust_app_event *ua_event,
        if (uevent->exclusion) {
                exclusion_alloc_size = sizeof(struct lttng_event_exclusion) +
                                LTTNG_UST_ABI_SYM_NAME_LEN * uevent->exclusion->count;
-               ua_event->exclusion = (lttng_event_exclusion *) zmalloc(exclusion_alloc_size);
+               ua_event->exclusion = zmalloc<lttng_event_exclusion>(exclusion_alloc_size);
                if (ua_event->exclusion == NULL) {
                        PERROR("malloc");
                } else {
@@ -3319,7 +3319,7 @@ static int send_channel_uid_to_ust(struct buffer_reg_channel *buf_reg_chan,
        /* Send all streams to application. */
        pthread_mutex_lock(&buf_reg_chan->stream_list_lock);
        cds_list_for_each_entry(reg_stream, &buf_reg_chan->streams, lnode) {
-               struct ust_app_stream stream;
+               struct ust_app_stream stream = {};
 
                ret = duplicate_stream_object(reg_stream, &stream);
                if (ret < 0) {
@@ -3336,8 +3336,8 @@ static int send_channel_uid_to_ust(struct buffer_reg_channel *buf_reg_chan,
                                 * Treat this the same way as an application
                                 * that is exiting.
                                 */
-                               WARN("Communication with application %d timed out on send_stream for stream \"%s\" of channel \"%s\" of session \"%" PRIu64 "\".",
-                                               app->pid, stream.name,
+                               WARN("Communication with application %d timed out on send_stream for stream of channel \"%s\" of session \"%" PRIu64 "\".",
+                                               app->pid,
                                                ua_chan->name,
                                                ua_sess->tracing_id);
                                ret = -ENOTCONN;
@@ -3993,7 +3993,7 @@ struct ust_app *ust_app_create(struct ust_register_msg *msg, int sock)
                goto error;
        }
 
-       lta = (ust_app *) zmalloc(sizeof(struct ust_app));
+       lta = zmalloc<ust_app>();
        if (lta == NULL) {
                PERROR("malloc");
                goto error_free_pipe;
@@ -4369,7 +4369,7 @@ int ust_app_list_events(struct lttng_event **events)
        struct lttng_event *tmp_event;
 
        nbmem = UST_APP_EVENT_LIST_SIZE;
-       tmp_event = (lttng_event *) zmalloc(nbmem * sizeof(struct lttng_event));
+       tmp_event = calloc<lttng_event>(nbmem);
        if (tmp_event == NULL) {
                PERROR("zmalloc ust app events");
                ret = -ENOMEM;
@@ -4504,7 +4504,7 @@ int ust_app_list_event_fields(struct lttng_event_field **fields)
        struct lttng_event_field *tmp_event;
 
        nbmem = UST_APP_EVENT_LIST_SIZE;
-       tmp_event = (lttng_event_field *) zmalloc(nbmem * sizeof(struct lttng_event_field));
+       tmp_event = calloc<lttng_event_field>(nbmem);
        if (tmp_event == NULL) {
                PERROR("zmalloc ust app event fields");
                ret = -ENOMEM;
@@ -6389,11 +6389,13 @@ static int ust_app_fixup_legacy_context_fields(size_t *_nr_fields,
        if (!found) {
                goto end;
        }
-       new_fields = (struct lttng_ust_ctl_field *) zmalloc(sizeof(*new_fields) * new_nr_fields);
+
+       new_fields = calloc<lttng_ust_ctl_field>(new_nr_fields);
        if (!new_fields) {
                ret = -ENOMEM;
                goto end;
        }
+
        for (i = 0, j = 0; i < nr_fields; i++, j++) {
                const struct lttng_ust_ctl_field *field = &fields[i];
                struct lttng_ust_ctl_field *new_field = &new_fields[j];
@@ -6944,7 +6946,7 @@ void ust_app_notify_sock_unregister(int sock)
 
        rcu_read_lock();
 
-       obj = (ust_app_notify_sock_obj *) zmalloc(sizeof(*obj));
+       obj = zmalloc<ust_app_notify_sock_obj>();
        if (!obj) {
                /*
                 * An ENOMEM is kind of uncool. If this strikes we continue the
This page took 0.027529 seconds and 4 git commands to generate.