Fix: sessiond: uninitialized bytes sent to lttng-ust
[lttng-tools.git] / src / bin / lttng-sessiond / event-notifier-error-accounting.cpp
index 138d51b4df2fd2823979f32f3eec7c2ad08e74eb..85327c2167b648d38541dcb282cdf2ca613f7908 100644 (file)
 #include <urcu/compiler.h>
 #include <pthread.h>
 
-#include <common/error.h>
-#include <common/hashtable/hashtable.h>
-#include <common/index-allocator.h>
-#include <common/kernel-ctl/kernel-ctl.h>
-#include <common/shm.h>
-#include <lttng/trigger/trigger-internal.h>
+#include <common/error.hpp>
+#include <common/hashtable/hashtable.hpp>
+#include <common/index-allocator.hpp>
+#include <common/kernel-ctl/kernel-ctl.hpp>
+#include <common/shm.hpp>
+#include <lttng/trigger/trigger-internal.hpp>
 
-#include "event-notifier-error-accounting.h"
-#include "lttng-ust-error.h"
-#include "ust-app.h"
+#include "event-notifier-error-accounting.hpp"
+#include "lttng-ust-error.hpp"
+#include "ust-app.hpp"
 
 #define ERROR_COUNTER_INDEX_HT_INITIAL_SIZE 16
 
+namespace {
 struct index_ht_entry {
        struct lttng_ht_node_u64 node;
        uint64_t error_counter_index;
@@ -53,10 +54,10 @@ struct kernel_error_accounting_entry {
        int error_counter_fd;
 };
 
-static struct kernel_error_accounting_entry kernel_error_accounting_entry;
+struct kernel_error_accounting_entry kernel_error_accounting_entry;
 
 /* Hashtable mapping uid to error_account_entry. */
-static struct lttng_ht *error_counter_uid_ht;
+struct lttng_ht *error_counter_uid_ht;
 
 struct error_accounting_state {
        struct lttng_index_allocator *index_allocator;
@@ -65,8 +66,9 @@ struct error_accounting_state {
        uint64_t number_indices;
 };
 
-static struct error_accounting_state ust_state;
-static struct error_accounting_state kernel_state;
+struct error_accounting_state ust_state;
+struct error_accounting_state kernel_state;
+} /* namespace */
 
 static inline void get_trigger_info_for_log(const struct lttng_trigger *trigger,
                const char **trigger_name,
@@ -113,18 +115,20 @@ const char *error_accounting_status_str(
 }
 
 #ifdef HAVE_LIBLTTNG_UST_CTL
+namespace {
 struct event_notifier_counter {
        pthread_mutex_t lock;
        long count;
 };
 
-static struct event_notifier_counter the_event_notifier_counter;
+struct event_notifier_counter the_event_notifier_counter;
+} /* namespace */
 
 static void free_ust_error_accounting_entry(struct rcu_head *head)
 {
        int i;
        struct ust_error_accounting_entry *entry =
-                       caa_container_of(head, typeof(*entry), rcu_head);
+                       lttng::utils::container_of(head, &ust_error_accounting_entry::rcu_head);
 
        for (i = 0; i < entry->nr_counter_cpu_fds; i++) {
                lttng_ust_ctl_release_object(-1, entry->cpu_counters[i]);
@@ -151,7 +155,7 @@ static
 void ust_error_accounting_entry_release(struct urcu_ref *entry_ref)
 {
        struct ust_error_accounting_entry *entry =
-                       container_of(entry_ref, typeof(*entry), ref);
+                       lttng::utils::container_of(entry_ref, &ust_error_accounting_entry::ref);
 
        rcu_read_lock();
        cds_lfht_del(error_counter_uid_ht->ht, &entry->node.node);
@@ -318,8 +322,7 @@ enum event_notifier_error_accounting_status get_error_counter_index_for_token(
        lttng_ht_lookup(state->indices_ht, &tracer_token, &iter);
        node = lttng_ht_iter_get_node_u64(&iter);
        if (node) {
-               index_entry = caa_container_of(
-                               node, const struct index_ht_entry, node);
+               index_entry = lttng::utils::container_of(node, &index_ht_entry::node);
                *error_counter_index = index_entry->error_counter_index;
                status = EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK;
        } else {
@@ -375,7 +378,7 @@ struct ust_error_accounting_entry *ust_error_accounting_entry_create(
        struct lttng_ust_ctl_daemon_counter *daemon_counter;
        struct lttng_ust_abi_object_data *counter, **cpu_counters;
        struct ust_error_accounting_entry *entry = NULL;
-       lttng_ust_ctl_counter_dimension dimension;
+       lttng_ust_ctl_counter_dimension dimension = {};
 
        dimension.size = ust_state.number_indices;
        dimension.has_underflow = false;
@@ -387,7 +390,7 @@ struct ust_error_accounting_entry *ust_error_accounting_entry_create(
                goto error;
        }
 
-       entry = (ust_error_accounting_entry *) zmalloc(sizeof(struct ust_error_accounting_entry));
+       entry = zmalloc<ust_error_accounting_entry>();
        if (!entry) {
                PERROR("Failed to allocate event notifier error acounting entry")
                goto error;
@@ -397,7 +400,7 @@ struct ust_error_accounting_entry *ust_error_accounting_entry_create(
        entry->uid = app->uid;
        entry->nr_counter_cpu_fds = lttng_ust_ctl_get_nr_cpu_per_counter();
 
-       cpu_counter_fds = (int *) zmalloc(entry->nr_counter_cpu_fds * sizeof(*cpu_counter_fds));
+       cpu_counter_fds = calloc<int>(entry->nr_counter_cpu_fds);
        if (!cpu_counter_fds) {
                PERROR("Failed to allocate event notifier error counter file descriptors array: application uid = %d, application name = '%s', pid = %d, allocation size = %zu",
                                (int) app->uid, app->name, (int) app->pid,
@@ -410,7 +413,7 @@ struct ust_error_accounting_entry *ust_error_accounting_entry_create(
                cpu_counter_fds[i] = -1;
        }
 
-       cpu_counters = (lttng_ust_abi_object_data **) zmalloc(entry->nr_counter_cpu_fds * sizeof(struct lttng_ust_abi_object_data *));
+       cpu_counters = calloc<lttng_ust_abi_object_data *>(entry->nr_counter_cpu_fds);
        if (!cpu_counters) {
                PERROR("Failed to allocate event notifier error counter lttng_ust_abi_object_data array: application uid = %d, application name = '%s', pid = %d, allocation size = %zu",
                                (int) app->uid, app->name, (int) app->pid,
@@ -653,7 +656,7 @@ event_notifier_error_accounting_register_app(struct ust_app *app)
                goto error_send_counter_data;
        }
 
-       cpu_counters = (lttng_ust_abi_object_data **) zmalloc(entry->nr_counter_cpu_fds * sizeof(struct lttng_ust_abi_object_data *));
+       cpu_counters = calloc<lttng_ust_abi_object_data *>(entry->nr_counter_cpu_fds);
        if (!cpu_counters) {
                PERROR("Failed to allocate event notifier error counter lttng_ust_abi_object_data array: application uid = %d, application name = '%s', pid = %d, allocation size = %zu",
                                (int) app->uid, app->name, (int) app->pid,
@@ -1050,7 +1053,7 @@ enum event_notifier_error_accounting_status create_error_counter_index_for_token
                goto end;
        }
 
-       index_entry = (index_ht_entry *) zmalloc(sizeof(*index_entry));
+       index_entry = zmalloc<index_ht_entry>();
        if (index_entry == NULL) {
                PERROR("Failed to allocate event notifier error counter hash table entry");
                status = EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_NOMEM;
@@ -1324,8 +1327,8 @@ void event_notifier_error_accounting_unregister_event_notifier(
        node = lttng_ht_iter_get_node_u64(&iter);
        if (node) {
                int del_ret;
-               struct index_ht_entry *index_entry = caa_container_of(
-                               node, typeof(*index_entry), node);
+               struct index_ht_entry *index_entry =
+                               lttng::utils::container_of(node, &index_ht_entry::node);
                enum lttng_index_allocator_status index_alloc_status;
 
                index_alloc_status = lttng_index_allocator_release(
This page took 0.02612 seconds and 4 git commands to generate.