Fix: sessiond: ODR violation results in memory corruption
[lttng-tools.git] / src / common / fd-tracker / fd-tracker.cpp
index 9c6f031b0b6dc6e4995dde7d72f50fc158c06824..e1f9b14fbba8fa618e072d5addc422f2c5cbdaec 100644 (file)
@@ -80,6 +80,7 @@ struct fd_tracker {
        struct lttng_unlinked_file_pool *unlinked_file_pool;
 };
 
+namespace {
 struct open_properties {
        int flags;
        LTTNG_OPTIONAL(mode_t) mode;
@@ -124,7 +125,7 @@ struct unsuspendable_fd {
        struct rcu_head rcu_head;
 };
 
-static struct {
+struct {
        pthread_mutex_t lock;
        bool initialized;
        unsigned long value;
@@ -133,6 +134,7 @@ static struct {
        .initialized = false,
        .value = 0,
 };
+} /* namespace */
 
 static int match_fd(struct cds_lfht_node *node, const void *key);
 static void unsuspendable_fd_destroy(struct unsuspendable_fd *entry);
@@ -188,7 +190,7 @@ static void unsuspendable_fd_destroy(struct unsuspendable_fd *entry)
 static struct unsuspendable_fd *unsuspendable_fd_create(
                const char *name, int fd)
 {
-       struct unsuspendable_fd *entry = (unsuspendable_fd *) zmalloc(sizeof(*entry));
+       struct unsuspendable_fd *entry = zmalloc<unsuspendable_fd>();
 
        if (!entry) {
                goto error;
@@ -365,7 +367,7 @@ end:
 struct fd_tracker *fd_tracker_create(const char *unlinked_file_path,
                unsigned int capacity)
 {
-       struct fd_tracker *tracker = (fd_tracker *) zmalloc(sizeof(struct fd_tracker));
+       struct fd_tracker *tracker = zmalloc<fd_tracker>();
 
        if (!tracker) {
                goto end;
@@ -526,7 +528,7 @@ struct fs_handle *fd_tracker_open_fs_handle(struct fd_tracker *tracker,
                }
        }
 
-       handle = (fs_handle_tracked *) zmalloc(sizeof(*handle));
+       handle = zmalloc<fs_handle_tracked>();
        if (!handle) {
                goto end;
        }
@@ -620,7 +622,7 @@ int fd_tracker_open_unsuspendable_fd(struct fd_tracker *tracker,
        unsigned int active_fds;
        struct unsuspendable_fd **entries;
 
-       entries = (unsuspendable_fd **) zmalloc(fd_count * sizeof(*entries));
+       entries = calloc<unsuspendable_fd *>(fd_count);
        if (!entries) {
                ret = -1;
                goto end;
@@ -719,7 +721,7 @@ int fd_tracker_close_unsuspendable_fd(struct fd_tracker *tracker,
         * Maintain a local copy of fds_in as the user's callback may modify its
         * contents (e.g. setting the fd(s) to -1 after close).
         */
-       fds = (int *) malloc(sizeof(*fds) * fd_count);
+       fds = malloc<int>(sizeof(*fds) * fd_count);
        if (!fds) {
                ret = -1;
                goto end;
This page took 0.024283 seconds and 4 git commands to generate.