Add type-checked versions of allocation and deallocations functions
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Nov 2021 02:36:17 +0000 (21:36 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 31 Mar 2022 02:59:33 +0000 (22:59 -0400)
A common mistake when porting things from C to C++ is to use malloc for
types that have a on-trivial constructor (and to not call the
constructor explicitly either). For example:

struct foo {
std::vector<int> field;
};

foo *f = (foo *) zmalloc(sizeof(*f));

This allocates a `foo` without calling the constructor, leaving it in an
invalid state. Same idea when free-ing with free something that has a
non-trivial destructor.

To avoid this, I suggest adding templated allocation functions that we
will use throughout, that verify if the given type is safe to malloc
(and generate a compilation failure if not). The existing code barely
needs changes. For example:

- (foo *) zmalloc(sizeof(*f))
+ zmalloc<foo>()

For simplicity I propose that as soon as a type is non-POD
(std::is_pod<T>::value is false), we prevent using malloc/free on it. It
would be ok in theory to allocate such a type with malloc and free with
free, but call the constructor (using placement-new) and destructor
explicitly, but I don't see why we would want to do that. It might also
be technically more correct to use a combination of
std::is_trivially_constructible and std::is_trivially_destructible
(std::is_pod being not fine-grained enough), but using std::is_pod just
keeps things simpler.

This patch introduces the following templated allocation functions:

1. zmalloc<T>()
2. zmalloc<T>(size)
3. malloc<T>()
4. malloc<T>(size)
5. calloc<T>(nmemb)

1. Allocate one T, zero-initialized
2. Allocate a buffer of size `size`, zero-initialized, this is used when
   the caller calculates the size to allocate, like when using flexible
   array members
3. Same as 1, but without the zero-initialization
4. Same as 2, but without the zero-initialization
5. Allocate an array of `nmemb` elements of type T, zero-initialized

For the de-allocation side, add templated `free` function declaration
that uses std::enable_if (SFINAE) to declare a deleted prototype if the
type T isn't safe to free (causing a compilation error).

There are a lot of places where we pass pointers to void to free. These
can't be checked, as we don't know what type of object the pointer
really points to. We could forbid that and fix all callers to pass a
typed pointer, but that seems a bit too much to chew for the moment. So
for now, simply accept that freeing pointers to void won't be checked.
It's a best effort.

As an example, if I add an explicit constructor to type ctf_trace (in
src/bin/lttng-relayd/ctf-trace.h), I get the following errors with
clang. For the allocation:

/home/simark/src/lttng-tools/src/common/macros.h:57:2: error: static_assert failed due to requirement 'std::is_pod<ctf_trace>::value' "type is POD"
static_assert (std::is_pod<T>::value, "type is POD");
^              ~~~~~~~~~~~~~~~~~~~~~
/home/simark/src/lttng-tools/src/bin/lttng-relayd/ctf-trace.cpp:84:10: note: in instantiation of function template specialization 'zmalloc<ctf_trace>' requested here
trace = zmalloc<ctf_trace>();
^

For the de-allocation:

/home/simark/src/lttng-tools/src/bin/lttng-relayd/ctf-trace.cpp:29:2: error: call to deleted function 'free'
free(trace);
^~~~
/home/simark/src/lttng-tools/src/common/macros.h:125:6: note: candidate function [with T = ctf_trace, $1 = void] has been explicitly deleted
void free(T *p) = delete;
     ^
/usr/include/stdlib.h:565:13: note: candidate function
extern void free (void *__ptr) __THROW;
    ^

Change-Id: I246a9113d08fa36b81a49137f4e80a5e808de913
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
135 files changed:
src/bin/lttng-crash/lttng-crash.cpp
src/bin/lttng-relayd/backward-compatibility-group-by.cpp
src/bin/lttng-relayd/connection.cpp
src/bin/lttng-relayd/ctf-trace.cpp
src/bin/lttng-relayd/index.cpp
src/bin/lttng-relayd/live.cpp
src/bin/lttng-relayd/session.cpp
src/bin/lttng-relayd/sessiond-trace-chunks.cpp
src/bin/lttng-relayd/stream.cpp
src/bin/lttng-relayd/tracefile-array.cpp
src/bin/lttng-relayd/viewer-session.cpp
src/bin/lttng-relayd/viewer-stream.cpp
src/bin/lttng-sessiond/action-executor.cpp
src/bin/lttng-sessiond/agent-thread.cpp
src/bin/lttng-sessiond/agent.cpp
src/bin/lttng-sessiond/buffer-registry.cpp
src/bin/lttng-sessiond/channel.cpp
src/bin/lttng-sessiond/clear.cpp
src/bin/lttng-sessiond/client.cpp
src/bin/lttng-sessiond/cmd.cpp
src/bin/lttng-sessiond/consumer.cpp
src/bin/lttng-sessiond/dispatch.cpp
src/bin/lttng-sessiond/event-notifier-error-accounting.cpp
src/bin/lttng-sessiond/health.cpp
src/bin/lttng-sessiond/kernel.cpp
src/bin/lttng-sessiond/lttng-syscall.cpp
src/bin/lttng-sessiond/manage-apps.cpp
src/bin/lttng-sessiond/manage-consumer.cpp
src/bin/lttng-sessiond/manage-kernel.cpp
src/bin/lttng-sessiond/modprobe.cpp
src/bin/lttng-sessiond/notification-thread-commands.cpp
src/bin/lttng-sessiond/notification-thread-events.cpp
src/bin/lttng-sessiond/notification-thread.cpp
src/bin/lttng-sessiond/notify-apps.cpp
src/bin/lttng-sessiond/register.cpp
src/bin/lttng-sessiond/rotation-thread.cpp
src/bin/lttng-sessiond/save.cpp
src/bin/lttng-sessiond/session.cpp
src/bin/lttng-sessiond/snapshot.cpp
src/bin/lttng-sessiond/thread.cpp
src/bin/lttng-sessiond/trace-kernel.cpp
src/bin/lttng-sessiond/trace-ust.cpp
src/bin/lttng-sessiond/tracker.cpp
src/bin/lttng-sessiond/ust-app.cpp
src/bin/lttng-sessiond/ust-registry.cpp
src/bin/lttng/commands/add_context.cpp
src/bin/lttng/commands/enable_events.cpp
src/bin/lttng/commands/list.cpp
src/bin/lttng/conf.cpp
src/bin/lttng/uprobe.cpp
src/common/actions/list.cpp
src/common/actions/notify.cpp
src/common/actions/path.cpp
src/common/actions/rate-policy.cpp
src/common/actions/rotate-session.cpp
src/common/actions/snapshot-session.cpp
src/common/actions/start-session.cpp
src/common/actions/stop-session.cpp
src/common/argpar-utils/argpar-utils.hpp
src/common/bytecode/bytecode.cpp
src/common/channel.cpp
src/common/compat/directory-handle.cpp
src/common/compat/poll.cpp
src/common/compat/string.hpp
src/common/conditions/buffer-usage.cpp
src/common/conditions/event-rule-matches.cpp
src/common/conditions/session-consumed-size.cpp
src/common/conditions/session-rotation.cpp
src/common/config/session-config.cpp
src/common/consumer/consumer-metadata-cache.cpp
src/common/consumer/consumer-stream.cpp
src/common/consumer/consumer.cpp
src/common/consumer/metadata-bucket.cpp
src/common/context.cpp
src/common/error-query.cpp
src/common/event-expr/event-expr.cpp
src/common/event-field-value.cpp
src/common/event-rule/jul-logging.cpp
src/common/event-rule/kernel-kprobe.cpp
src/common/event-rule/kernel-syscall.cpp
src/common/event-rule/kernel-tracepoint.cpp
src/common/event-rule/kernel-uprobe.cpp
src/common/event-rule/log4j-logging.cpp
src/common/event-rule/python-logging.cpp
src/common/event-rule/user-tracepoint.cpp
src/common/event.cpp
src/common/fd-handle.cpp
src/common/fd-tracker/fd-tracker.cpp
src/common/fd-tracker/inode.cpp
src/common/filter.cpp
src/common/filter/filter-parser.ypp
src/common/filter/filter-visitor-generate-ir.cpp
src/common/hashtable/hashtable.cpp
src/common/health/health.cpp
src/common/index-allocator.cpp
src/common/index/index.cpp
src/common/ini-config/ini-config.cpp
src/common/ini-config/ini.cpp
src/common/kernel-ctl/kernel-ctl.cpp
src/common/kernel-probe.cpp
src/common/location.cpp
src/common/log-level-rule.cpp
src/common/lttng-elf.cpp
src/common/macros.hpp
src/common/mi-lttng.cpp
src/common/notification.cpp
src/common/path.cpp
src/common/pipe.cpp
src/common/relayd/relayd.cpp
src/common/runas.cpp
src/common/session-descriptor.cpp
src/common/sessiond-comm/sessiond-comm.cpp
src/common/spawn-viewer.cpp
src/common/string-utils/string-utils.cpp
src/common/trace-chunk.cpp
src/common/tracker.cpp
src/common/trigger.cpp
src/common/uri.cpp
src/common/userspace-probe.cpp
src/common/ust-consumer/ust-consumer.cpp
src/common/utils.cpp
src/lib/lttng-ctl/channel.cpp
src/lib/lttng-ctl/clear.cpp
src/lib/lttng-ctl/destruction-handle.cpp
src/lib/lttng-ctl/event.cpp
src/lib/lttng-ctl/load.cpp
src/lib/lttng-ctl/lttng-ctl-health.cpp
src/lib/lttng-ctl/lttng-ctl.cpp
src/lib/lttng-ctl/rotate.cpp
src/lib/lttng-ctl/save.cpp
src/lib/lttng-ctl/snapshot.cpp
src/lib/lttng-ctl/tracker.cpp
tests/regression/tools/live/live_test.cpp
tests/unit/test_ust_data.cpp
tests/unit/test_utils_expand_path.cpp

index 0b4afc91bdfa49a95ed980fcd33f25cf3b627de4..f63ececc09d861049342883c65a4afb86df263e3 100644 (file)
@@ -781,7 +781,7 @@ int copy_crash_data(const struct lttng_crash_layout *layout, int fd_dest,
                return ret;
        }
        src_file_len = layout->mmap_length;
-       buf = (char *) zmalloc(src_file_len);
+       buf = calloc<char>(src_file_len);
        if (!buf) {
                return -1;
        }
@@ -1129,7 +1129,7 @@ int delete_dir_recursive(const char *path)
                }
 
                if (S_ISDIR(st.st_mode)) {
-                       char *subpath = (char *) zmalloc(PATH_MAX);
+                       char *subpath = calloc<char>(PATH_MAX);
 
                        if (!subpath) {
                                PERROR("zmalloc path");
index e1d289d98748090e9fada15a72c8536d52b675f6..78f8a1971a190814919007e98f59ab33b6bb8ba9 100644 (file)
@@ -172,7 +172,7 @@ char *backward_compat_group_by_session(const char *path,
                                goto error_regex;
                        }
                } else {
-                       datetime = (char *) zmalloc(DATETIME_STR_LEN);
+                       datetime = calloc<char>(DATETIME_STR_LEN);
                        if (!datetime) {
                                PERROR("Failed to allocate DATETIME string");
                                goto error;
index c1e58aba3430f0fbbbedb89cb42261731cc94b3d..fb53862a436bde4a4c84b1cc7e6a467049efa444 100644 (file)
@@ -90,7 +90,7 @@ struct relay_connection *connection_create(struct lttcomm_sock *sock,
 {
        struct relay_connection *conn;
 
-       conn = (relay_connection *) zmalloc(sizeof(*conn));
+       conn = zmalloc<relay_connection>();
        if (!conn) {
                PERROR("zmalloc relay connection");
                goto end;
index 4ee745a10c9102b42e01f32a6e16ffbf699a12cd..cad67b78e2517296f06e3610b2d7b3d7e25d2ce2 100644 (file)
@@ -97,7 +97,7 @@ static struct ctf_trace *ctf_trace_create(struct relay_session *session,
 {
        struct ctf_trace *trace;
 
-       trace = (ctf_trace *) zmalloc(sizeof(*trace));
+       trace = zmalloc<ctf_trace>();
        if (!trace) {
                PERROR("Failed to allocate ctf_trace");
                goto end;
index 651b36715c106a9f0a2794ad1572b48a9ba0ffff..e7846a5b9233b9141d6c9ffd48717aa188d93641 100644 (file)
@@ -34,7 +34,7 @@ static struct relay_index *relay_index_create(struct relay_stream *stream,
        DBG2("Creating relay index for stream id %" PRIu64 " and seqnum %" PRIu64,
                        stream->stream_handle, net_seq_num);
 
-       index = (relay_index *) zmalloc(sizeof(*index));
+       index = zmalloc<relay_index>();
        if (!index) {
                PERROR("Relay index zmalloc");
                goto end;
index 64c194fdc9bcfd61ac02471406641de66f45d165..ef830d4ba0d4daa7a391f5c6d6e06753fad0bb78 100644 (file)
@@ -1112,7 +1112,7 @@ int viewer_list_sessions(struct relay_connection *conn)
        uint32_t buf_count = SESSION_BUF_DEFAULT_COUNT;
        uint32_t count = 0;
 
-       send_session_buf = (lttng_viewer_session *) zmalloc(SESSION_BUF_DEFAULT_COUNT * sizeof(*send_session_buf));
+       send_session_buf = calloc<lttng_viewer_session>(SESSION_BUF_DEFAULT_COUNT);
        if (!send_session_buf) {
                return -1;
        }
@@ -2115,7 +2115,7 @@ int viewer_get_packet(struct relay_connection *conn)
                reply_size += packet_data_len;
        }
 
-       reply = (char *) zmalloc(reply_size);
+       reply = zmalloc<char>(reply_size);
        if (!reply) {
                get_packet_status = LTTNG_VIEWER_GET_PACKET_ERR;
                PERROR("Falled to allocate reply, returning status=%s",
@@ -2378,7 +2378,7 @@ int viewer_get_metadata(struct relay_connection *conn)
        }
 
        reply.len = htobe64(len);
-       data = (char *) zmalloc(len);
+       data = zmalloc<char>(len);
        if (!data) {
                PERROR("viewer metadata zmalloc");
                goto error;
index abefc0d276ef355fefa11cc60d60de554e27b3da..a8a1520694025f3843b6cfabe9aebddca8a9488a 100644 (file)
@@ -310,7 +310,7 @@ struct relay_session *session_create(const char *session_name,
                goto error;
        }
 
-       session = (relay_session *) zmalloc(sizeof(*session));
+       session = zmalloc<relay_session>();
        if (!session) {
                PERROR("Failed to allocate session");
                goto error;
index 0a5c44825414bc720fe6081e459b5b3410c349b4..68a5e454f8afba796a4aeaa3e86a0ddcbe2cfdaf 100644 (file)
@@ -197,7 +197,7 @@ int trace_chunk_registry_ht_element_create(
                goto end;
        }
 
-       new_element = (trace_chunk_registry_ht_element *) zmalloc(sizeof(*new_element));
+       new_element = zmalloc<trace_chunk_registry_ht_element>();
        if (!new_element) {
                ret = -1;
                goto end;
@@ -263,7 +263,7 @@ end:
 struct sessiond_trace_chunk_registry *sessiond_trace_chunk_registry_create(void)
 {
        struct sessiond_trace_chunk_registry *sessiond_registry =
-                       (sessiond_trace_chunk_registry *) zmalloc(sizeof(*sessiond_registry));
+                       zmalloc<sessiond_trace_chunk_registry>();
 
        if (!sessiond_registry) {
                goto end;
index aba160bfa473c5ac401f9e62a55482839e3c837d..9f7bfcb15bb513229118302765c8c8f2655f7f91 100644 (file)
@@ -580,7 +580,7 @@ struct relay_stream *stream_create(struct ctf_trace *trace,
        bool acquired_reference = false;
        struct lttng_trace_chunk *current_trace_chunk;
 
-       stream = (relay_stream *) zmalloc(sizeof(struct relay_stream));
+       stream = zmalloc<relay_stream>();
        if (stream == NULL) {
                PERROR("relay stream zmalloc");
                goto error_no_alloc;
index 8b1b533d5d60e8520344531ff3f3813d36030591..73a2887941517275c4a860e89f71dab92585f3c8 100644 (file)
@@ -17,11 +17,11 @@ struct tracefile_array *tracefile_array_create(size_t count)
        struct tracefile_array *tfa = NULL;
        int i;
 
-       tfa = (tracefile_array *) zmalloc(sizeof(*tfa));
+       tfa = zmalloc<tracefile_array>();
        if (!tfa) {
                goto error;
        }
-       tfa->tf = (tracefile *) zmalloc(sizeof(*tfa->tf) * count);
+       tfa->tf = calloc<tracefile>(count);
        if (!tfa->tf) {
                goto error;
        }
index 4529a21fa7c9342f9aa30749dce2dcfd226dcdc0..194073f598783e011cf8b852515e34dba05950a3 100644 (file)
@@ -22,7 +22,7 @@ struct relay_viewer_session *viewer_session_create(void)
 {
        struct relay_viewer_session *vsession;
 
-       vsession = (relay_viewer_session *) zmalloc(sizeof(*vsession));
+       vsession = zmalloc<relay_viewer_session>();
        if (!vsession) {
                goto end;
        }
index fa447d45bb20584a75236d9969e0ade9a534d03a..2790903adb7962d706eeb8bb0e660b7229c17d26 100644 (file)
@@ -62,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;
index f43716c63986673377890c8a635f25c149a4f7d7..cc481e5b74fad316b6354306b9f7c3f5fe743545 100644 (file)
@@ -821,7 +821,7 @@ static void clean_up_action_executor_thread(void *_data)
 struct action_executor *action_executor_create(
                struct notification_thread_handle *handle)
 {
-       struct action_executor *executor = (action_executor *) zmalloc(sizeof(*executor));
+       struct action_executor *executor = zmalloc<action_executor>();
 
        if (!executor) {
                goto end;
@@ -893,7 +893,7 @@ enum action_executor_status action_executor_enqueue_trigger(
                goto error_unlock;
        }
 
-       work_item = (action_work_item *) zmalloc(sizeof(*work_item));
+       work_item = zmalloc<action_work_item>();
        if (!work_item) {
                PERROR("Failed to allocate action executor work item: trigger name = `%s`",
                                get_trigger_name(trigger));
index 77470b3ee1a25446a9a8f23e2be3c9f4f4a7e134..704f21d65b4add91b1e885269271228ab1759a71 100644 (file)
@@ -570,7 +570,7 @@ bool launch_agent_management_thread(void)
        struct thread_notifiers *notifiers;
        struct lttng_thread *thread;
 
-       notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers));
+       notifiers = zmalloc<thread_notifiers>();
        if (!notifiers) {
                goto error_alloc;
        }
index ed8a8d12607aad0c2e7d45fd43485f11071de0ba..08785235623d5d312d14b95960c1efaaac003f68 100644 (file)
@@ -348,7 +348,7 @@ static ssize_t list_events(struct agent_app *app, struct lttng_event **events)
                goto error;
        }
 
-       reply = (lttcomm_agent_list_reply *) zmalloc(data_size);
+       reply = zmalloc<lttcomm_agent_list_reply>(data_size);
        if (!reply) {
                ret = LTTNG_ERR_NOMEM;
                goto error;
@@ -361,7 +361,7 @@ static ssize_t list_events(struct agent_app *app, struct lttng_event **events)
        }
 
        nb_event = be32toh(reply->nb_event);
-       tmp_events = (lttng_event *) zmalloc(sizeof(*tmp_events) * nb_event);
+       tmp_events = calloc<lttng_event>(nb_event);
        if (!tmp_events) {
                ret = LTTNG_ERR_NOMEM;
                goto error;
@@ -441,7 +441,7 @@ static int enable_event(const struct agent_app *app, struct agent_event *event)
                goto error_io;
        }
 
-       bytes_to_send = (char *) zmalloc(data_size);
+       bytes_to_send = calloc<char>(data_size);
        if (!bytes_to_send) {
                ret = LTTNG_ERR_NOMEM;
                goto error;
@@ -726,7 +726,7 @@ struct agent_app_ctx *create_app_ctx(const struct lttng_event_context *ctx)
        }
 
        LTTNG_ASSERT(ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT);
-       agent_ctx = (agent_app_ctx *) zmalloc(sizeof(*ctx));
+       agent_ctx = zmalloc<agent_app_ctx>();
        if (!agent_ctx) {
                goto end;
        }
@@ -898,7 +898,7 @@ int agent_list_events(struct lttng_event **events,
        DBG2("Agent listing events for domain %d", domain);
 
        nbmem = UST_APP_EVENT_LIST_SIZE;
-       tmp_events = (lttng_event *) zmalloc(nbmem * sizeof(*tmp_events));
+       tmp_events = calloc<lttng_event>(nbmem);
        if (!tmp_events) {
                PERROR("zmalloc agent list events");
                ret = -ENOMEM;
@@ -974,7 +974,7 @@ struct agent_app *agent_create_app(pid_t pid, enum lttng_domain_type domain,
 
        LTTNG_ASSERT(sock);
 
-       app = (agent_app *) zmalloc(sizeof(*app));
+       app = zmalloc<agent_app>();
        if (!app) {
                PERROR("Failed to allocate agent application instance");
                goto error;
@@ -1117,7 +1117,7 @@ struct agent *agent_create(enum lttng_domain_type domain)
        int ret;
        struct agent *agt;
 
-       agt = (agent *) zmalloc(sizeof(struct agent));
+       agt = zmalloc<agent>();
        if (!agt) {
                goto error;
        }
@@ -1156,7 +1156,7 @@ struct agent_event *agent_create_event(const char *name,
                goto error;
        }
 
-       event = (agent_event *) zmalloc(sizeof(*event));
+       event = zmalloc<agent_event>();
        if (!event) {
                goto error;
        }
index ca7830a384d8dcca29537fc4e0c724f4216f9f7d..7a446633b8f878cbd6cfaad67a2a07ee33dd281b 100644 (file)
@@ -104,14 +104,14 @@ int buffer_reg_uid_create(uint64_t session_id, uint32_t bits_per_long, uid_t uid
 
        LTTNG_ASSERT(regp);
 
-       reg = (buffer_reg_uid *) zmalloc(sizeof(*reg));
+       reg = zmalloc<buffer_reg_uid>();
        if (!reg) {
                PERROR("zmalloc buffer registry uid");
                ret = -ENOMEM;
                goto error;
        }
 
-       reg->registry = (buffer_reg_session *) zmalloc(sizeof(struct buffer_reg_session));
+       reg->registry = zmalloc<buffer_reg_session>();
        if (!reg->registry) {
                PERROR("zmalloc buffer registry uid session");
                ret = -ENOMEM;
@@ -234,14 +234,14 @@ int buffer_reg_pid_create(uint64_t session_id, struct buffer_reg_pid **regp,
 
        LTTNG_ASSERT(regp);
 
-       reg = (buffer_reg_pid *) zmalloc(sizeof(*reg));
+       reg = zmalloc<buffer_reg_pid>();
        if (!reg) {
                PERROR("zmalloc buffer registry pid");
                ret = -ENOMEM;
                goto error;
        }
 
-       reg->registry = (buffer_reg_session *) zmalloc(sizeof(struct buffer_reg_session));
+       reg->registry = zmalloc<buffer_reg_session>();
        if (!reg->registry) {
                PERROR("zmalloc buffer registry pid session");
                ret = -ENOMEM;
@@ -371,7 +371,7 @@ int buffer_reg_channel_create(uint64_t key, struct buffer_reg_channel **regp)
 
        DBG3("Buffer registry channel create with key: %" PRIu64, key);
 
-       reg = (buffer_reg_channel *) zmalloc(sizeof(*reg));
+       reg = zmalloc<buffer_reg_channel>();
        if (!reg) {
                PERROR("zmalloc buffer registry channel");
                return -ENOMEM;
@@ -401,7 +401,7 @@ int buffer_reg_stream_create(struct buffer_reg_stream **regp)
 
        DBG3("Buffer registry creating stream");
 
-       reg = (buffer_reg_stream *) zmalloc(sizeof(*reg));
+       reg = zmalloc<buffer_reg_stream>();
        if (!reg) {
                PERROR("zmalloc buffer registry stream");
                return -ENOMEM;
index e3bb232fa155d32d9620c07c0a0c87bc406e0b85..540fc973405de16ebcc4d3fddf450827e9018f03 100644 (file)
@@ -34,13 +34,13 @@ struct lttng_channel *channel_new_default_attr(int dom,
        const char *channel_name = DEFAULT_CHANNEL_NAME;
        struct lttng_channel_extended *extended_attr = NULL;
 
-       chan = (lttng_channel *) zmalloc(sizeof(struct lttng_channel));
+       chan = zmalloc<lttng_channel>();
        if (chan == NULL) {
                PERROR("zmalloc channel init");
                goto error_alloc;
        }
 
-       extended_attr = (lttng_channel_extended *) zmalloc(sizeof(struct lttng_channel_extended));
+       extended_attr = zmalloc<lttng_channel_extended>();
        if (!extended_attr) {
                PERROR("zmalloc channel extended init");
                goto error;
index fcac76ffa4c349a7e97ce521b2d9cc8c06539413..04f2a368e44252152dba51c3ed868227e38df9cf 100644 (file)
@@ -67,7 +67,7 @@ int cmd_clear_session(struct ltt_session *session, int *sock_fd)
        usess = session->ust_session;
 
        if (sock_fd) {
-               reply_context = (cmd_clear_session_reply_context *) zmalloc(sizeof(*reply_context));
+               reply_context = zmalloc<cmd_clear_session_reply_context>();
                if (!reply_context) {
                        ret = LTTNG_ERR_NOMEM;
                        goto end;
index cf3fd44243bd18cbce118f4d53b37aa8000a0c15..37ea0509a2c3a71b8897b30d24a77b0859ff5064 100644 (file)
@@ -264,7 +264,7 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                                        tmp = "";
                                }
                                tmplen = strlen(the_config.consumerd64_lib_dir.value) + 1 /* : */ + strlen(tmp);
-                               tmpnew = (char *) zmalloc(tmplen + 1 /* \0 */);
+                               tmpnew = zmalloc<char>(tmplen + 1 /* \0 */);
                                if (!tmpnew) {
                                        ret = -ENOMEM;
                                        goto error;
@@ -306,7 +306,7 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                                        tmp = "";
                                }
                                tmplen = strlen(the_config.consumerd32_lib_dir.value) + 1 /* : */ + strlen(tmp);
-                               tmpnew = (char *) zmalloc(tmplen + 1 /* \0 */);
+                               tmpnew = zmalloc<char>(tmplen + 1 /* \0 */);
                                if (!tmpnew) {
                                        ret = -ENOMEM;
                                        goto error;
@@ -1751,7 +1751,7 @@ skip_domain:
                        goto error;
                }
 
-               uris = (lttng_uri *) zmalloc(len);
+               uris = calloc<lttng_uri>(nb_uri);
                if (uris == NULL) {
                        ret = LTTNG_ERR_FATAL;
                        goto error;
@@ -1892,31 +1892,35 @@ skip_domain:
        case LTTNG_LIST_SESSIONS:
        {
                unsigned int nr_sessions;
-               lttng_session *sessions_payload;
-               size_t payload_len;
+               lttng_session *sessions_payload = nullptr;
+               size_t payload_len = 0;
 
                session_lock_list();
                nr_sessions = lttng_sessions_count(
                                LTTNG_SOCK_GET_UID_CRED(&cmd_ctx->creds),
                                LTTNG_SOCK_GET_GID_CRED(&cmd_ctx->creds));
 
-               payload_len = (sizeof(struct lttng_session) * nr_sessions) +
-                               (sizeof(struct lttng_session_extended) * nr_sessions);
-               sessions_payload = (lttng_session *) zmalloc(payload_len);
+               if (nr_sessions > 0) {
+                       payload_len = (sizeof(struct lttng_session) *
+                                                     nr_sessions) +
+                                       (sizeof(struct lttng_session_extended) *
+                                                       nr_sessions);
+                       sessions_payload = zmalloc<lttng_session>(payload_len);
+                       if (!sessions_payload) {
+                               session_unlock_list();
+                               ret = -ENOMEM;
+                               goto setup_error;
+                       }
 
-               if (!sessions_payload) {
-                       session_unlock_list();
-                       ret = -ENOMEM;
-                       goto setup_error;
+                       cmd_list_lttng_sessions(sessions_payload, nr_sessions,
+                                       LTTNG_SOCK_GET_UID_CRED(&cmd_ctx->creds),
+                                       LTTNG_SOCK_GET_GID_CRED(&cmd_ctx->creds));
                }
 
-               cmd_list_lttng_sessions(sessions_payload, nr_sessions,
-                       LTTNG_SOCK_GET_UID_CRED(&cmd_ctx->creds),
-                       LTTNG_SOCK_GET_GID_CRED(&cmd_ctx->creds));
                session_unlock_list();
 
-               ret = setup_lttng_msg_no_cmd_header(cmd_ctx, sessions_payload,
-                       payload_len);
+               ret = setup_lttng_msg_no_cmd_header(
+                               cmd_ctx, sessions_payload, payload_len);
                free(sessions_payload);
 
                if (ret < 0) {
index 53a175372dadc5099b97d98d5795cf51a03ae600..aea78167160be7abc349758af1ad776d45b3c988 100644 (file)
@@ -2140,7 +2140,7 @@ static int _cmd_enable_event(struct ltt_session *session,
                                }
                        }
                        if (filter) {
-                               filter_a = (lttng_bytecode *) zmalloc(sizeof(*filter_a) + filter->len);
+                               filter_a = zmalloc<lttng_bytecode>(sizeof(*filter_a) + filter->len);
                                if (!filter_a) {
                                        free(filter_expression_a);
                                        ret = LTTNG_ERR_FATAL;
@@ -2368,7 +2368,7 @@ static int _cmd_enable_event(struct ltt_session *session,
                                                struct lttng_bytecode)
                                                + filter->len;
 
-                               filter_copy = (lttng_bytecode *) zmalloc(filter_size);
+                               filter_copy = zmalloc<lttng_bytecode>(filter_size);
                                if (!filter_copy) {
                                        ret = LTTNG_ERR_NOMEM;
                                        goto error;
@@ -3380,11 +3380,12 @@ int cmd_destroy_session(struct ltt_session *session,
        struct cmd_destroy_session_reply_context *reply_context = NULL;
 
        if (sock_fd) {
-               reply_context = (cmd_destroy_session_reply_context *) zmalloc(sizeof(*reply_context));
+               reply_context = zmalloc<cmd_destroy_session_reply_context>();
                if (!reply_context) {
                        ret = LTTNG_ERR_NOMEM;
                        goto end;
                }
+
                reply_context->reply_sock_fd = *sock_fd;
        }
 
@@ -3583,12 +3584,13 @@ int cmd_register_consumer(struct ltt_session *session,
                        goto error;
                }
 
-               socket->lock = (pthread_mutex_t *) zmalloc(sizeof(pthread_mutex_t));
+               socket->lock = zmalloc<pthread_mutex_t>();
                if (socket->lock == NULL) {
                        PERROR("zmalloc pthread mutex");
                        ret = LTTNG_ERR_FATAL;
                        goto error;
                }
+
                pthread_mutex_init(socket->lock, NULL);
                socket->registered = 1;
 
@@ -3651,7 +3653,7 @@ ssize_t cmd_list_domains(struct ltt_session *session,
                goto end;
        }
 
-       *domains = (lttng_domain *) zmalloc(nb_dom * sizeof(struct lttng_domain));
+       *domains = calloc<lttng_domain>(nb_dom);
        if (*domains == NULL) {
                ret = LTTNG_ERR_FATAL;
                goto error;
@@ -4193,7 +4195,7 @@ ssize_t cmd_snapshot_list_outputs(struct ltt_session *session,
                goto end;
        }
 
-       list = (lttng_snapshot_output *) zmalloc(session->snapshot.nb_output * sizeof(*list));
+       list = calloc<lttng_snapshot_output>(session->snapshot.nb_output);
        if (!list) {
                ret = -LTTNG_ERR_NOMEM;
                goto end;
index 238da05085739aaca35506b543b10380e89c1197..bdda3913597a7639150a67473517e92bf31f1180 100644 (file)
@@ -49,7 +49,7 @@ char *setup_channel_trace_path(struct consumer_output *consumer,
         * Allocate the string ourself to make sure we never exceed
         * LTTNG_PATH_MAX.
         */
-       pathname = (char *) zmalloc(LTTNG_PATH_MAX);
+       pathname = calloc<char>(LTTNG_PATH_MAX);
        if (!pathname) {
                goto error;
        }
@@ -429,7 +429,7 @@ struct consumer_socket *consumer_allocate_socket(int *fd)
 
        LTTNG_ASSERT(fd);
 
-       socket = (consumer_socket *) zmalloc(sizeof(struct consumer_socket));
+       socket = zmalloc<consumer_socket>();
        if (socket == NULL) {
                PERROR("zmalloc consumer socket");
                goto error;
@@ -520,7 +520,7 @@ struct consumer_output *consumer_create_output(enum consumer_dst_type type)
 {
        struct consumer_output *output = NULL;
 
-       output = (consumer_output *) zmalloc(sizeof(struct consumer_output));
+       output = zmalloc<consumer_output>();
        if (output == NULL) {
                PERROR("zmalloc consumer_output");
                goto error;
index 7988f1ba8a212894dc09d7c3e8338f267b6fb221..89d7c7c2e0d1fb894b02f10d7b17223ebbef9bee 100644 (file)
@@ -292,7 +292,7 @@ static void *thread_dispatch_ust_registration(void *data)
                                        ust_cmd->reg_msg.major, ust_cmd->reg_msg.minor);
 
                        if (ust_cmd->reg_msg.type == LTTNG_UST_CTL_SOCKET_CMD) {
-                               wait_node = (ust_reg_wait_node *) zmalloc(sizeof(*wait_node));
+                               wait_node = zmalloc<ust_reg_wait_node>();
                                if (!wait_node) {
                                        PERROR("zmalloc wait_node dispatch");
                                        ret = close(ust_cmd->sock);
@@ -510,7 +510,7 @@ bool launch_ust_dispatch_thread(struct ust_cmd_queue *cmd_queue,
        struct lttng_thread *thread;
        struct thread_notifiers *notifiers;
 
-       notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers));
+       notifiers = zmalloc<thread_notifiers>();
        if (!notifiers) {
                goto error;
        }
index 10d69493bbc5a9ecfd42a87b87252d3b7faf3d22..d42f5802d4c677238ece78c7314fc110cf7e4e9b 100644 (file)
@@ -387,7 +387,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 +397,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 +410,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 +653,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 +1050,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;
index a7f4bdcbb534dc82ae6b6cebaae876043a8f71f5..9a4dee8610b0deeb6b4c3527bc5da84b6ee140c5 100644 (file)
@@ -255,7 +255,7 @@ bool launch_health_management_thread(void)
        struct thread_notifiers *notifiers;
        struct lttng_thread *thread;
 
-       notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers));
+       notifiers = zmalloc<thread_notifiers>();
        if (!notifiers) {
                goto error_alloc;
        }
index 9d256e2075373c7dbb1de925a2f759129e6742bd..f7d232ffc01aadb346b5fdf6d8c4928ea5163727 100644 (file)
@@ -1436,7 +1436,7 @@ ssize_t kernel_list_events(struct lttng_event **events)
         * See kernel-ctl.h for explanation of this value
         */
        nbmem = KERNEL_EVENT_INIT_LIST_SIZE;
-       elist = (lttng_event *) zmalloc(sizeof(struct lttng_event) * nbmem);
+       elist = calloc<lttng_event>(nbmem);
        if (elist == NULL) {
                PERROR("alloc list events");
                count = -ENOMEM;
index d7f6327ae788cbce1cd536ed45861f66c978da39..a3030bcf47e2d27aa3aea3a97de897ea66a1e594 100644 (file)
@@ -60,7 +60,7 @@ int syscall_init_table(int tracer_fd)
        }
 
        nbmem = SYSCALL_TABLE_INIT_SIZE;
-       syscall_table = (struct syscall *) zmalloc(sizeof(struct syscall) * nbmem);
+       syscall_table = calloc<struct syscall>(nbmem);
        if (!syscall_table) {
                ret = -errno;
                PERROR("syscall list zmalloc");
@@ -245,7 +245,7 @@ static int add_syscall_to_ht(struct lttng_ht *ht, unsigned int index,
 
        LTTNG_ASSERT(ht);
 
-       ksyscall = (struct syscall *) zmalloc(sizeof(*ksyscall));
+       ksyscall = zmalloc<struct syscall>();
        if (!ksyscall) {
                ret = -LTTNG_ERR_NOMEM;
                goto error;
@@ -288,7 +288,7 @@ ssize_t syscall_table_list(struct lttng_event **_events)
         * them might not be valid. The count below will make sure to return the
         * right size of the events array.
         */
-       events = (lttng_event *) zmalloc(syscall_table_nb_entry * sizeof(*events));
+       events = calloc<lttng_event>(syscall_table_nb_entry);
        if (!events) {
                PERROR("syscall table list zmalloc");
                ret = -LTTNG_ERR_NOMEM;
index 4ee3538b2b9e70703edf7f02d2f9a5adf79767b8..93d3b93cc12a0699b724ca7f36966ca7539c4640 100644 (file)
@@ -211,7 +211,7 @@ bool launch_application_management_thread(int apps_cmd_pipe_read_fd)
        struct thread_notifiers *notifiers = NULL;
        struct lttng_thread *thread;
 
-       notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers));
+       notifiers = zmalloc<thread_notifiers>();
        if (!notifiers) {
                goto error_alloc;
        }
index 4a3e3b4ab9ec2adc991be079bee4b72478b5420a..47ce9d16a60b2b7d59c7b1104fa1ea62886947fb 100644 (file)
@@ -193,7 +193,7 @@ static void *thread_consumer_management(void *data)
        consumer_data->metadata_sock.fd_ptr = &consumer_data->metadata_fd;
 
        /* Create metadata socket lock. */
-       consumer_data->metadata_sock.lock = (pthread_mutex_t *) zmalloc(sizeof(pthread_mutex_t));
+       consumer_data->metadata_sock.lock = zmalloc<pthread_mutex_t>();
        if (consumer_data->metadata_sock.lock == NULL) {
                PERROR("zmalloc pthread mutex");
                mark_thread_intialization_as_failed(notifiers);
@@ -437,7 +437,7 @@ bool launch_consumer_management_thread(struct consumer_data *consumer_data)
        struct thread_notifiers *notifiers = NULL;
        struct lttng_thread *thread;
 
-       notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers));
+       notifiers = zmalloc<thread_notifiers>();
        if (!notifiers) {
                goto error_alloc;
        }
index a5d21b0fe52ac10267b154671f55a8eadd4836d5..a6393b6c0832bce45c903446c8de28df4cb4f1b9 100644 (file)
@@ -332,7 +332,7 @@ bool launch_kernel_management_thread(int kernel_poll_pipe_read_fd)
        struct thread_notifiers *notifiers = NULL;
        struct lttng_thread *thread;
 
-       notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers));
+       notifiers = zmalloc<thread_notifiers>();
        if (!notifiers) {
                goto error_alloc;
        }
index 0dc123de156eb23247d8196eb0971493b3a99b1a..90ed3ff14479b43a9dcdbf43ad5440358d311923 100644 (file)
@@ -666,7 +666,7 @@ static int grow_probes(void)
 
        /* Initialize capacity to 1 if 0. */
        if (probes_capacity == 0) {
-               probes = (kern_modules_param *) zmalloc(sizeof(*probes));
+               probes = zmalloc<kern_modules_param>();
                if (!probes) {
                        PERROR("malloc probe list");
                        return -ENOMEM;
@@ -679,7 +679,7 @@ static int grow_probes(void)
        /* Double size. */
        probes_capacity *= 2;
 
-       tmp_probes = (kern_modules_param *) zmalloc(sizeof(*tmp_probes) * probes_capacity);
+       tmp_probes = calloc<kern_modules_param>(probes_capacity);
        if (!tmp_probes) {
                PERROR("malloc probe list");
                return -ENOMEM;
@@ -741,7 +741,7 @@ static int append_list_to_probes(const char *list)
                name_len = strlen(next) + 13;
 
                cur_mod = &probes[nr_probes];
-               cur_mod->name = (char *) zmalloc(name_len);
+               cur_mod->name = calloc<char>(name_len);
                if (!cur_mod->name) {
                        PERROR("malloc probe list");
                        ret = -ENOMEM;
@@ -792,7 +792,7 @@ int modprobe_lttng_data(void)
                /* Default probes. */
                int def_len = ARRAY_SIZE(kern_modules_probes_default);
 
-               probes = (kern_modules_param *) zmalloc(sizeof(*probes) * def_len);
+               probes = calloc<kern_modules_param>(def_len);
                if (!probes) {
                        PERROR("malloc probe list");
                        return -ENOMEM;
index ce499eb1cb3418ac10085f1ac98baa3cf2bf2d56..568580403abc13039afa6f1b50b47457f83ff805 100644 (file)
@@ -59,7 +59,7 @@ struct notification_thread_command *notification_thread_command_copy(
 {
        struct notification_thread_command *new_cmd;
 
-       new_cmd = (notification_thread_command *) zmalloc(sizeof(*new_cmd));
+       new_cmd = zmalloc<notification_thread_command>();
        if (!new_cmd) {
                goto end;
        }
@@ -425,7 +425,7 @@ struct lttng_event_notifier_notification *lttng_event_notifier_notification_crea
        LTTNG_ASSERT(domain != LTTNG_DOMAIN_NONE);
        LTTNG_ASSERT((payload && payload_size) || (!payload && !payload_size));
 
-       notification = (lttng_event_notifier_notification *) zmalloc(sizeof(struct lttng_event_notifier_notification));
+       notification = zmalloc<lttng_event_notifier_notification>();
        if (notification == NULL) {
                ERR("Error allocating notification");
                goto end;
index 67fca2a357bb3fcac0814d150313e49ae38532a2..48ba7a00bccf30da93cfd02b560433da32179239 100644 (file)
@@ -569,7 +569,7 @@ struct session_info *session_info_create(const char *name, uid_t uid, gid_t gid,
 
        LTTNG_ASSERT(name);
 
-       session_info = (struct session_info *) zmalloc(sizeof(*session_info));
+       session_info = zmalloc<struct session_info>();
        if (!session_info) {
                goto end;
        }
@@ -623,7 +623,7 @@ struct channel_info *channel_info_create(const char *channel_name,
                struct channel_key *channel_key, uint64_t channel_capacity,
                struct session_info *session_info)
 {
-       struct channel_info *channel_info = (struct channel_info *) zmalloc(sizeof(*channel_info));
+       struct channel_info *channel_info = zmalloc<struct channel_info>();
 
        if (!channel_info) {
                goto end;
@@ -723,7 +723,7 @@ struct notification_client_list *notification_client_list_create(
        struct cds_lfht_iter iter;
        struct notification_client_list *client_list;
 
-       client_list = (notification_client_list *) zmalloc(sizeof(*client_list));
+       client_list = zmalloc<notification_client_list>();
        if (!client_list) {
                PERROR("Failed to allocate notification client list");
                goto end;
@@ -755,7 +755,7 @@ struct notification_client_list *notification_client_list_create(
                        continue;
                }
 
-               client_list_element = (notification_client_list_element *) zmalloc(sizeof(*client_list_element));
+               client_list_element = zmalloc<notification_client_list_element>();
                if (!client_list_element) {
                        goto error_put_client_list;
                }
@@ -1123,12 +1123,12 @@ int notification_thread_client_subscribe(struct notification_client *client,
                }
        }
 
-       condition_list_element = (lttng_condition_list_element *) zmalloc(sizeof(*condition_list_element));
+       condition_list_element = zmalloc<lttng_condition_list_element>();
        if (!condition_list_element) {
                ret = -1;
                goto error;
        }
-       client_list_element = (notification_client_list_element *) zmalloc(sizeof(*client_list_element));
+       client_list_element = zmalloc<notification_client_list_element>();
        if (!client_list_element) {
                ret = -1;
                goto error;
@@ -1506,7 +1506,7 @@ struct lttng_session_trigger_list *lttng_session_trigger_list_create(
 {
        struct lttng_session_trigger_list *list;
 
-       list = (lttng_session_trigger_list *) zmalloc(sizeof(*list));
+       list = zmalloc<lttng_session_trigger_list>();
        if (!list) {
                goto end;
        }
@@ -1557,7 +1557,7 @@ int lttng_session_trigger_list_add(struct lttng_session_trigger_list *list,
 {
        int ret = 0;
        struct lttng_trigger_list_element *new_element =
-                       (lttng_trigger_list_element *) zmalloc(sizeof(*new_element));
+                       zmalloc<lttng_trigger_list_element>();
 
        if (!new_element) {
                ret = -1;
@@ -1755,7 +1755,7 @@ int handle_notification_thread_command_add_channel(
                        continue;
                }
 
-               new_element = (lttng_trigger_list_element *) zmalloc(sizeof(*new_element));
+               new_element = zmalloc<lttng_trigger_list_element>();
                if (!new_element) {
                        rcu_read_unlock();
                        goto error;
@@ -1769,7 +1769,7 @@ int handle_notification_thread_command_add_channel(
 
        DBG("Found %i triggers that apply to newly added channel",
                        trigger_count);
-       channel_trigger_list = (lttng_channel_trigger_list *) zmalloc(sizeof(*channel_trigger_list));
+       channel_trigger_list = zmalloc<lttng_channel_trigger_list>();
        if (!channel_trigger_list) {
                goto error;
        }
@@ -2032,7 +2032,7 @@ int handle_notification_thread_command_add_tracer_event_source(
        enum lttng_error_code cmd_result = LTTNG_OK;
        struct notification_event_tracer_event_source_element *element = NULL;
 
-       element = (notification_event_tracer_event_source_element *) zmalloc(sizeof(*element));
+       element = zmalloc<notification_event_tracer_event_source_element>();
        if (!element) {
                cmd_result = LTTNG_ERR_NOMEM;
                ret = -1;
@@ -2501,7 +2501,7 @@ int bind_trigger_to_matching_channels(struct lttng_trigger *trigger,
                                struct lttng_channel_trigger_list,
                                channel_triggers_ht_node);
 
-               trigger_list_element = (lttng_trigger_list_element *) zmalloc(sizeof(*trigger_list_element));
+               trigger_list_element = zmalloc<lttng_trigger_list_element>();
                if (!trigger_list_element) {
                        ret = -1;
                        goto end;
@@ -2622,7 +2622,7 @@ enum lttng_error_code setup_tracer_notifier(
        struct lttng_condition *condition = lttng_trigger_get_condition(trigger);
        struct notification_trigger_tokens_ht_element *trigger_tokens_ht_element = NULL;
 
-       trigger_tokens_ht_element = (notification_trigger_tokens_ht_element *) zmalloc(sizeof(*trigger_tokens_ht_element));
+       trigger_tokens_ht_element = zmalloc<notification_trigger_tokens_ht_element>();
        if (!trigger_tokens_ht_element) {
                ret = LTTNG_ERR_NOMEM;
                goto end;
@@ -2745,7 +2745,7 @@ int handle_notification_thread_command_register_trigger(
                goto error;
        }
 
-       trigger_ht_element = (lttng_trigger_ht_element *) zmalloc(sizeof(*trigger_ht_element));
+       trigger_ht_element = zmalloc<lttng_trigger_ht_element>();
        if (!trigger_ht_element) {
                ret = -1;
                goto error;
@@ -3336,7 +3336,7 @@ int handle_notification_thread_client_connect(
 
        DBG("Handling new notification channel client connection");
 
-       client = (notification_client *) zmalloc(sizeof(*client));
+       client = zmalloc<notification_client>();
        if (!client) {
                /* Fatal error. */
                ret = -1;
@@ -4586,7 +4586,7 @@ struct lttng_event_notifier_notification *recv_one_event_notifier_notification(
                goto end;
        }
 
-       capture_buffer = (char *) zmalloc(capture_buffer_size);
+       capture_buffer = calloc<char>(capture_buffer_size);
        if (!capture_buffer) {
                ERR("Failed to allocate capture buffer");
                goto end;
@@ -4889,7 +4889,7 @@ int handle_notification_thread_channel_sample(
                 */
                struct channel_state_sample *stored_sample;
 
-               stored_sample = (channel_state_sample *) zmalloc(sizeof(*stored_sample));
+               stored_sample = zmalloc<channel_state_sample>();
                if (!stored_sample) {
                        ret = -1;
                        goto end_unlock;
index 74e37902db0056d5599fa57dd4da4a72678451ea..cd95e68858f58d68521c29e2d752a15f088430dc 100644 (file)
@@ -94,7 +94,7 @@ struct notification_thread_handle *notification_thread_handle_create(
        struct notification_thread_handle *handle;
        struct lttng_pipe *event_pipe = NULL;
 
-       handle = (notification_thread_handle *) zmalloc(sizeof(*handle));
+       handle = zmalloc<notification_thread_handle>();
        if (!handle) {
                goto end;
        }
@@ -162,7 +162,7 @@ char *get_notification_channel_sock_path(void)
        bool is_root = !getuid();
        char *sock_path;
 
-       sock_path = (char *) zmalloc(LTTNG_PATH_MAX);
+       sock_path = calloc<char>(LTTNG_PATH_MAX);
        if (!sock_path) {
                goto error;
        }
index 8e238e5c15ba4a68a471979fead43753061954b5..80c7fb143f06d0e88768428cd392ad4c602122d6 100644 (file)
@@ -212,7 +212,7 @@ bool launch_application_notification_thread(int apps_cmd_notify_pipe_read_fd)
        struct thread_notifiers *notifiers;
        struct lttng_pipe *quit_pipe;
 
-       notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers));
+       notifiers = zmalloc<thread_notifiers>();
        if (!notifiers) {
                goto error_alloc;
        }
index 36a29d86316586487d90851f37fbf1092c5d44aa..aac16b183cfb3aae0f6b6519e4b946cbf6bfe289 100644 (file)
@@ -265,7 +265,7 @@ static void *thread_application_registration(void *data)
                                        (void) utils_set_fd_cloexec(sock);
 
                                        /* Create UST registration command for enqueuing */
-                                       ust_cmd = (ust_command *) zmalloc(sizeof(struct ust_command));
+                                       ust_cmd = zmalloc<ust_command>();
                                        if (ust_cmd == NULL) {
                                                PERROR("ust command zmalloc");
                                                ret = close(sock);
@@ -392,7 +392,7 @@ struct lttng_thread *launch_application_registration_thread(
        const bool is_root = (getuid() == 0);
        int application_socket = -1;
 
-       thread_state = (struct thread_state *) zmalloc(sizeof(*thread_state));
+       thread_state = zmalloc<struct thread_state>();
        if (!thread_state) {
                goto error_alloc;
        }
index 2f89fbc64ee875f8e94f5efc78b34e6a57648575..ee924ba98f042ee83a7f80f5d0737c95630d867a 100644 (file)
@@ -89,7 +89,7 @@ struct rotation_thread_timer_queue *rotation_thread_timer_queue_create(void)
 {
        struct rotation_thread_timer_queue *queue = NULL;
 
-       queue = (rotation_thread_timer_queue *) zmalloc(sizeof(*queue));
+       queue = zmalloc<rotation_thread_timer_queue>();
        if (!queue) {
                PERROR("Failed to allocate timer rotate queue");
                goto end;
@@ -134,7 +134,7 @@ struct rotation_thread_handle *rotation_thread_handle_create(
 {
        struct rotation_thread_handle *handle;
 
-       handle = (rotation_thread_handle *) zmalloc(sizeof(*handle));
+       handle = zmalloc<rotation_thread_handle>();
        if (!handle) {
                goto end;
        }
@@ -193,7 +193,7 @@ void rotation_thread_enqueue_job(struct rotation_thread_timer_queue *queue,
                goto end;
        }
 
-       job = (rotation_thread_job *) zmalloc(sizeof(struct rotation_thread_job));
+       job = zmalloc<rotation_thread_job>();
        if (!job) {
                PERROR("Failed to allocate rotation thread job of type \"%s\" for session \"%s\"",
                                job_type_str, session->name);
index 16b2705149e9fd59ce1ffedfa63ae8b32fa1922b..757b97226a1bb5be53eb2650add9f204fd13a1be 100644 (file)
@@ -2322,7 +2322,7 @@ int save_consumer_output(struct config_writer *writer,
        {
                char *uri;
 
-               uri = (char *) zmalloc(PATH_MAX);
+               uri = calloc<char>(PATH_MAX);
                if (!uri) {
                        ret = LTTNG_ERR_NOMEM;
                        goto end;
index bcab0147d70fbd7ee05c503a33fdeb5f2326c100..fc43684e9b2b2a4035b4837ccae9fcd73f0c0344 100644 (file)
@@ -1187,7 +1187,7 @@ enum lttng_error_code session_create(const char *name, uid_t uid, gid_t gid,
                        goto error;
                }
        }
-       new_session = (ltt_session *) zmalloc(sizeof(struct ltt_session));
+       new_session = zmalloc<ltt_session>();
        if (!new_session) {
                PERROR("Failed to allocate an ltt_session structure");
                ret_code = LTTNG_ERR_NOMEM;
index f7821da95da978ac54f1111d7622a4080e8b31ca..1601f17ccc2f0918f1bb81b0c6cc0fe00796ca23 100644 (file)
@@ -165,7 +165,7 @@ error:
 
 struct snapshot_output *snapshot_output_alloc(void)
 {
-       return (snapshot_output *) zmalloc(sizeof(struct snapshot_output));
+       return zmalloc<snapshot_output>();
 }
 
 /*
index 9ce539b816a99732cf0a6c3ed5c3901584e8e44a..94890e6ef47786db7d13fce3fac6f9e372fe878a 100644 (file)
@@ -77,7 +77,7 @@ struct lttng_thread *lttng_thread_create(const char *name,
        int ret;
        struct lttng_thread *thread;
 
-       thread = (lttng_thread *) zmalloc(sizeof(*thread));
+       thread = zmalloc<lttng_thread>();
        if (!thread) {
                goto error_alloc;
        }
index 8466304829cb9109f94755ec4e0a6a138384b7ef..23d808ce8852f155e82bcbf7dc6cd65f41f48703 100644 (file)
@@ -151,7 +151,7 @@ struct ltt_kernel_session *trace_kernel_create_session(void)
        struct ltt_kernel_session *lks = NULL;
 
        /* Allocate a new ltt kernel session */
-       lks = (ltt_kernel_session *) zmalloc(sizeof(struct ltt_kernel_session));
+       lks = zmalloc<ltt_kernel_session>();
        if (lks == NULL) {
                PERROR("create kernel session zmalloc");
                goto alloc_error;
@@ -222,19 +222,19 @@ struct ltt_kernel_channel *trace_kernel_create_channel(
 
        LTTNG_ASSERT(chan);
 
-       lkc = (ltt_kernel_channel *) zmalloc(sizeof(struct ltt_kernel_channel));
+       lkc = zmalloc<ltt_kernel_channel>();
        if (lkc == NULL) {
                PERROR("ltt_kernel_channel zmalloc");
                goto error;
        }
 
-       lkc->channel = (lttng_channel *) zmalloc(sizeof(struct lttng_channel));
+       lkc->channel = zmalloc<lttng_channel>();
        if (lkc->channel == NULL) {
                PERROR("lttng_channel zmalloc");
                goto error;
        }
 
-       extended = (lttng_channel_extended *) zmalloc(sizeof(struct lttng_channel_extended));
+       extended = zmalloc<lttng_channel_extended>();
        if (!extended) {
                PERROR("lttng_channel_channel zmalloc");
                goto error;
@@ -285,7 +285,7 @@ struct ltt_kernel_context *trace_kernel_create_context(
 {
        struct ltt_kernel_context *kctx;
 
-       kctx = (ltt_kernel_context *) zmalloc(sizeof(*kctx));
+       kctx = zmalloc<ltt_kernel_context>();
        if (!kctx) {
                PERROR("zmalloc kernel context");
                goto error;
@@ -310,7 +310,7 @@ struct ltt_kernel_context *trace_kernel_copy_context(
        struct ltt_kernel_context *kctx_copy;
 
        LTTNG_ASSERT(kctx);
-       kctx_copy = (ltt_kernel_context *) zmalloc(sizeof(*kctx_copy));
+       kctx_copy = zmalloc<ltt_kernel_context>();
        if (!kctx_copy) {
                PERROR("zmalloc ltt_kernel_context");
                goto error;
@@ -341,8 +341,8 @@ enum lttng_error_code trace_kernel_create_event(
 
        LTTNG_ASSERT(ev);
 
-       local_kernel_event = (ltt_kernel_event *) zmalloc(sizeof(struct ltt_kernel_event));
-       attr = (lttng_kernel_abi_event *) zmalloc(sizeof(struct lttng_kernel_abi_event));
+       local_kernel_event = zmalloc<ltt_kernel_event>();
+       attr = zmalloc<lttng_kernel_abi_event>();
        if (local_kernel_event == NULL || attr == NULL) {
                PERROR("kernel event zmalloc");
                ret = LTTNG_ERR_NOMEM;
@@ -514,7 +514,7 @@ enum lttng_error_code trace_kernel_create_event_notifier_rule(
        LTTNG_ASSERT(event_rule_type != LTTNG_EVENT_RULE_TYPE_UNKNOWN);
 
        local_kernel_token_event_rule =
-                       (ltt_kernel_event_notifier_rule *) zmalloc(sizeof(struct ltt_kernel_event_notifier_rule));
+                       zmalloc<ltt_kernel_event_notifier_rule>();
        if (local_kernel_token_event_rule == NULL) {
                PERROR("Failed to allocate ltt_kernel_token_event_rule structure");
                ret = LTTNG_ERR_NOMEM;
@@ -735,8 +735,8 @@ struct ltt_kernel_metadata *trace_kernel_create_metadata(void)
        struct ltt_kernel_metadata *lkm;
        struct lttng_channel *chan;
 
-       lkm = (ltt_kernel_metadata *) zmalloc(sizeof(struct ltt_kernel_metadata));
-       chan = (lttng_channel *) zmalloc(sizeof(struct lttng_channel));
+       lkm = zmalloc<ltt_kernel_metadata>();
+       chan = zmalloc<lttng_channel>();
        if (lkm == NULL || chan == NULL) {
                PERROR("kernel metadata zmalloc");
                goto error;
@@ -801,7 +801,7 @@ struct ltt_kernel_stream *trace_kernel_create_stream(const char *name,
 
        LTTNG_ASSERT(name);
 
-       lks = (ltt_kernel_stream *) zmalloc(sizeof(struct ltt_kernel_stream));
+       lks = zmalloc<ltt_kernel_stream>();
        if (lks == NULL) {
                PERROR("kernel stream zmalloc");
                goto error;
index 285ff0811f3a9f5be3573cad48893d9985ad244d..de368a3baa054a25616f342017b0d1fdc3ecf1f4 100644 (file)
@@ -271,7 +271,7 @@ struct ltt_ust_session *trace_ust_create_session(uint64_t session_id)
        struct ltt_ust_session *lus;
 
        /* Allocate a new ltt ust session */
-       lus = (ltt_ust_session *) zmalloc(sizeof(struct ltt_ust_session));
+       lus = zmalloc<ltt_ust_session>();
        if (lus == NULL) {
                PERROR("create ust session zmalloc");
                goto error_alloc;
@@ -350,7 +350,7 @@ struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan,
 
        LTTNG_ASSERT(chan);
 
-       luc = (ltt_ust_channel *) zmalloc(sizeof(struct ltt_ust_channel));
+       luc = zmalloc<ltt_ust_channel>();
        if (luc == NULL) {
                PERROR("ltt_ust_channel zmalloc");
                goto error;
@@ -463,7 +463,7 @@ enum lttng_error_code trace_ust_create_event(struct lttng_event *ev,
                goto error;
        }
 
-       local_ust_event = (ltt_ust_event *) zmalloc(sizeof(struct ltt_ust_event));
+       local_ust_event = zmalloc<ltt_ust_event>();
        if (local_ust_event == NULL) {
                PERROR("ust event zmalloc");
                ret = LTTNG_ERR_NOMEM;
@@ -687,7 +687,7 @@ struct ltt_ust_context *trace_ust_create_context(
                goto end;
        }
 
-       uctx = (ltt_ust_context *) zmalloc(sizeof(struct ltt_ust_context));
+       uctx = zmalloc<ltt_ust_context>();
        if (!uctx) {
                PERROR("zmalloc ltt_ust_context");
                goto end;
@@ -813,7 +813,7 @@ static int id_tracker_add_id(struct ust_id_tracker *id_tracker, int id)
                retval = LTTNG_ERR_PROCESS_ATTR_EXISTS;
                goto end;
        }
-       tracker_node = (ust_id_tracker_node *) zmalloc(sizeof(*tracker_node));
+       tracker_node = zmalloc<ust_id_tracker_node>();
        if (!tracker_node) {
                retval = LTTNG_ERR_NOMEM;
                goto end;
index 204ade426316b288afd6e59d1ceade61f82a706f..7d587280645b0ebe72381075038994a15f17d605 100644 (file)
@@ -49,7 +49,7 @@ struct process_attr_tracker *process_attr_tracker_create(void)
 {
        struct process_attr_tracker *tracker;
 
-       tracker = (process_attr_tracker *) zmalloc(sizeof(*tracker));
+       tracker = zmalloc<process_attr_tracker>();
        if (!tracker) {
                return NULL;
        }
@@ -201,7 +201,7 @@ enum process_attr_tracker_status process_attr_tracker_inclusion_set_add_value(
                goto end;
        }
 
-       value_node = (process_attr_tracker_value_node *) zmalloc(sizeof(*value_node));
+       value_node = zmalloc<process_attr_tracker_value_node>();
        if (!value_node) {
                status = PROCESS_ATTR_TRACKER_STATUS_ERROR;
                goto end;
index 5cffdc9741012ec6cdc562ff56c2a11c8f75c8fa..fcc4267ad5ea8360ae6e139bada338f6f1dff83e 100644 (file)
@@ -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 {
@@ -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
index 0b92d19c52b3aa459cd22110d7230c753394e1d5..b327fdf32c449dfc082af8a55eebd9dd8b99c145 100644 (file)
@@ -288,7 +288,7 @@ static struct ust_registry_event *alloc_event(int session_objd,
                return NULL;
        }
 
-       event = (ust_registry_event *) zmalloc(sizeof(*event));
+       event = zmalloc<ust_registry_event>();
        if (!event) {
                PERROR("zmalloc ust registry event");
                goto error;
@@ -630,7 +630,7 @@ int ust_registry_create_or_find_enum(struct ust_registry_session *session,
        }
 
        /* Check if the enumeration was already dumped */
-       reg_enum = (ust_registry_enum *) zmalloc(sizeof(*reg_enum));
+       reg_enum = zmalloc<ust_registry_enum>();
        if (!reg_enum) {
                PERROR("zmalloc ust registry enumeration");
                ret = -ENOMEM;
@@ -756,7 +756,7 @@ int ust_registry_channel_add(struct ust_registry_session *session,
 
        LTTNG_ASSERT(session);
 
-       chan = (ust_registry_channel *) zmalloc(sizeof(*chan));
+       chan = zmalloc<ust_registry_channel>();
        if (!chan) {
                PERROR("zmalloc ust registry channel");
                ret = -ENOMEM;
@@ -887,7 +887,7 @@ int ust_registry_session_init(struct ust_registry_session **sessionp,
 
        LTTNG_ASSERT(sessionp);
 
-       session = (ust_registry_session *) zmalloc(sizeof(*session));
+       session = zmalloc<ust_registry_session>();
        if (!session) {
                PERROR("zmalloc ust registry session");
                goto error_alloc;
index 27d932c340ab8622225df5badd8ca1d99e5b3cce..b25d2d10a3aced9b771a8094bac5e12cf3bee335 100644 (file)
@@ -902,21 +902,21 @@ void destroy_ctx_type(struct ctx_type *type)
        if (type->opt) {
                free(type->opt->symbol);
        }
-       free(type->opt);
+       delete type->opt;
        free(type);
 }
 
 static
 struct ctx_type *create_ctx_type(void)
 {
-       struct ctx_type *type = (ctx_type *) zmalloc(sizeof(*type));
+       struct ctx_type *type = zmalloc<ctx_type>();
 
        if (!type) {
                PERROR("malloc ctx_type");
                goto end;
        }
 
-       type->opt = (struct ctx_opts *) zmalloc(sizeof(*type->opt));
+       type->opt = new struct ctx_opts;
        if (!type->opt) {
                PERROR("malloc ctx_type options");
                destroy_ctx_type(type);
@@ -1091,7 +1091,7 @@ struct ctx_type *get_context_type(const char *ctx)
        }
 
        provider_name_len = colon_pos - sizeof(app_ctx_prefix) + 2;
-       provider_name = (char *) zmalloc(provider_name_len);
+       provider_name = calloc<char>(provider_name_len);
        if (!provider_name) {
                PERROR("malloc provider_name");
                goto not_found;
@@ -1101,7 +1101,7 @@ struct ctx_type *get_context_type(const char *ctx)
        type->opt->u.app_ctx.provider_name = provider_name;
 
        ctx_name_len = len - colon_pos;
-       ctx_name = (char *) zmalloc(ctx_name_len);
+       ctx_name = calloc<char>(ctx_name_len);
        if (!ctx_name) {
                PERROR("malloc ctx_name");
                goto not_found;
index 9d9a28ab86486cdd1c1bcb9b9e113094a5101f64..1d81143ae562bd6589ad09b8c1e07b0dc59b6575 100644 (file)
@@ -254,7 +254,7 @@ char *print_exclusions(const struct lttng_dynamic_pointer_array *exclusions)
        }
 
        length += sizeof(preamble);
-       ret = (char *) zmalloc(length);
+       ret = calloc<char>(length);
        if (!ret) {
                return NULL;
        }
index 444a96b40a5e4957177109777196360c7ce9adf7..8636cd101850d5557e489e2671add4ede354e4cc 100644 (file)
@@ -91,11 +91,12 @@ static char *get_cmdline_by_pid(pid_t pid)
        }
 
        /* Caller must free() *cmdline */
-       cmdline = (char *) zmalloc(PATH_MAX);
+       cmdline = zmalloc<char>(PATH_MAX);
        if (!cmdline) {
                PERROR("malloc cmdline");
                goto end;
        }
+
        ret = fread(cmdline, 1, PATH_MAX, fp);
        if (ret < 0) {
                PERROR("fread proc list");
index d79fba989f1368bc75cfcb2575f8b459b232b7cb..33550eb3778fe5fb636c0700618b153804f84057 100644 (file)
@@ -178,7 +178,7 @@ int _config_read_session_name(const char *path, char **name)
 #define NAME_MAX_SCANF_IS_A_BROKEN_API "254"
 #endif
 
-       session_name = (char *) zmalloc(NAME_MAX);
+       session_name = calloc<char>(NAME_MAX);
        if (session_name == NULL) {
                ret = -ENOMEM;
                ERR("Out of memory");
index 07ac5d5fa5ab6d9d30fadf31f8492455f9f689b8..c6a2d9429090f3ce2141f0fbdd66ecc51272ff75 100644 (file)
@@ -58,7 +58,7 @@ int walk_command_search_path(const char *binary, char *binary_full_path)
         * This char array is used to concatenate path to binary to look for
         * the binary.
         */
-       tentative_binary_path = (char *) zmalloc(LTTNG_PATH_MAX * sizeof(char));
+       tentative_binary_path = calloc<char>(LTTNG_PATH_MAX);
        if (!tentative_binary_path) {
                ret = -1;
                goto alloc_error;
@@ -292,7 +292,7 @@ int parse_userspace_probe_opts(const char *opt,
         */
        if (strchr(unescaped_target_path, '/') == NULL) {
                /* Walk the $PATH variable to find the targeted binary. */
-               real_target_path = (char *) zmalloc(LTTNG_PATH_MAX * sizeof(char));
+               real_target_path = calloc<char>(LTTNG_PATH_MAX);
                if (!real_target_path) {
                        PERROR("Error allocating path buffer");
                        ret = CMD_ERROR;
index c80832570d2dab694a4e77c61a33adffc84cdd26..e524399adf499b7ebf57833bf53e7183acdbcb06 100644 (file)
@@ -362,7 +362,7 @@ struct lttng_action *lttng_action_list_create(void)
        struct lttng_action_list *action_list;
        struct lttng_action *action;
 
-       action_list = (lttng_action_list *) zmalloc(sizeof(struct lttng_action_list));
+       action_list = zmalloc<lttng_action_list>();
        if (!action_list) {
                action = NULL;
                goto end;
index 8ee51c31617a6370b776a5415230056bfa9f2901..ff117321e0b73d7e0e0b7e30fc6b865cd7085660 100644 (file)
@@ -132,7 +132,7 @@ struct lttng_action *lttng_action_notify_create(void)
        struct lttng_action_notify *notify = NULL;
        struct lttng_action *action = NULL;
 
-       notify = (lttng_action_notify *) zmalloc(sizeof(struct lttng_action_notify));
+       notify = zmalloc<lttng_action_notify>();
        if (!notify) {
                goto end;
        }
index 0c8181896dfc612614baebf3775d5a37c250c2e7..cbb7519b13f5a21d907f993755785b6d6dfeaa4f 100644 (file)
@@ -23,7 +23,7 @@ struct lttng_action_path *lttng_action_path_create(
                goto error;
        }
 
-       path = (lttng_action_path *) zmalloc(sizeof(*path));
+       path = zmalloc<lttng_action_path>();
        if (!path) {
                goto error;
        }
index 58db624d8312814bff23b1fec56e78ee4d5c698a..25f8e4083387b11a53f0a74e92c4b6bcb4290306 100644 (file)
@@ -487,7 +487,7 @@ struct lttng_rate_policy *lttng_rate_policy_every_n_create(uint64_t interval)
                goto end;
        }
 
-       policy = (lttng_rate_policy_every_n *) zmalloc(sizeof(struct lttng_rate_policy_every_n));
+       policy = zmalloc<lttng_rate_policy_every_n>();
        if (!policy) {
                goto end;
        }
@@ -702,7 +702,7 @@ struct lttng_rate_policy *lttng_rate_policy_once_after_n_create(
                goto end;
        }
 
-       policy = (lttng_rate_policy_once_after_n *) zmalloc(sizeof(struct lttng_rate_policy_once_after_n));
+       policy = zmalloc<lttng_rate_policy_once_after_n>();
        if (!policy) {
                goto end;
        }
index ad2f9e2938c1d7bc228adce90cb7d8800e90bdfe..a8e882b4faa4e175ca113ebb3821e7db441d0784 100644 (file)
@@ -288,7 +288,7 @@ end:
 
 struct lttng_action *lttng_action_rotate_session_create(void)
 {
-       struct lttng_action *action = NULL;
+       struct lttng_action_rotate_session *action_rotate = NULL;
        struct lttng_rate_policy *policy = NULL;
        enum lttng_action_status status;
 
@@ -298,12 +298,13 @@ struct lttng_action *lttng_action_rotate_session_create(void)
                goto end;
        }
 
-       action = (lttng_action *) zmalloc(sizeof(struct lttng_action_rotate_session));
-       if (!action) {
+       action_rotate = zmalloc<lttng_action_rotate_session>();
+       if (!action_rotate) {
                goto end;
        }
 
-       lttng_action_init(action, LTTNG_ACTION_TYPE_ROTATE_SESSION,
+       lttng_action_init(&action_rotate->parent,
+                       LTTNG_ACTION_TYPE_ROTATE_SESSION,
                        lttng_action_rotate_session_validate,
                        lttng_action_rotate_session_serialize,
                        lttng_action_rotate_session_is_equal,
@@ -312,16 +313,17 @@ struct lttng_action *lttng_action_rotate_session_create(void)
                        lttng_action_generic_add_error_query_results,
                        lttng_action_rotate_session_mi_serialize);
 
-       status = lttng_action_rotate_session_set_rate_policy(action, policy);
+       status = lttng_action_rotate_session_set_rate_policy(
+                       &action_rotate->parent, policy);
        if (status != LTTNG_ACTION_STATUS_OK) {
-               free(action);
-               action = NULL;
+               lttng_action_destroy(&action_rotate->parent);
+               action_rotate = NULL;
                goto end;
        }
 
 end:
        lttng_rate_policy_destroy(policy);
-       return action;
+       return action_rotate ? &action_rotate->parent : nullptr;
 }
 
 enum lttng_action_status lttng_action_rotate_session_set_session_name(
index 600d803e3610b1d065a23cbe82e7fc79e2151596..c3570081abcdf2248137fdd8c631403a3c45c0bf 100644 (file)
@@ -445,7 +445,7 @@ end:
 
 struct lttng_action *lttng_action_snapshot_session_create(void)
 {
-       struct lttng_action *action = NULL;
+       struct lttng_action_snapshot_session *action_snapshot = NULL;
        struct lttng_rate_policy *policy = NULL;
        enum lttng_action_status status;
 
@@ -455,12 +455,13 @@ struct lttng_action *lttng_action_snapshot_session_create(void)
                goto end;
        }
 
-       action = (lttng_action *) zmalloc(sizeof(struct lttng_action_snapshot_session));
-       if (!action) {
+       action_snapshot = zmalloc<lttng_action_snapshot_session>();
+       if (!action_snapshot) {
                goto end;
        }
 
-       lttng_action_init(action, LTTNG_ACTION_TYPE_SNAPSHOT_SESSION,
+       lttng_action_init(&action_snapshot->parent,
+                       LTTNG_ACTION_TYPE_SNAPSHOT_SESSION,
                        lttng_action_snapshot_session_validate,
                        lttng_action_snapshot_session_serialize,
                        lttng_action_snapshot_session_is_equal,
@@ -469,16 +470,17 @@ struct lttng_action *lttng_action_snapshot_session_create(void)
                        lttng_action_generic_add_error_query_results,
                        lttng_action_snapshot_session_mi_serialize);
 
-       status = lttng_action_snapshot_session_set_rate_policy(action, policy);
+       status = lttng_action_snapshot_session_set_rate_policy(
+                       &action_snapshot->parent, policy);
        if (status != LTTNG_ACTION_STATUS_OK) {
-               free(action);
-               action = NULL;
+               lttng_action_destroy(&action_snapshot->parent);
+               action_snapshot = NULL;
                goto end;
        }
 
 end:
        lttng_rate_policy_destroy(policy);
-       return action;
+       return action_snapshot ? &action_snapshot->parent : nullptr;
 }
 
 enum lttng_action_status lttng_action_snapshot_session_set_session_name(
index 739540189e24dbb3882345007b6579103e572552..f9138f51a56f8b20fd2aee980ea800d779b0e758 100644 (file)
@@ -291,7 +291,7 @@ end:
 
 struct lttng_action *lttng_action_start_session_create(void)
 {
-       struct lttng_action *action = NULL;
+       struct lttng_action_start_session *action_start = NULL;
        struct lttng_rate_policy *policy = NULL;
        enum lttng_action_status status;
 
@@ -301,12 +301,13 @@ struct lttng_action *lttng_action_start_session_create(void)
                goto end;
        }
 
-       action = (lttng_action *) zmalloc(sizeof(struct lttng_action_start_session));
-       if (!action) {
+       action_start = zmalloc<lttng_action_start_session>();
+       if (!action_start) {
                goto end;
        }
 
-       lttng_action_init(action, LTTNG_ACTION_TYPE_START_SESSION,
+       lttng_action_init(&action_start->parent,
+                       LTTNG_ACTION_TYPE_START_SESSION,
                        lttng_action_start_session_validate,
                        lttng_action_start_session_serialize,
                        lttng_action_start_session_is_equal,
@@ -315,16 +316,17 @@ struct lttng_action *lttng_action_start_session_create(void)
                        lttng_action_generic_add_error_query_results,
                        lttng_action_start_session_mi_serialize);
 
-       status = lttng_action_start_session_set_rate_policy(action, policy);
+       status = lttng_action_start_session_set_rate_policy(
+                       &action_start->parent, policy);
        if (status != LTTNG_ACTION_STATUS_OK) {
-               free(action);
-               action = NULL;
+               lttng_action_destroy(&action_start->parent);
+               action_start = NULL;
                goto end;
        }
 
 end:
        lttng_rate_policy_destroy(policy);
-       return action;
+       return &action_start->parent;
 }
 
 enum lttng_action_status lttng_action_start_session_set_session_name(
index 3cffb4a553b8a774684b0a438856273544609052..75ff1b84755b5ec682d712093d4990f082f472c0 100644 (file)
@@ -291,7 +291,7 @@ end:
 
 struct lttng_action *lttng_action_stop_session_create(void)
 {
-       struct lttng_action *action = NULL;
+       struct lttng_action_stop_session *action_stop = NULL;
        struct lttng_rate_policy *policy = NULL;
        enum lttng_action_status status;
 
@@ -301,12 +301,12 @@ struct lttng_action *lttng_action_stop_session_create(void)
                goto end;
        }
 
-       action = (lttng_action *) zmalloc(sizeof(struct lttng_action_stop_session));
-       if (!action) {
+       action_stop = zmalloc<lttng_action_stop_session>();
+       if (!action_stop) {
                goto end;
        }
 
-       lttng_action_init(action, LTTNG_ACTION_TYPE_STOP_SESSION,
+       lttng_action_init(&action_stop->parent, LTTNG_ACTION_TYPE_STOP_SESSION,
                        lttng_action_stop_session_validate,
                        lttng_action_stop_session_serialize,
                        lttng_action_stop_session_is_equal,
@@ -315,16 +315,17 @@ struct lttng_action *lttng_action_stop_session_create(void)
                        lttng_action_generic_add_error_query_results,
                        lttng_action_stop_session_mi_serialize);
 
-       status = lttng_action_stop_session_set_rate_policy(action, policy);
+       status = lttng_action_stop_session_set_rate_policy(
+                       &action_stop->parent, policy);
        if (status != LTTNG_ACTION_STATUS_OK) {
-               free(action);
-               action = NULL;
+               lttng_action_destroy(&action_stop->parent);
+               action_stop = NULL;
                goto end;
        }
 
 end:
        lttng_rate_policy_destroy(policy);
-       return action;
+       return &action_stop->parent;
 }
 
 enum lttng_action_status lttng_action_stop_session_set_session_name(
index ea773450748c9bc63a5abd3032cfa95857d299c6..b77609edd5b53f35ea08da0b9e8f38c052c97d88 100644 (file)
@@ -8,16 +8,16 @@
 #ifndef COMMON_ARGPAR_UTILS_H
 #define COMMON_ARGPAR_UTILS_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #include <stdarg.h>
 
 #include <common/macros.hpp>
 #include <common/argpar/argpar.h>
 #include <common/string-utils/format.hpp>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define WHILE_PARSING_ARG_N_ARG_FMT "While parsing argument #%d (`%s`): "
 
 enum parse_next_item_status
index 707394229e947cad92d4dfa0a542d62762ceaa71..c32f3900b8d4332d32e0a9eb5b771dc40b82fe85 100644 (file)
@@ -251,9 +251,8 @@ end:
 struct lttng_bytecode *lttng_bytecode_copy(
                const struct lttng_bytecode *orig_f)
 {
-       struct lttng_bytecode *bytecode = NULL;
-
-       bytecode = (lttng_bytecode *) zmalloc(sizeof(*bytecode) + orig_f->len);
+       lttng_bytecode *bytecode
+               = zmalloc<lttng_bytecode>(sizeof(*bytecode) + orig_f->len);
        if (!bytecode) {
                goto error;
        }
index be3b62343ec447bdb45b619a79452e55e0796772..5bef795589d75c4349cdf05fe31b65a77369698f 100644 (file)
@@ -37,7 +37,7 @@ struct lttng_channel *lttng_channel_copy(const struct lttng_channel *src)
        struct lttng_channel_extended *extended = nullptr;
        struct lttng_channel *channel = nullptr, *ret = nullptr;
 
-       channel = (struct lttng_channel *) zmalloc(sizeof(*channel));
+       channel = zmalloc<lttng_channel>();
        if (!channel) {
                goto end;
        }
@@ -45,8 +45,7 @@ struct lttng_channel *lttng_channel_copy(const struct lttng_channel *src)
        *channel = *src;
 
        if (src->attr.extended.ptr) {
-               extended = (struct lttng_channel_extended *) zmalloc(
-                               sizeof(*extended));
+               extended = zmalloc<lttng_channel_extended>();
                if (!extended) {
                        goto end;
                }
@@ -71,15 +70,13 @@ struct lttng_channel *lttng_channel_create_internal(void)
        struct lttng_channel *local_channel = nullptr, *ret = nullptr;
        struct lttng_channel_extended *extended = nullptr;
 
-       local_channel = (struct lttng_channel *) zmalloc(
-                       sizeof(struct lttng_channel));
+       local_channel = zmalloc<lttng_channel>();
        if (!local_channel) {
                goto end;
        }
 
        /* Extended struct */
-       extended = (struct lttng_channel_extended *) zmalloc(
-                       sizeof(*extended));
+       extended = zmalloc<lttng_channel_extended>();
        if (!extended) {
                goto end;
        }
index ba5c6925c49feb3667f61e60ea0450507e19fe71..5c8d28db9de6db30e95589cfa074edb76784961c 100644 (file)
@@ -147,7 +147,7 @@ struct lttng_directory_handle *lttng_directory_handle_create_from_dirfd(
                int dirfd)
 {
        int ret;
-       struct lttng_directory_handle *handle = (lttng_directory_handle *) zmalloc(sizeof(*handle));
+       struct lttng_directory_handle *handle = zmalloc<lttng_directory_handle>();
        struct stat stat_buf;
 
        if (!handle) {
@@ -405,7 +405,7 @@ end:
 static
 struct lttng_directory_handle *_lttng_directory_handle_create(char *path)
 {
-       struct lttng_directory_handle *handle = zmalloc(sizeof(*handle));
+       struct lttng_directory_handle *handle = zmalloc<lttng_directory_handle>();
 
        if (!handle) {
                goto end;
@@ -525,7 +525,7 @@ struct lttng_directory_handle *lttng_directory_handle_create_from_handle(
                                handle_path_len, LTTNG_PATH_MAX);
                goto end;
        }
-       new_path = zmalloc(handle_path_len);
+       new_path = zmalloc<char>(handle_path_len);
        if (!new_path) {
                PERROR("Failed to initialize directory handle");
                goto end;
index 4f532a26d66715adc77cafce1ba30481112449b8..0617905a6ee65e37656956b650a41838cb9e1393 100644 (file)
@@ -71,11 +71,11 @@ error:
 /*
  * Create epoll set and allocate returned events structure.
  */
-int compat_epoll_create(struct lttng_poll_event *events, int size, int flags)
+int compat_epoll_create(struct lttng_poll_event *events, int count, int flags)
 {
        int ret;
 
-       if (events == NULL || size <= 0) {
+       if (events == NULL || count <= 0) {
                goto error;
        }
 
@@ -86,11 +86,11 @@ int compat_epoll_create(struct lttng_poll_event *events, int size, int flags)
        }
 
        /* Don't bust the limit here */
-       if (size > poll_max_size) {
-               size = poll_max_size;
+       if (count > poll_max_size) {
+               count = poll_max_size;
        }
 
-       ret = compat_glibc_epoll_create(size, flags);
+       ret = compat_glibc_epoll_create(count, flags);
        if (ret < 0) {
                /* At this point, every error is fatal */
                PERROR("epoll_create1");
@@ -100,13 +100,13 @@ int compat_epoll_create(struct lttng_poll_event *events, int size, int flags)
        events->epfd = ret;
 
        /* This *must* be freed by using lttng_poll_free() */
-       events->events = (epoll_event *) zmalloc(size * sizeof(struct epoll_event));
+       events->events = calloc<epoll_event>(count);
        if (events->events == NULL) {
                PERROR("zmalloc epoll set");
                goto error_close;
        }
 
-       events->alloc_size = events->init_size = size;
+       events->alloc_size = events->init_size = count;
        events->nb_fd = 0;
 
        return 0;
index 4a96cb1456ffd2a928d18439007cfc3959b2b5e5..526f2b2ced3b200ecfa696083baa9fadc72408eb 100644 (file)
@@ -61,7 +61,7 @@ char *lttng_strndup(const char *s, size_t n)
                navail = n + 1;
        }
 
-       ret = (char *) malloc(navail);
+       ret = malloc<char>(navail);
        if (!ret) {
                goto end;
        }
index b1d001dc4ae599332546a61eab3940a13a58ad4a..57e1c79cbd43bfb21b9e2b46e3ad850678a94fff 100644 (file)
@@ -321,7 +321,7 @@ struct lttng_condition *lttng_condition_buffer_usage_create(
 {
        struct lttng_condition_buffer_usage *condition;
 
-       condition = (lttng_condition_buffer_usage *) zmalloc(sizeof(struct lttng_condition_buffer_usage));
+       condition = zmalloc<lttng_condition_buffer_usage>();
        if (!condition) {
                return NULL;
        }
@@ -864,7 +864,7 @@ struct lttng_evaluation *lttng_evaluation_buffer_usage_create(
 {
        struct lttng_evaluation_buffer_usage *usage;
 
-       usage = (lttng_evaluation_buffer_usage *) zmalloc(sizeof(struct lttng_evaluation_buffer_usage));
+       usage = zmalloc<lttng_evaluation_buffer_usage>();
        if (!usage) {
                goto end;
        }
index 033dbca48a040b46131d7b9b5615e6f06e7e946f..0a926755ecee1eef537805e89604ed8810c38f08 100644 (file)
@@ -518,7 +518,7 @@ struct lttng_condition *lttng_condition_event_rule_matches_create(
                goto end;
        }
 
-       condition = (lttng_condition_event_rule_matches *) zmalloc(sizeof(struct lttng_condition_event_rule_matches));
+       condition = zmalloc<lttng_condition_event_rule_matches>();
        if (!condition) {
                return NULL;
        }
@@ -889,7 +889,7 @@ lttng_condition_event_rule_matches_append_capture_descriptor(
                goto end;
        }
 
-       descriptor = (lttng_capture_descriptor *) malloc(sizeof(*descriptor));
+       descriptor = malloc<lttng_capture_descriptor>();
        if (descriptor == NULL) {
                status = LTTNG_CONDITION_STATUS_ERROR;
                goto end;
@@ -1385,7 +1385,7 @@ struct lttng_evaluation *lttng_evaluation_event_rule_matches_create(
        struct lttng_evaluation_event_rule_matches *hit;
        struct lttng_evaluation *evaluation = NULL;
 
-       hit = (lttng_evaluation_event_rule_matches *) zmalloc(sizeof(struct lttng_evaluation_event_rule_matches));
+       hit = zmalloc<lttng_evaluation_event_rule_matches>();
        if (!hit) {
                goto error;
        }
index 8bc70abf61fab875ff67f87944dac9de7895b62e..abb5db8cef17dca10caaf208b49cfb9034189897 100644 (file)
@@ -203,7 +203,7 @@ struct lttng_condition *lttng_condition_session_consumed_size_create(void)
 {
        struct lttng_condition_session_consumed_size *condition;
 
-       condition = (lttng_condition_session_consumed_size *) zmalloc(sizeof(struct lttng_condition_session_consumed_size));
+       condition = zmalloc<lttng_condition_session_consumed_size>();
        if (!condition) {
                return NULL;
        }
@@ -484,7 +484,7 @@ struct lttng_evaluation *lttng_evaluation_session_consumed_size_create(
 {
        struct lttng_evaluation_session_consumed_size *consumed_eval;
 
-       consumed_eval = (lttng_evaluation_session_consumed_size *) zmalloc(sizeof(struct lttng_evaluation_session_consumed_size));
+       consumed_eval = zmalloc<lttng_evaluation_session_consumed_size>();
        if (!consumed_eval) {
                goto end;
        }
index 094d1ea9421fa000007540359541ce92218c01c6..82e843465ccb453097a86cde2aa0533ce93c9e4c 100644 (file)
@@ -185,7 +185,7 @@ struct lttng_condition *lttng_condition_session_rotation_create(
 {
        struct lttng_condition_session_rotation *condition;
 
-       condition = (lttng_condition_session_rotation *) zmalloc(sizeof(struct lttng_condition_session_rotation));
+       condition = zmalloc<lttng_condition_session_rotation>();
        if (!condition) {
                return NULL;
        }
@@ -333,7 +333,7 @@ struct lttng_evaluation *lttng_evaluation_session_rotation_create(
 {
        struct lttng_evaluation_session_rotation *evaluation;
 
-       evaluation = (lttng_evaluation_session_rotation *) zmalloc(sizeof(struct lttng_evaluation_session_rotation));
+       evaluation = zmalloc<lttng_evaluation_session_rotation>();
        if (!evaluation) {
                return NULL;
        }
index dfbddf2913d25550c7058ca96b9d7e54757501e9..9e5f0ff20cbf298b4753c2e0bf2975e7b8d5ea25 100644 (file)
@@ -287,7 +287,7 @@ struct config_writer *config_writer_create(int fd_output, int indent)
        struct config_writer *writer;
        xmlOutputBufferPtr buffer;
 
-       writer = (config_writer *) zmalloc(sizeof(struct config_writer));
+       writer = zmalloc<config_writer>();
        if (!writer) {
                PERROR("zmalloc config_writer_create");
                goto end;
@@ -581,7 +581,7 @@ char *get_session_config_xsd_path(void)
        base_path_len = strlen(base_path);
        max_path_len = base_path_len +
                sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME) + 1;
-       xsd_path = (char *) zmalloc(max_path_len);
+       xsd_path = zmalloc<char>(max_path_len);
        if (!xsd_path) {
                goto end;
        }
@@ -1856,7 +1856,7 @@ int process_event_node(xmlNodePtr event_node, struct lttng_handle *handle,
                                continue;
                        }
 
-                       exclusions = (char **) zmalloc(exclusion_count * sizeof(char *));
+                       exclusions = calloc<char *>(exclusion_count);
                        if (!exclusions) {
                                exclusion_count = 0;
                                ret = -LTTNG_ERR_NOMEM;
@@ -3399,9 +3399,8 @@ int process_session_node(xmlNodePtr session_node, const char *session_name,
        /* Init domains to create the session handles */
        for (node = xmlFirstElementChild(domains_node); node;
                node = xmlNextElementSibling(node)) {
-               struct lttng_domain *domain;
+               lttng_domain *domain = zmalloc<lttng_domain>();
 
-               domain = (lttng_domain *) zmalloc(sizeof(*domain));
                if (!domain) {
                        ret = -LTTNG_ERR_NOMEM;
                        goto error;
index a810c7dab9eea84bbac194d6f1afa304603ee100..274ecf48fa71275ee28803f850049b7ab882f763 100644 (file)
@@ -129,8 +129,7 @@ int consumer_metadata_cache_allocate(struct lttng_consumer_channel *channel)
 
        LTTNG_ASSERT(channel);
 
-       channel->metadata_cache = (consumer_metadata_cache *) zmalloc(
-                       sizeof(struct consumer_metadata_cache));
+       channel->metadata_cache = zmalloc<consumer_metadata_cache>();
        if (!channel->metadata_cache) {
                PERROR("zmalloc metadata cache struct");
                ret = -1;
index f57e37ab81379027daf318acc58d2b90b710b41d..c22c7e5f3390f74576bb22fa0bfe10e506ed9a51 100644 (file)
@@ -654,7 +654,7 @@ struct lttng_consumer_stream *consumer_stream_create(
        int ret;
        struct lttng_consumer_stream *stream;
 
-       stream = (lttng_consumer_stream *) zmalloc(sizeof(*stream));
+       stream = zmalloc<lttng_consumer_stream>();
        if (stream == NULL) {
                PERROR("malloc struct lttng_consumer_stream");
                ret = -ENOMEM;
index 685d55f838120a4b94cf407d9e420e03cf294e32..9393e6cc29af21a8c3b8072ffd42eb6a0ae14b3e 100644 (file)
@@ -662,7 +662,7 @@ static struct consumer_relayd_sock_pair *consumer_allocate_relayd_sock_pair(
                goto error;
        }
 
-       obj = (consumer_relayd_sock_pair *) zmalloc(sizeof(struct consumer_relayd_sock_pair));
+       obj = zmalloc<consumer_relayd_sock_pair>();
        if (obj == NULL) {
                PERROR("zmalloc relayd sock");
                goto error;
@@ -1029,7 +1029,7 @@ struct lttng_consumer_channel *consumer_allocate_channel(uint64_t key,
                }
        }
 
-       channel = (lttng_consumer_channel *) zmalloc(sizeof(*channel));
+       channel = zmalloc<lttng_consumer_channel>();
        if (channel == NULL) {
                PERROR("malloc struct lttng_consumer_channel");
                goto end;
@@ -1425,7 +1425,7 @@ struct lttng_consumer_local_data *lttng_consumer_create(
                        the_consumer_data.type == type);
        the_consumer_data.type = type;
 
-       ctx = (lttng_consumer_local_data *) zmalloc(sizeof(struct lttng_consumer_local_data));
+       ctx = zmalloc<lttng_consumer_local_data>();
        if (ctx == NULL) {
                PERROR("allocating context");
                goto error;
@@ -2561,7 +2561,7 @@ void *consumer_thread_data_poll(void *data)
 
        health_code_update();
 
-       local_stream = (lttng_consumer_stream **) zmalloc(sizeof(struct lttng_consumer_stream *));
+       local_stream = zmalloc<lttng_consumer_stream *>();
        if (local_stream == NULL) {
                PERROR("local_stream malloc");
                goto end;
@@ -2586,18 +2586,14 @@ void *consumer_thread_data_poll(void *data)
                        local_stream = NULL;
 
                        /* Allocate for all fds */
-                       pollfd = (struct pollfd *) zmalloc((the_consumer_data.stream_count +
-                                                        nb_pipes_fd) *
-                                       sizeof(struct pollfd));
+                       pollfd = calloc<struct pollfd>(the_consumer_data.stream_count + nb_pipes_fd);
                        if (pollfd == NULL) {
                                PERROR("pollfd malloc");
                                pthread_mutex_unlock(&the_consumer_data.lock);
                                goto end;
                        }
 
-                       local_stream = (lttng_consumer_stream **) zmalloc((the_consumer_data.stream_count +
-                                                              nb_pipes_fd) *
-                                       sizeof(struct lttng_consumer_stream *));
+                       local_stream = calloc<lttng_consumer_stream *>(the_consumer_data.stream_count + nb_pipes_fd);
                        if (local_stream == NULL) {
                                PERROR("local_stream malloc");
                                pthread_mutex_unlock(&the_consumer_data.lock);
index ed78ec9472f800e3b55358bd9c5e235135bf52e9..f9c35e22ce4c4d3e25521c53e02d91dc9694c1eb 100644 (file)
@@ -25,9 +25,7 @@ struct metadata_bucket {
 struct metadata_bucket *metadata_bucket_create(
                metadata_bucket_flush_cb flush, void *data)
 {
-       struct metadata_bucket *bucket;
-
-       bucket = (metadata_bucket *) zmalloc(sizeof(typeof(*bucket)));
+       metadata_bucket *bucket = zmalloc<metadata_bucket>();
        if (!bucket) {
                PERROR("Failed to allocate buffer bucket");
                goto end;
index 98c29f86c2cbac21f344e3a1df33231e6e6eb7c5..a4111ad9002e9a29fcd073b4b4c6f93b41041040 100644 (file)
@@ -52,7 +52,7 @@ int parse_application_context(const char *str, char **out_provider_name,
        }
 
        provider_name_len = colon_pos - sizeof(app_ctx_prefix) + 2;
-       provider_name = (char *) zmalloc(provider_name_len);
+       provider_name = calloc<char>(provider_name_len);
        if (!provider_name) {
                PERROR("malloc provider_name");
                goto not_found;
@@ -61,7 +61,7 @@ int parse_application_context(const char *str, char **out_provider_name,
                        provider_name_len - 1);
 
        ctx_name_len = len - colon_pos;
-       ctx_name = (char *) zmalloc(ctx_name_len);
+       ctx_name = calloc<char>(ctx_name_len);
        if (!ctx_name) {
                PERROR("malloc ctx_name");
                goto not_found;
index b299966515dd4175e75f19aa5bce56eb74593940..13efbbfd7d03f6154ceca9dcc8f9b7b2e8fb69fb 100644 (file)
@@ -111,7 +111,7 @@ struct lttng_error_query *lttng_error_query_trigger_create(
                goto end;
        }
 
-       query = (lttng_error_query_trigger *) zmalloc(sizeof(*query));
+       query = zmalloc<lttng_error_query_trigger>();
        if (!query) {
                PERROR("Failed to allocate trigger error query");
                goto error;
@@ -142,7 +142,7 @@ struct lttng_error_query *lttng_error_query_condition_create(
                goto end;
        }
 
-       query = (lttng_error_query_condition *) zmalloc(sizeof(*query));
+       query = zmalloc<lttng_error_query_condition>();
        if (!query) {
                PERROR("Failed to allocate condition error query");
                goto error;
@@ -221,7 +221,7 @@ struct lttng_error_query *lttng_error_query_action_create(
                goto end;
        }
 
-       query = (lttng_error_query_action *) zmalloc(sizeof(*query));
+       query = zmalloc<lttng_error_query_action>();
        if (!query) {
                PERROR("Failed to allocate action error query");
                goto error;
@@ -388,7 +388,7 @@ lttng_error_query_result_counter_create(
        int init_ret;
        struct lttng_error_query_result_counter *counter;
 
-       counter = (lttng_error_query_result_counter *) zmalloc(sizeof(*counter));
+       counter = zmalloc<lttng_error_query_result_counter>();
        if (!counter) {
                PERROR("Failed to allocate error query counter result");
                goto end;
@@ -419,7 +419,7 @@ void destroy_result(void *ptr)
 
 struct lttng_error_query_results *lttng_error_query_results_create(void)
 {
-       struct lttng_error_query_results *set = (lttng_error_query_results *) zmalloc(sizeof(*set));
+       struct lttng_error_query_results *set = zmalloc<lttng_error_query_results>();
 
        if (!set) {
                PERROR("Failed to allocate an error query result set");
index 9306dbeee76571c0cb210b99f0360cf9b0f1464a..1b592bdb121cf54fbc5d8f3204e9c9be0512994a 100644 (file)
@@ -40,7 +40,7 @@ struct lttng_event_expr *create_empty_expr(enum lttng_event_expr_type type,
 {
        struct lttng_event_expr *expr;
 
-       expr = (lttng_event_expr *) zmalloc(size);
+       expr = zmalloc<lttng_event_expr>(size);
        if (!expr) {
                goto end;
        }
index 816017a2da77fe1e316fdf0f347c1bcfa0512df4..3ab12728c769ae9f642fdc236646664e8a49bf1b 100644 (file)
@@ -23,7 +23,7 @@ struct lttng_event_field_value *create_empty_field_val(
 {
        struct lttng_event_field_value *field_val;
 
-       field_val = (lttng_event_field_value *) zmalloc(size);
+       field_val = zmalloc<lttng_event_field_value>(size);
        if (!field_val) {
                goto end;
        }
index 51cbdc0041857ed2894995124a02f0dc85bfb6da..14fa179eba2276820f3099cb7c70594c05ec7f62 100644 (file)
@@ -421,7 +421,7 @@ static struct lttng_event *lttng_event_rule_jul_logging_generate_lttng_event(
        jul_logging = container_of(
                        rule, const struct lttng_event_rule_jul_logging, parent);
 
-       local_event = (lttng_event *) zmalloc(sizeof(*local_event));
+       local_event = zmalloc<lttng_event>();
        if (!local_event) {
                goto error;
        }
@@ -561,7 +561,7 @@ struct lttng_event_rule *lttng_event_rule_jul_logging_create(void)
        struct lttng_event_rule_jul_logging *tp_rule;
        enum lttng_event_rule_status status;
 
-       tp_rule = (lttng_event_rule_jul_logging *) zmalloc(sizeof(struct lttng_event_rule_jul_logging));
+       tp_rule = zmalloc<lttng_event_rule_jul_logging>();
        if (!tp_rule) {
                goto end;
        }
index 628a051c30ce312ebd46f5389022aa80bccd5119..bad894e35962141326b7b692246f69ea51328661 100644 (file)
@@ -289,7 +289,7 @@ struct lttng_event_rule *lttng_event_rule_kernel_kprobe_create(
        struct lttng_event_rule *rule = NULL;
        struct lttng_event_rule_kernel_kprobe *krule;
 
-       krule = (lttng_event_rule_kernel_kprobe *) zmalloc(sizeof(struct lttng_event_rule_kernel_kprobe));
+       krule = zmalloc<lttng_event_rule_kernel_kprobe>();
        if (!krule) {
                goto end;
        }
index 815f99d9df0434a3dfac3f9ec96160c342116c32..d006eaa054960b29eeb59edf0e342cc60ba19459 100644 (file)
@@ -356,7 +356,7 @@ struct lttng_event_rule *lttng_event_rule_kernel_syscall_create(
                goto end;
        }
 
-       syscall_rule = (lttng_event_rule_kernel_syscall *) zmalloc(sizeof(struct lttng_event_rule_kernel_syscall));
+       syscall_rule = zmalloc<lttng_event_rule_kernel_syscall>();
        if (!syscall_rule) {
                goto end;
        }
index e546de1f3d7539eb6bd65f7f2ceb1bb679477326..0bedfb5010e2cff38281a2381aa22f450bc36879 100644 (file)
@@ -333,7 +333,7 @@ struct lttng_event_rule *lttng_event_rule_kernel_tracepoint_create(void)
        struct lttng_event_rule_kernel_tracepoint *tp_rule;
        enum lttng_event_rule_status status;
 
-       tp_rule = (lttng_event_rule_kernel_tracepoint *) zmalloc(sizeof(struct lttng_event_rule_kernel_tracepoint));
+       tp_rule = zmalloc<lttng_event_rule_kernel_tracepoint>();
        if (!tp_rule) {
                goto end;
        }
index 1a42421d39c2f405632083c244752b5435e53d90..4e611aca231d7373425205382ee1076d662afa4a 100644 (file)
@@ -279,7 +279,7 @@ struct lttng_event_rule *lttng_event_rule_kernel_uprobe_create(
        struct lttng_event_rule *rule = NULL;
        struct lttng_event_rule_kernel_uprobe *urule;
 
-       urule = (lttng_event_rule_kernel_uprobe *) zmalloc(sizeof(struct lttng_event_rule_kernel_uprobe));
+       urule = zmalloc<lttng_event_rule_kernel_uprobe>();
        if (!urule) {
                goto end;
        }
index 937331a36a315a533be2c161b7e571c2ed7023a8..b7386c0ba36f99743055efff6c0ff5a8b04d954e 100644 (file)
@@ -421,7 +421,7 @@ static struct lttng_event *lttng_event_rule_log4j_logging_generate_lttng_event(
        log4j_logging = container_of(
                        rule, const struct lttng_event_rule_log4j_logging, parent);
 
-       local_event = (lttng_event *) zmalloc(sizeof(*local_event));
+       local_event = zmalloc<lttng_event>();
        if (!local_event) {
                goto error;
        }
@@ -560,7 +560,7 @@ struct lttng_event_rule *lttng_event_rule_log4j_logging_create(void)
        struct lttng_event_rule_log4j_logging *tp_rule;
        enum lttng_event_rule_status status;
 
-       tp_rule = (lttng_event_rule_log4j_logging *) zmalloc(sizeof(struct lttng_event_rule_log4j_logging));
+       tp_rule = zmalloc<lttng_event_rule_log4j_logging>();
        if (!tp_rule) {
                goto end;
        }
index 20b649648c13bb94bee1bab8b7cbdd3b4ee4e133..25e967702436e2afc34708a067a32b1ea7ffccd8 100644 (file)
@@ -421,7 +421,7 @@ static struct lttng_event *lttng_event_rule_python_logging_generate_lttng_event(
        python_logging = container_of(
                        rule, const struct lttng_event_rule_python_logging, parent);
 
-       local_event = (lttng_event *) zmalloc(sizeof(*local_event));
+       local_event = zmalloc<lttng_event>();
        if (!local_event) {
                goto error;
        }
@@ -560,7 +560,7 @@ struct lttng_event_rule *lttng_event_rule_python_logging_create(void)
        struct lttng_event_rule_python_logging *tp_rule;
        enum lttng_event_rule_status status;
 
-       tp_rule = (lttng_event_rule_python_logging *) zmalloc(sizeof(struct lttng_event_rule_python_logging));
+       tp_rule = zmalloc<lttng_event_rule_python_logging>();
        if (!tp_rule) {
                goto end;
        }
index 8932ca786c72c657ac11692c1de6d6228f3daa77..48040fc59292384310ae1ac4fb19e0332266b08b 100644 (file)
@@ -362,8 +362,7 @@ lttng_event_rule_user_tracepoint_generate_exclusions(
                goto end;
        }
 
-       exclusions = (lttng_event_exclusion *) zmalloc(sizeof(struct lttng_event_exclusion) +
-                       (LTTNG_SYMBOL_NAME_LEN * nb_exclusions));
+       exclusions = zmalloc<lttng_event_exclusion>(sizeof(struct lttng_event_exclusion) + (LTTNG_SYMBOL_NAME_LEN * nb_exclusions));
        if (!exclusions) {
                PERROR("Failed to allocate exclusions buffer");
                ret_status = LTTNG_EVENT_RULE_GENERATE_EXCLUSIONS_STATUS_OUT_OF_MEMORY;
@@ -560,7 +559,7 @@ struct lttng_event_rule *lttng_event_rule_user_tracepoint_create(void)
        struct lttng_event_rule_user_tracepoint *tp_rule;
        enum lttng_event_rule_status status;
 
-       tp_rule = (lttng_event_rule_user_tracepoint *) zmalloc(sizeof(struct lttng_event_rule_user_tracepoint));
+       tp_rule = zmalloc<lttng_event_rule_user_tracepoint>();
        if (!tp_rule) {
                goto end;
        }
index 358d058411cf5ce862ff44815b59f52ff5aa4a0d..4844888a2df770ca5b9bed7e5dd7a9d758be7def 100644 (file)
@@ -41,7 +41,7 @@ struct lttng_event *lttng_event_copy(const struct lttng_event *event)
        struct lttng_event *new_event;
        struct lttng_event_extended *new_event_extended;
 
-       new_event = (lttng_event *) zmalloc(sizeof(*event));
+       new_event = zmalloc<lttng_event>();
        if (!new_event) {
                PERROR("Error allocating event structure");
                goto end;
@@ -54,7 +54,7 @@ struct lttng_event *lttng_event_copy(const struct lttng_event *event)
         * We need to create a new extended since the previous pointer is now
         * invalid.
         */
-       new_event_extended = (lttng_event_extended *) zmalloc(sizeof(*new_event_extended));
+       new_event_extended = zmalloc<lttng_event_extended>();
        if (!new_event_extended) {
                PERROR("Error allocating event extended structure");
                goto error;
@@ -157,8 +157,7 @@ static ssize_t lttng_event_probe_attr_create_from_payload(
        comm = (typeof(comm)) comm_view.buffer.data;
        offset += sizeof(*comm);
 
-       local_attr = (struct lttng_event_probe_attr *) zmalloc(
-                       sizeof(*local_attr));
+       local_attr = zmalloc<lttng_event_probe_attr>();
        if (local_attr == NULL) {
                ret = -1;
                goto end;
@@ -222,8 +221,7 @@ static ssize_t lttng_event_function_attr_create_from_payload(
        comm = (typeof(comm)) view->buffer.data;
        offset += sizeof(*comm);
 
-       local_attr = (struct lttng_event_function_attr *) zmalloc(
-                       sizeof(*local_attr));
+       local_attr = zmalloc<lttng_event_function_attr>();
        if (local_attr == NULL) {
                ret = -1;
                goto end;
@@ -272,12 +270,12 @@ static ssize_t lttng_event_exclusions_create_from_payload(
                struct lttng_event_exclusion **exclusions)
 {
        ssize_t ret, offset = 0;
-       size_t size = (count * LTTNG_SYMBOL_NAME_LEN);
+       const size_t size = (count * LTTNG_SYMBOL_NAME_LEN);
        uint32_t i;
        const struct lttng_event_exclusion_comm *comm;
        struct lttng_event_exclusion *local_exclusions;
 
-       local_exclusions = (struct lttng_event_exclusion *) zmalloc(
+       local_exclusions = zmalloc<lttng_event_exclusion>(
                        sizeof(struct lttng_event_exclusion) + size);
        if (!local_exclusions) {
                ret = -1;
@@ -510,8 +508,7 @@ deserialize_filter_expression:
                        goto end;
                }
 
-               local_bytecode = (struct lttng_bytecode *) zmalloc(
-                               event_comm->bytecode_len);
+               local_bytecode = zmalloc<lttng_bytecode>(event_comm->bytecode_len);
                if (!local_bytecode) {
                        ret = -1;
                        goto end;
@@ -1078,8 +1075,7 @@ ssize_t lttng_event_context_create_from_payload(
        comm = (typeof(comm)) comm_view.data;
        offset += sizeof(*comm);
 
-       local_context = (struct lttng_event_context *)
-                       zmalloc(sizeof(*local_context));
+       local_context = zmalloc<lttng_event_context>();
        if (!local_context) {
                ret = -1;
                goto end;
@@ -1331,8 +1327,7 @@ ssize_t lttng_event_field_create_from_payload(
                offset += sizeof(*comm);
        }
 
-       local_event_field = (struct lttng_event_field *)
-                       zmalloc(sizeof(*local_event_field));
+       local_event_field = zmalloc<lttng_event_field>();
        if (!local_event_field) {
                ret = -1;
                goto end;
@@ -1713,8 +1708,7 @@ static enum lttng_error_code event_list_create_from_payload(
                ssize_t event_size;
                struct lttng_payload_view event_view =
                                lttng_payload_view_from_view(view, offset, -1);
-               struct event_list_element *element =
-                               (struct event_list_element *) zmalloc(sizeof(*element));
+               struct event_list_element *element = zmalloc<event_list_element>();
 
                if (!element) {
                        ret_code = LTTNG_ERR_NOMEM;
@@ -1870,7 +1864,7 @@ static enum lttng_error_code event_field_list_create_from_payload(
        assert(view);
        assert(event_field_list);
 
-       list = (struct lttng_dynamic_pointer_array *) zmalloc(sizeof(*list));
+       list = zmalloc<lttng_dynamic_pointer_array>();
        if (!list) {
                ret_code = LTTNG_ERR_NOMEM;
                goto end;
index 7473f071789982ca1c169812ef6d109430269269..579757782702f175315254b3003b001e1355bbae 100644 (file)
@@ -41,7 +41,7 @@ struct fd_handle *fd_handle_create(int fd)
                goto end;
        }
 
-       handle = (fd_handle *) zmalloc(sizeof(*handle));
+       handle = zmalloc<fd_handle>();
        if (!handle) {
                PERROR("Failed to allocate fd_handle");
                goto end;
index 9c6f031b0b6dc6e4995dde7d72f50fc158c06824..398ec971ddd5fdf5c8e0ff61e987efbad3ac1432 100644 (file)
@@ -188,7 +188,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 +365,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 +526,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 +620,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 +719,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;
index b5cdcf1b27b583dd3e67f004db62ba214057281d..9c1133ea56255281e628533453df8b36d55eac89 100644 (file)
@@ -250,7 +250,7 @@ static void lttng_inode_get(struct lttng_inode *inode)
 struct lttng_unlinked_file_pool *lttng_unlinked_file_pool_create(
                const char *path)
 {
-       struct lttng_unlinked_file_pool *pool = (lttng_unlinked_file_pool *) zmalloc(sizeof(*pool));
+       struct lttng_unlinked_file_pool *pool = zmalloc<lttng_unlinked_file_pool>();
 
        if (!pool) {
                goto error;
@@ -434,7 +434,7 @@ static struct lttng_inode *lttng_inode_create(const struct inode_id *id,
        reference_acquired = lttng_directory_handle_get(directory_handle);
        LTTNG_ASSERT(reference_acquired);
 
-       inode = (lttng_inode *) zmalloc(sizeof(*inode));
+       inode = zmalloc<lttng_inode>();
        if (!inode) {
                goto end;
        }
@@ -455,7 +455,7 @@ end:
 
 struct lttng_inode_registry *lttng_inode_registry_create(void)
 {
-       struct lttng_inode_registry *registry = (lttng_inode_registry *) zmalloc(sizeof(*registry));
+       struct lttng_inode_registry *registry = zmalloc<lttng_inode_registry>();
 
        if (!registry) {
                goto end;
index 2bff02031f2b97d5220bf034af286f2e3e386682..f0b248e88155e51e54773163532a90da3e949cca 100644 (file)
@@ -23,7 +23,7 @@ struct bytecode_symbol_iterator *bytecode_symbol_iterator_create(
                goto end;
        }
 
-       it = (bytecode_symbol_iterator *) zmalloc(sizeof(*it));
+       it = zmalloc<bytecode_symbol_iterator>();
        if (!it) {
                goto end;
        }
index 89f6b43d911f7de5a17db2dd25dadfb2aaf74262..0f11c234d6197f30ab3b9cea48ea749bf6697fbe 100644 (file)
@@ -97,7 +97,7 @@ static struct gc_string *gc_string_alloc(struct filter_parser_ctx *parser_ctx,
        for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
             alloclen *= 2);
 
-       gstr = (gc_string *) zmalloc(alloclen);
+       gstr = zmalloc<gc_string>(alloclen);
        if (!gstr) {
                goto end;
        }
@@ -154,7 +154,7 @@ static struct filter_node *make_node(struct filter_parser_ctx *scanner,
        struct filter_ast *ast = filter_parser_get_ast(scanner);
        struct filter_node *node;
 
-       node = (filter_node *) zmalloc(sizeof(*node));
+       node = zmalloc<filter_node>();
        if (!node)
                return NULL;
        memset(node, 0, sizeof(*node));
@@ -191,7 +191,7 @@ static struct filter_node *make_op_node(struct filter_parser_ctx *scanner,
        struct filter_ast *ast = filter_parser_get_ast(scanner);
        struct filter_node *node;
 
-       node = (filter_node *) zmalloc(sizeof(*node));
+       node = zmalloc<filter_node>();
        if (!node)
                return NULL;
        memset(node, 0, sizeof(*node));
@@ -227,7 +227,7 @@ static struct filter_ast *filter_ast_alloc(void)
 {
        struct filter_ast *ast;
 
-       ast = (filter_ast *) zmalloc(sizeof(*ast));
+       ast = zmalloc<filter_ast>();
        if (!ast)
                return NULL;
        memset(ast, 0, sizeof(*ast));
@@ -257,7 +257,7 @@ struct filter_parser_ctx *filter_parser_ctx_alloc(FILE *input)
 
        yydebug = filter_parser_debug;
 
-       parser_ctx = (filter_parser_ctx *) zmalloc(sizeof(*parser_ctx));
+       parser_ctx = zmalloc<filter_parser_ctx>();
        if (!parser_ctx)
                return NULL;
        memset(parser_ctx, 0, sizeof(*parser_ctx));
index a7236bd104f7e7314301507dc7442bb3a82b6f6a..1bfe66c6f0d5010d71c2d8fe02f774f5eb5744a7 100644 (file)
@@ -31,7 +31,7 @@ struct ir_op *make_op_root(struct ir_op *child, enum ir_side side)
 {
        struct ir_op *op;
 
-       op = (ir_op *) zmalloc(sizeof(struct ir_op));
+       op = zmalloc<ir_op>();
        if (!op)
                return NULL;
        switch (child->data_type) {
@@ -80,7 +80,7 @@ struct ir_op *make_op_load_string(const char *string, enum ir_side side)
 {
        struct ir_op *op;
 
-       op = (ir_op *) zmalloc(sizeof(struct ir_op));
+       op = zmalloc<ir_op>();
        if (!op)
                return NULL;
        op->op = IR_OP_LOAD;
@@ -101,7 +101,7 @@ struct ir_op *make_op_load_numeric(int64_t v, enum ir_side side)
 {
        struct ir_op *op;
 
-       op = (ir_op *) zmalloc(sizeof(struct ir_op));
+       op = zmalloc<ir_op>();
        if (!op)
                return NULL;
        op->op = IR_OP_LOAD;
@@ -118,7 +118,7 @@ struct ir_op *make_op_load_float(double v, enum ir_side side)
 {
        struct ir_op *op;
 
-       op = (ir_op *) zmalloc(sizeof(struct ir_op));
+       op = zmalloc<ir_op>();
        if (!op)
                return NULL;
        op->op = IR_OP_LOAD;
@@ -192,12 +192,12 @@ struct ir_load_expression *create_load_expression(struct filter_node *node)
        node = load_expression_get_forward_chain(node);
        if (!node)
                return NULL;
-       load_exp = (ir_load_expression *) zmalloc(sizeof(struct ir_load_expression));
+       load_exp = zmalloc<ir_load_expression>();
        if (!load_exp)
                return NULL;
 
        /* Root */
-       load_exp_op = (ir_load_expression_op *) zmalloc(sizeof(struct ir_load_expression_op));
+       load_exp_op = zmalloc<ir_load_expression_op>();
        if (!load_exp_op)
                goto error;
        load_exp->child = load_exp_op;
@@ -229,7 +229,7 @@ struct ir_load_expression *create_load_expression(struct filter_node *node)
                struct filter_node *bracket_node;
 
                prev_op = load_exp_op;
-               load_exp_op = (ir_load_expression_op *) zmalloc(sizeof(struct ir_load_expression_op));
+               load_exp_op = zmalloc<ir_load_expression_op>();
                if (!load_exp_op)
                        goto error;
                prev_op->next = load_exp_op;
@@ -248,7 +248,7 @@ struct ir_load_expression *create_load_expression(struct filter_node *node)
                                        fprintf(stderr, "[error] Expecting constant index in array expression\n");
                                        goto error;
                                }
-                       load_exp_op = (ir_load_expression_op *) zmalloc(sizeof(struct ir_load_expression_op));
+                       load_exp_op = zmalloc<ir_load_expression_op>();
                        if (!load_exp_op)
                                goto error;
                        prev_op->next = load_exp_op;
@@ -263,7 +263,7 @@ struct ir_load_expression *create_load_expression(struct filter_node *node)
        }
        /* Add final load field */
        prev_op = load_exp_op;
-       load_exp_op = (ir_load_expression_op *) zmalloc(sizeof(struct ir_load_expression_op));
+       load_exp_op = zmalloc<ir_load_expression_op>();
        if (!load_exp_op)
                goto error;
        prev_op->next = load_exp_op;
@@ -281,7 +281,7 @@ struct ir_op *make_op_load_expression(struct filter_node *node,
 {
        struct ir_op *op;
 
-       op = (ir_op *) zmalloc(sizeof(struct ir_op));
+       op = zmalloc<ir_op>();
        if (!op)
                return NULL;
        op->op = IR_OP_LOAD;
@@ -312,7 +312,7 @@ struct ir_op *make_op_unary(enum unary_op_type unary_op_type,
                goto error;
        }
 
-       op = (ir_op *) zmalloc(sizeof(struct ir_op));
+       op = zmalloc<ir_op>();
        if (!op)
                return NULL;
        op->op = IR_OP_UNARY;
@@ -380,7 +380,7 @@ struct ir_op *make_op_binary_compare(enum op_type bin_op_type,
                goto error;
        }
 
-       op = (ir_op *) zmalloc(sizeof(struct ir_op));
+       op = zmalloc<ir_op>();
        if (!op)
                return NULL;
        op->op = IR_OP_BINARY;
@@ -461,7 +461,7 @@ struct ir_op *make_op_binary_logical(enum op_type bin_op_type,
                goto error;
        }
 
-       op = (ir_op *) zmalloc(sizeof(struct ir_op));
+       op = zmalloc<ir_op>();
        if (!op)
                return NULL;
        op->op = IR_OP_LOGICAL;
@@ -505,7 +505,7 @@ struct ir_op *make_op_binary_bitwise(enum op_type bin_op_type,
                goto error;
        }
 
-       op = (ir_op *) zmalloc(sizeof(struct ir_op));
+       op = zmalloc<ir_op>();
        if (!op)
                return NULL;
        op->op = IR_OP_BINARY;
index 6b87ff71f016ae9fb1fa309ace336a58d369b1f8..1b40f91f125fa97ef46d409476148d1ef29585dd 100644 (file)
@@ -110,7 +110,7 @@ struct lttng_ht *lttng_ht_new(unsigned long size, lttng_ht_type type)
        }
        pthread_mutex_unlock(&seed_lock);
 
-       ht = (lttng_ht *) zmalloc(sizeof(*ht));
+       ht = zmalloc<lttng_ht>();
        if (ht == NULL) {
                PERROR("zmalloc lttng_ht");
                goto error;
index 9d33ffd2fc7b8e487885bc69d0fbce0c6875f09d..8181eab931c07aa0c131c8157ce85a6584f8d11c 100644 (file)
@@ -67,11 +67,11 @@ struct health_app *health_app_create(int nr_types)
 {
        struct health_app *ha;
 
-       ha = (health_app *) zmalloc(sizeof(*ha));
+       ha = zmalloc<health_app>();
        if (!ha) {
                return NULL;
        }
-       ha->flags = (health_flags *) zmalloc(sizeof(*ha->flags) * nr_types);
+       ha->flags = calloc<health_flags>(nr_types);
        if (!ha->flags) {
                goto error_flags;
        }
index 7fe18eb1862cd41674b38c359d425de62f1365ad..1f7b3e05208d3cfb6fa60785f4db7218f57f7588 100644 (file)
@@ -32,7 +32,7 @@ struct lttng_index_allocator *lttng_index_allocator_create(
 {
        struct lttng_index_allocator *allocator = NULL;
 
-       allocator = (lttng_index_allocator *) zmalloc(sizeof(*allocator));
+       allocator = zmalloc<lttng_index_allocator>();
        if (!allocator) {
                PERROR("Failed to allocate index allocator");
                goto end;
@@ -92,7 +92,7 @@ enum lttng_index_allocator_status lttng_index_allocator_release(
 
        LTTNG_ASSERT(idx < allocator->size);
 
-       index = (lttng_index *) zmalloc(sizeof(*index));
+       index = zmalloc<lttng_index>();
        if (!index) {
                PERROR("Failed to allocate free index queue");
                status = LTTNG_INDEX_ALLOCATOR_STATUS_ERROR;
index 9d6895baea9817af1a7e4c34dafffbce53e131ea..de66ac4bdd3088427fccd5d9a00f0adc5a4a4da9 100644 (file)
@@ -45,7 +45,7 @@ static enum lttng_trace_chunk_status _lttng_index_file_create_from_trace_chunk(
 
        LTTNG_ASSERT(acquired_reference);
 
-       index_file = (lttng_index_file *) zmalloc(sizeof(*index_file));
+       index_file = zmalloc<lttng_index_file>();
        if (!index_file) {
                PERROR("Failed to allocate lttng_index_file");
                chunk_status = LTTNG_TRACE_CHUNK_STATUS_ERROR;
index 98308c9f348ee2946b86da36654c6897194779db..0b9502fc48c77db3a200bfb8a7f4f0e3b7217929 100644 (file)
@@ -144,7 +144,7 @@ int config_parse_value(const char *value)
                goto end;
        }
 
-       lower_str = (char *) zmalloc(len + 1);
+       lower_str = zmalloc<char>(len + 1);
        if (!lower_str) {
                PERROR("zmalloc");
                ret = -errno;
index d8ec8cf3e375545b36416867704e45fa2b16f2cc..ec5a41119e87c17f66b47d3656909ed670c11ea4 100644 (file)
@@ -109,7 +109,7 @@ int ini_parse_file(FILE* file, ini_entry_handler handler, void* user)
        int error = 0;
 
 #if !INI_USE_STACK
-       line = (char*)zmalloc(INI_MAX_LINE);
+       line = zmalloc<char>(INI_MAX_LINE);
        if (!line) {
                return -2;
        }
index 059ab4b0dc5a41060818c624abb1e5d16528520e..76960307c80abe7924011c22f2f3a3ebccfc626d 100644 (file)
@@ -181,7 +181,7 @@ int kernctl_syscall_mask(int fd, char **syscall_mask, uint32_t *nr_bits)
 
        array_alloc_len = lttng_align_ceil(kmask_len.len, 8) >> 3;
 
-       kmask = (lttng_kernel_abi_syscall_mask *) zmalloc(sizeof(*kmask) + array_alloc_len);
+       kmask = zmalloc<lttng_kernel_abi_syscall_mask>(sizeof(*kmask) + array_alloc_len);
        if (!kmask) {
                ret = -1;
                goto end;
@@ -519,7 +519,7 @@ int kernctl_capture(int fd, const struct lttng_bytecode *capture)
        struct lttng_kernel_abi_capture_bytecode *kb;
 
        /* Translate bytecode to kernel bytecode. */
-       kb = (lttng_kernel_abi_capture_bytecode *) zmalloc(sizeof(*kb) + capture->len);
+       kb = zmalloc<lttng_kernel_abi_capture_bytecode>(sizeof(*kb) + capture->len);
        if (!kb) {
                ret = -ENOMEM;
                goto end;
@@ -542,7 +542,7 @@ int kernctl_filter(int fd, const struct lttng_bytecode *filter)
        int ret;
 
        /* Translate bytecode to kernel bytecode */
-       kb = (lttng_kernel_abi_filter_bytecode *) zmalloc(sizeof(*kb) + filter->len);
+       kb = zmalloc<lttng_kernel_abi_filter_bytecode>(sizeof(*kb) + filter->len);
        if (!kb)
                return -ENOMEM;
        kb->len = len = filter->len;
index 979ca73111dc161b82cc4e6b8872ea5f9f34853c..172527f9a4f33d4cb6cb66db1f10edec9bbf2879 100644 (file)
@@ -117,7 +117,7 @@ lttng_kernel_probe_location_address_create(uint64_t address)
        struct lttng_kernel_probe_location *ret = NULL;
        struct lttng_kernel_probe_location_address *location;
 
-       location = (lttng_kernel_probe_location_address *) zmalloc(sizeof(*location));
+       location = zmalloc<lttng_kernel_probe_location_address>();
        if (!location) {
                PERROR("Error allocating userspace probe location.");
                goto end;
@@ -154,7 +154,7 @@ lttng_kernel_probe_location_symbol_create(const char *symbol_name,
                goto error;
        }
 
-       location = (lttng_kernel_probe_location_symbol *) zmalloc(sizeof(*location));
+       location = zmalloc<lttng_kernel_probe_location_symbol>();
        if (!location) {
                PERROR("Failed to allocate kernel symbol probe location");
                goto error;
index 7e6ea79b0aac8baa6082ff5f06869e7771bac670..65c0412402a42d2dca6a4f99727293f88c58795f 100644 (file)
@@ -16,7 +16,7 @@ struct lttng_trace_archive_location *lttng_trace_archive_location_create(
 {
        struct lttng_trace_archive_location *location;
 
-       location = (lttng_trace_archive_location *) zmalloc(sizeof(*location));
+       location = zmalloc<lttng_trace_archive_location>();
        if (!location) {
                goto end;
        }
index 766e8b25becb60296b7afb750108c48098dfbda1..4494b31962b7aa760d9fc6043f7d0dabea440bdc 100644 (file)
@@ -44,7 +44,7 @@ struct lttng_log_level_rule *lttng_log_level_rule_exactly_create(
 {
        struct lttng_log_level_rule *rule = NULL;
 
-       rule = (lttng_log_level_rule *) zmalloc(sizeof(struct lttng_log_level_rule));
+       rule = zmalloc<lttng_log_level_rule>();
        if (!rule) {
                goto end;
        }
@@ -77,7 +77,7 @@ lttng_log_level_rule_at_least_as_severe_as_create(int level)
 {
        struct lttng_log_level_rule *rule = NULL;
 
-       rule = (lttng_log_level_rule *) zmalloc(sizeof(struct lttng_log_level_rule));
+       rule = zmalloc<lttng_log_level_rule>();
        if (!rule) {
                goto end;
        }
@@ -227,7 +227,7 @@ struct lttng_log_level_rule *lttng_log_level_rule_copy(
 
        LTTNG_ASSERT(source);
 
-       copy = (lttng_log_level_rule *) zmalloc(sizeof(struct lttng_log_level_rule));
+       copy = zmalloc<lttng_log_level_rule>();
        if (!copy) {
                goto end;
        }
index 47d66936f9b9356c772da348f71ef849850e5dd9..ba8d80bb5abef8f4678343a2c3570157da59ecfc 100644 (file)
@@ -394,7 +394,7 @@ end:
         * We found the length of the section name, now seek back to the
         * beginning of the name and copy it in the newly allocated buffer.
         */
-       name = (char *)zmalloc(sizeof(char) * (name_length + 1));       /* + 1 for \0 */
+       name = calloc<char>((name_length + 1)); /* + 1 for \0 */
        if (!name) {
                PERROR("Error allocating ELF section name buffer");
                goto error;
@@ -495,7 +495,7 @@ int lttng_elf_validate_and_populate(struct lttng_elf *elf)
                goto end;
        }
 
-       elf->ehdr = (lttng_elf_ehdr *) zmalloc(sizeof(struct lttng_elf_ehdr));
+       elf->ehdr = zmalloc<lttng_elf_ehdr>();
        if (!elf->ehdr) {
                PERROR("Error allocation buffer for ELF header");
                ret = LTTNG_ERR_NOMEM;
@@ -548,7 +548,7 @@ struct lttng_elf *lttng_elf_create(int fd)
                goto error;
        }
 
-       elf = (lttng_elf *) zmalloc(sizeof(struct lttng_elf));
+       elf = zmalloc<lttng_elf>();
        if (!elf) {
                PERROR("Error allocating struct lttng_elf");
                goto error;
@@ -664,7 +664,7 @@ char *lttng_elf_get_section_data(struct lttng_elf *elf,
                                max_alloc_size);
                goto error;
        }
-       data = (char *) zmalloc(shdr->sh_size);
+       data = calloc<char>(shdr->sh_size);
        if (!data) {
                PERROR("Error allocating buffer for ELF section data");
                goto error;
index d2b78200e7ebab9e7e6faffd16749f2a88082bae..49f163b42fb5a6c81cc3906f9016a06fac6383a2 100644 (file)
@@ -9,10 +9,13 @@
 #ifndef _MACROS_H
 #define _MACROS_H
 
-#include <stdlib.h>
+#include <common/compat/string.hpp>
+
 #include <stddef.h>
+#include <stdlib.h>
 #include <string.h>
-#include <common/compat/string.hpp>
+
+#include <type_traits>
 
 /*
  * Takes a pointer x and transform it so we can use it to access members
  */
 #define LTTNG_REF(x) ((typeof(*x) *)(x))
 
+#ifdef NDEBUG
+/*
+* Force usage of the assertion condition to prevent unused variable warnings
+* when `assert()` are disabled by the `NDEBUG` definition.
+*/
+# define LTTNG_ASSERT(_cond) ((void) sizeof((void) (_cond), 0))
+#else
+# include <assert.h>
+# define LTTNG_ASSERT(_cond) assert(_cond)
+#endif
+
 /*
  * Memory allocation zeroed
  */
+
 static inline
-void *zmalloc(size_t len)
+void *zmalloc_internal(size_t size)
+{
+       return calloc(1, size);
+}
+
+template <typename T>
+struct can_malloc
+{
+       static constexpr bool value = std::is_trivially_constructible<T>::value;
+};
+
+/*
+ * Malloc and zero-initialize an object of type T, asserting that T can be
+ * safely malloc-ed (is trivially constructible).
+ */
+template<typename T>
+T *zmalloc()
+{
+       static_assert (can_malloc<T>::value, "type can be malloc'ed");
+       return (T *) zmalloc_internal(sizeof(T));
+}
+
+/*
+ * Malloc and zero-initialize a buffer of size `size`, asserting that type T
+ * can be safely malloc-ed (is trivially constructible).
+ */
+template<typename T>
+T *zmalloc(size_t size)
+{
+       static_assert (can_malloc<T>::value, "type can be malloc'ed");
+       LTTNG_ASSERT(size >= sizeof(T));
+       return (T *) zmalloc_internal(size);
+}
+
+/*
+ * Malloc and zero-initialize an array of `nmemb` elements of type T,
+ * asserting that T can be safely malloc-ed (is trivially constructible).
+ */
+template<typename T>
+T *calloc(size_t nmemb)
+{
+       static_assert (can_malloc<T>::value, "type can be malloc'ed");
+       return (T *) zmalloc_internal(nmemb * sizeof(T));
+}
+
+/*
+ * Malloc an object of type T, asserting that T can be safely malloc-ed (is
+ * trivially constructible).
+ */
+template<typename T>
+T *malloc()
 {
-       return calloc(1, len);
+       static_assert (can_malloc<T>::value, "type can be malloc'ed");
+       return (T *) malloc(sizeof(T));
 }
 
+/*
+ * Malloc a buffer of size `size`, asserting that type T can be safely
+ * malloc-ed (is trivially constructible).
+ */
+template<typename T>
+T *malloc(size_t size)
+{
+       static_assert (can_malloc<T>::value, "type can be malloc'ed");
+       return (T *) malloc(size);
+}
+
+/*
+ * Prevent using `free` on types that are non-POD.
+ *
+ * Declare a delete prototype of free if the parameter type is not safe to free
+ * (non-POD).
+ *
+ * If the parameter is a pointer to void, we can't check if what is pointed
+ * to is safe to free or not, as we don't know what is pointed to.  Ideally,
+ * all calls to free would be with a typed pointer, but there are too many
+ * instances of passing a pointer to void to enforce that right now.  So allow
+ * pointers to void, these will not be checked.
+ */
+
+template<typename T>
+struct is_pod_or_void
+{
+       static constexpr bool value = std::is_pod<T>::value || std::is_void<T>::value;
+};
+
+template<typename T, typename = typename std::enable_if<!is_pod_or_void<T>::value>::type>
+void free(T *p) = delete;
+
 #ifndef ARRAY_SIZE
 #define ARRAY_SIZE(array)   (sizeof(array) / (sizeof((array)[0])))
 #endif
@@ -130,15 +229,4 @@ int lttng_strncpy(char *dst, const char *src, size_t dst_len)
        return 0;
 }
 
-#ifdef NDEBUG
-/*
-* Force usage of the assertion condition to prevent unused variable warnings
-* when `assert()` are disabled by the `NDEBUG` definition.
-*/
-# define LTTNG_ASSERT(_cond) ((void) sizeof((void) (_cond), 0))
-#else
-# include <assert.h>
-# define LTTNG_ASSERT(_cond) assert(_cond)
-#endif
-
 #endif /* _MACROS_H */
index 2a1dfa57d942c4b5cec5c259900ee85671f71171..01e89b779811a62be5da524148ba41b21f3cb71a 100644 (file)
@@ -773,7 +773,7 @@ struct mi_writer *mi_lttng_writer_create(int fd_output, int mi_output_type)
 {
        struct mi_writer *mi_writer;
 
-       mi_writer = (struct mi_writer *) zmalloc(sizeof(struct mi_writer));
+       mi_writer = zmalloc<struct mi_writer>();
        if (!mi_writer) {
                PERROR("zmalloc mi_writer_create");
                goto end;
index 248dd42e7529cf3f9ae16fdb69f0d4e2f9c013dc..77e61f21ae60c7a6168ed0feca12fabea758b943 100644 (file)
@@ -24,7 +24,7 @@ struct lttng_notification *lttng_notification_create(
                goto end;
        }
 
-       notification = (lttng_notification *) zmalloc(sizeof(struct lttng_notification));
+       notification = zmalloc<lttng_notification>();
        if (!notification) {
                goto end;
        }
index 1699cc5a6de28d0075002ee0266220399fd8c79d..61e78a5c1d7a583f11b92ce5cbe2e9da20f3c375 100644 (file)
@@ -70,7 +70,7 @@ char *utils_partial_realpath(const char *path)
                        goto error;
                }
 
-               try_path_buf = (char *) zmalloc(LTTNG_PATH_MAX);
+               try_path_buf = zmalloc<char>(LTTNG_PATH_MAX);
                if (!try_path_buf) {
                        PERROR("zmalloc");
                        goto error;
@@ -108,7 +108,7 @@ char *utils_partial_realpath(const char *path)
        }
 
        /* Allocate memory for the resolved path. */
-       resolved_path = (char *) zmalloc(LTTNG_PATH_MAX);
+       resolved_path = zmalloc<char>(LTTNG_PATH_MAX);
        if (resolved_path == NULL) {
                PERROR("zmalloc resolved path");
                goto error;
@@ -288,7 +288,7 @@ char *_utils_expand_path(const char *path, bool keep_symlink)
        }
 
        /* Allocate memory for the absolute_path */
-       absolute_path = (char *) zmalloc(LTTNG_PATH_MAX);
+       absolute_path = zmalloc<char>(LTTNG_PATH_MAX);
        if (absolute_path == NULL) {
                PERROR("zmalloc expand path");
                goto error;
index c2dce78816f0fad0e41a935d49371b20f5bbcd0d..8bf0c1ff33341e54728d3b0b196f62752fc536c6 100644 (file)
@@ -108,7 +108,7 @@ static struct lttng_pipe *_pipe_create(void)
        int ret;
        struct lttng_pipe *p;
 
-       p = (lttng_pipe *) zmalloc(sizeof(*p));
+       p = zmalloc<lttng_pipe>();
        if (!p) {
                PERROR("zmalloc pipe create");
                goto end;
index 28cab7bc5c8d0500f8615e071d1eac758ca1896c..5148bd03a9ed241e1141add72175fcf137e63f86 100644 (file)
@@ -65,7 +65,7 @@ static int send_command(struct lttcomm_relayd_sock *rsock,
                buf_size += size;
        }
 
-       buf = (char *) zmalloc(buf_size);
+       buf = calloc<char>(buf_size);
        if (buf == NULL) {
                PERROR("zmalloc relayd send command buf");
                ret = -1;
@@ -166,7 +166,7 @@ static int relayd_create_session_2_11(struct lttcomm_relayd_sock *rsock,
        base_path_len = strlen(base_path) + 1;
 
        msg_length = sizeof(*msg) + session_name_len + hostname_len + base_path_len;
-       msg = (lttcomm_relayd_create_session_2_11 *) zmalloc(msg_length);
+       msg = zmalloc<lttcomm_relayd_create_session_2_11>(msg_length);
        if (!msg) {
                PERROR("zmalloc create_session_2_11 command message");
                ret = -1;
@@ -446,7 +446,7 @@ static int relayd_add_stream_2_11(struct lttcomm_relayd_sock *rsock,
        pathname_len = strlen(pathname) + 1;
 
        msg_length = sizeof(*msg) + channel_name_len + pathname_len;
-       msg = (lttcomm_relayd_add_stream_2_11 *) zmalloc(msg_length);
+       msg = zmalloc<lttcomm_relayd_add_stream_2_11>(msg_length);
        if (!msg) {
                PERROR("zmalloc add_stream_2_11 command message");
                ret = -1;
index d5b53f2dc29ab31f6ecb99b49b70a64ec1e462bc..6b1201deb6fc032c3dfb7cd4abcb7db6bd8e31fb 100644 (file)
@@ -930,7 +930,7 @@ static int get_user_infos_from_uid(
 
        get_pw_buf_size = (size_t) raw_get_pw_buf_size;
 
-       buf = (char *) zmalloc(get_pw_buf_size);
+       buf = calloc<char>(get_pw_buf_size);
        if (buf == NULL) {
                PERROR("Failed to allocate buffer to get password file entries");
                goto error;
@@ -1458,7 +1458,7 @@ int run_as_create_worker_no_lock(const char *procname,
                ret = 0;
                goto end;
        }
-       worker = (run_as_worker_data *) zmalloc(sizeof(*worker));
+       worker = zmalloc<run_as_worker_data>();
        if (!worker) {
                ret = -ENOMEM;
                goto end;
@@ -1959,7 +1959,7 @@ int run_as_extract_sdt_probe_offsets(int fd, const char* provider_name,
        }
 
        *num_offset = run_as_ret.u.extract_sdt_probe_offsets.num_offset;
-       *offsets = (uint64_t *) zmalloc(*num_offset * sizeof(uint64_t));
+       *offsets = calloc<uint64_t>(*num_offset);
        if (!*offsets) {
                ret = -ENOMEM;
                goto error;
@@ -2001,7 +2001,7 @@ int run_as_generate_filter_bytecode(const char *filter_expression,
 
        view_bytecode = (const struct lttng_bytecode *) run_as_ret.u.generate_filter_bytecode.bytecode;
 
-       local_bytecode = (lttng_bytecode *) zmalloc(sizeof(*local_bytecode) + view_bytecode->len);
+       local_bytecode = calloc<lttng_bytecode>(view_bytecode->len);
        if (!local_bytecode) {
                ret = -ENOMEM;
                goto error;
index 9867de83e73a0f8db63d3d4cb4b060f6b830f21a..a3aa40b3e7ddede7f09cf756284cdaef45d78e02 100644 (file)
@@ -71,7 +71,7 @@ struct lttng_uri *uri_copy(const struct lttng_uri *uri)
                goto end;
        }
 
-       new_uri = (lttng_uri *) zmalloc(sizeof(*new_uri));
+       new_uri = zmalloc<lttng_uri>();
        if (!new_uri) {
                goto end;
        }
@@ -179,8 +179,8 @@ int network_location_set_from_uri_strings(
         * session descriptors expect individually allocated lttng_uris.
         */
        if (uri_count == 2) {
-               control_uri = (lttng_uri *) zmalloc(sizeof(*control_uri));
-               data_uri = (lttng_uri *) zmalloc(sizeof(*data_uri));
+               control_uri = zmalloc<lttng_uri>();
+               data_uri = zmalloc<lttng_uri>();
                if (!control_uri || !data_uri) {
                        ret = -1;
                        goto end;
@@ -208,7 +208,7 @@ lttng_session_descriptor_create(const char *name)
 {
        struct lttng_session_descriptor *descriptor;
 
-       descriptor = (lttng_session_descriptor *) zmalloc(sizeof(*descriptor));
+       descriptor = zmalloc<lttng_session_descriptor>();
        if (!descriptor) {
                goto error;
        }
@@ -334,7 +334,7 @@ _lttng_session_descriptor_snapshot_create(const char *name)
 {
        struct lttng_session_descriptor_snapshot *descriptor;
 
-       descriptor = (lttng_session_descriptor_snapshot *) zmalloc(sizeof(*descriptor));
+       descriptor = zmalloc<lttng_session_descriptor_snapshot>();
        if (!descriptor) {
                goto error;
        }
@@ -477,7 +477,7 @@ _lttng_session_descriptor_live_create(const char *name,
        if (live_timer_interval_us == 0) {
                goto error;
        }
-       descriptor = (lttng_session_descriptor_live *) zmalloc(sizeof(*descriptor));
+       descriptor = zmalloc<lttng_session_descriptor_live>();
        if (!descriptor) {
                goto error;
        }
@@ -709,7 +709,7 @@ skip_name:
                }
 
                uri = (typeof(uri)) current_view.data;
-               uris[i] = (lttng_uri *) zmalloc(sizeof(*uri));
+               uris[i] = zmalloc<lttng_uri>();
                if (!uris[i]) {
                        ret = -1;
                        goto end;
index 7b20007a8ea2ef0068a57cdd6c348043ad0a907c..ed14a9e63ec7af3f721a80d4ee7b1d53d7429eaa 100644 (file)
@@ -178,9 +178,8 @@ error:
  */
 struct lttcomm_sock *lttcomm_alloc_sock(enum lttcomm_sock_proto proto)
 {
-       struct lttcomm_sock *sock;
+       struct lttcomm_sock *sock = zmalloc<lttcomm_sock>();
 
-       sock = (lttcomm_sock *) zmalloc(sizeof(lttcomm_sock));
        if (sock == NULL) {
                PERROR("zmalloc create sock");
                goto end;
@@ -366,11 +365,10 @@ struct lttcomm_relayd_sock *lttcomm_alloc_relayd_sock(struct lttng_uri *uri,
 {
        int ret;
        struct lttcomm_sock *tmp_sock = NULL;
-       struct lttcomm_relayd_sock *rsock = NULL;
+       struct lttcomm_relayd_sock *rsock = zmalloc<lttcomm_relayd_sock>();
 
        LTTNG_ASSERT(uri);
 
-       rsock = (lttcomm_relayd_sock *) zmalloc(sizeof(*rsock));
        if (!rsock) {
                PERROR("zmalloc relayd sock");
                goto error;
index fe11587130be8961da27c4e0484dab8d328bfd9e..288e3a2ae6b60beb404bf6248e509d9370d6aef1 100644 (file)
@@ -85,7 +85,7 @@ static char **alloc_argv_from_user_opts(char *opts, const char *trace_path)
        } while (*token != '\0');
 
        /* Add two here for the NULL terminating element and trace path */
-       argv = (char **) zmalloc(sizeof(char *) * (num_opts + 2));
+       argv = calloc<char *>(num_opts + 2);
        if (argv == NULL) {
                goto error;
        }
@@ -126,7 +126,7 @@ static char **alloc_argv_from_local_opts(const char **opts, size_t opts_len,
                const char *trace_path, bool opt_live_mode)
 {
        char **argv;
-       size_t size, mem_len;
+       size_t mem_len;
 
        /* Add one for the NULL terminating element. */
        mem_len = opts_len + 1;
@@ -138,10 +138,7 @@ static char **alloc_argv_from_local_opts(const char **opts, size_t opts_len,
                mem_len += 1;
        }
 
-       size = sizeof(char *) * mem_len;
-
-       /* Add two here for the trace_path and the NULL terminating element. */
-       argv = (char **) zmalloc(size);
+       argv = calloc<char *>(mem_len);
        if (argv == NULL) {
                goto error;
        }
index 5cfcef2566fec7f3bf5173eb176ddab8cf1735d5..d172aeb4b0fd69aaf3284e00283c2cdcab9cd5ce 100644 (file)
@@ -148,7 +148,7 @@ char *strutils_unescape_string(const char *input, char only_char)
        const char *i;
 
        LTTNG_ASSERT(input);
-       output = (char *) zmalloc(strlen(input) + 1);
+       output = calloc<char>(strlen(input) + 1);
        if (!output) {
                goto end;
        }
@@ -299,7 +299,7 @@ int strutils_split(const char *input,
        for (at = 0, s = input; at < number_of_substrings; at++) {
                const char *ss;
                char *d;
-               char *substring = (char *) zmalloc(longest_substring_len + 1);
+               char *substring = calloc<char>(longest_substring_len + 1);
 
                if (!substring) {
                        goto error;
@@ -385,7 +385,7 @@ int strutils_append_str(char **s, const char *append)
        size_t oldlen = (old == NULL) ? 0 : strlen(old);
        size_t appendlen = strlen(append);
 
-       new_str = (char *) zmalloc(oldlen + appendlen + 1);
+       new_str = zmalloc<char>(oldlen + appendlen + 1);
        if (!new_str) {
                return -ENOMEM;
        }
@@ -415,7 +415,7 @@ int strutils_appendf(char **s, const char *fmt, ...)
        }
 
        /* Allocate space for old string + new string + \0. */
-       new_str = (char *) zmalloc(oldlen + ret + 1);
+       new_str = zmalloc<char>(oldlen + ret + 1);
        if (!new_str) {
                ret = -ENOMEM;
                goto end;
index 2bf1a39623d4ac6700ac48f99bdea254786a1dc1..2d12216d0ed7ceee52526a316c8c502a2116c993 100644 (file)
@@ -203,7 +203,7 @@ struct fs_handle *fs_handle_untracked_create(
                goto end;
        }
 
-       handle = (fs_handle_untracked *) zmalloc(sizeof(typeof(*handle)));
+       handle = zmalloc<fs_handle_untracked>();
        if (!handle) {
                PERROR("Failed to allocate untracked filesystem handle");
                goto end;
@@ -346,7 +346,7 @@ char *generate_chunk_name(uint64_t chunk_id, time_t creation_timestamp,
                        goto error;
                }
        }
-       new_name = (char *) zmalloc(GENERATED_CHUNK_NAME_LEN);
+       new_name = calloc<char>(GENERATED_CHUNK_NAME_LEN);
        if (!new_name) {
                ERR("Failed to allocate buffer for automatically-generated trace chunk name");
                goto error;
@@ -399,7 +399,7 @@ struct lttng_trace_chunk *lttng_trace_chunk_allocate(void)
 {
        struct lttng_trace_chunk *chunk = NULL;
 
-       chunk = (lttng_trace_chunk *) zmalloc(sizeof(*chunk));
+       chunk = zmalloc<lttng_trace_chunk>();
        if (!chunk) {
                ERR("Failed to allocate trace chunk");
                goto end;
@@ -1930,7 +1930,7 @@ struct lttng_trace_chunk_registry *lttng_trace_chunk_registry_create(void)
 {
        struct lttng_trace_chunk_registry *registry;
 
-       registry = (lttng_trace_chunk_registry *) zmalloc(sizeof(*registry));
+       registry = zmalloc<lttng_trace_chunk_registry>();
        if (!registry) {
                goto end;
        }
@@ -1966,7 +1966,7 @@ lttng_trace_chunk_registry_element_create_from_chunk(
                struct lttng_trace_chunk *chunk, uint64_t session_id)
 {
        struct lttng_trace_chunk_registry_element *element =
-               (lttng_trace_chunk_registry_element *) zmalloc(sizeof(*element));
+               zmalloc<lttng_trace_chunk_registry_element>();
 
        if (!element) {
                goto end;
index 6bb84d0cad8175c8a879de39b056e03546099db0..181a0a8c9c69e411136c7e78979aba5af1d4a013 100644 (file)
@@ -71,7 +71,7 @@ enum lttng_error_code process_attr_value_from_comm(
 {
        char *name = NULL;
        enum lttng_error_code ret = LTTNG_OK;
-       struct process_attr_value *value = (process_attr_value *) zmalloc(sizeof(*value));
+       struct process_attr_value *value = zmalloc<process_attr_value>();
 
        if (!value) {
                ret = LTTNG_ERR_NOMEM;
@@ -214,7 +214,7 @@ static void process_attr_tracker_value_destructor(void *ptr)
 
 struct lttng_process_attr_values *lttng_process_attr_values_create(void)
 {
-       struct lttng_process_attr_values *values = (lttng_process_attr_values *) zmalloc(sizeof(*values));
+       struct lttng_process_attr_values *values = zmalloc<lttng_process_attr_values>();
 
        if (!values) {
                goto end;
@@ -426,7 +426,7 @@ struct process_attr_value *process_attr_value_copy(
                goto end;
        }
 
-       new_value = (process_attr_value *) zmalloc(sizeof(*new_value));
+       new_value = zmalloc<process_attr_value>();
        if (!new_value) {
                goto end;
        }
index be2c49b7cd3d79a03dc61eb1ed12e90c23321825..8e6f0734e8c811c7cf4ed9e5e1b64f92d1a8c7ae 100644 (file)
@@ -55,7 +55,7 @@ struct lttng_trigger *lttng_trigger_create(
                goto end;
        }
 
-       trigger = (lttng_trigger *) zmalloc(sizeof(struct lttng_trigger));
+       trigger = zmalloc<lttng_trigger>();
        if (!trigger) {
                goto end;
        }
@@ -505,7 +505,7 @@ struct lttng_triggers *lttng_triggers_create(void)
 {
        struct lttng_triggers *triggers = NULL;
 
-       triggers = (lttng_triggers *) zmalloc(sizeof(*triggers));
+       triggers = zmalloc<lttng_triggers>();
        if (!triggers) {
                goto end;
        }
index b15fe25db9aca76a27127f753ca05df65ac463ad..8e663c46a732116b84c9e5c20615c6c018354034 100644 (file)
@@ -306,7 +306,7 @@ ssize_t uri_parse(const char *str_uri, struct lttng_uri **uris)
        }
 
        /* Allocate URI array */
-       tmp_uris = (lttng_uri *) zmalloc(sizeof(struct lttng_uri) * size);
+       tmp_uris = calloc<lttng_uri>(size);
        if (tmp_uris == NULL) {
                PERROR("zmalloc uri");
                goto error;
@@ -634,7 +634,7 @@ ssize_t uri_parse_str_urls(const char *ctrl_url, const char *data_url,
                goto error;
        }
 
-       tmp_uris = (lttng_uri *) zmalloc(sizeof(struct lttng_uri) * uri_count);
+       tmp_uris = calloc<lttng_uri>(uri_count);
        if (tmp_uris == NULL) {
                PERROR("zmalloc uris");
                goto error;
index 7eb4a6d91117e4632eea619090582a08000705c4..99893b6432cfa687098f28f115e1798a66c61e27 100644 (file)
@@ -72,7 +72,7 @@ lttng_userspace_probe_location_lookup_method_function_elf_create(void)
        struct lttng_userspace_probe_location_lookup_method *ret = NULL;
        struct lttng_userspace_probe_location_lookup_method_elf *elf_method;
 
-       elf_method = (lttng_userspace_probe_location_lookup_method_elf *) zmalloc(sizeof(*elf_method));
+       elf_method = zmalloc<lttng_userspace_probe_location_lookup_method_elf>();
        if (!elf_method) {
                PERROR("zmalloc");
                goto end;
@@ -90,7 +90,7 @@ lttng_userspace_probe_location_lookup_method_tracepoint_sdt_create(void)
        struct lttng_userspace_probe_location_lookup_method *ret = NULL;
        struct lttng_userspace_probe_location_lookup_method_sdt *sdt_method;
 
-       sdt_method = (lttng_userspace_probe_location_lookup_method_sdt *) zmalloc(sizeof(*sdt_method));
+       sdt_method = zmalloc<lttng_userspace_probe_location_lookup_method_sdt>();
        if (!sdt_method) {
                PERROR("zmalloc");
                goto end;
@@ -311,7 +311,7 @@ lttng_userspace_probe_location_function_create_no_check(const char *binary_path,
                goto error;
        }
 
-       location = (lttng_userspace_probe_location_function *) zmalloc(sizeof(*location));
+       location = zmalloc<lttng_userspace_probe_location_function>();
        if (!location) {
                PERROR("Error allocating userspace probe location");
                goto error;
@@ -448,7 +448,7 @@ lttng_userspace_probe_location_tracepoint_create_no_check(const char *binary_pat
                goto error;
        }
 
-       location = (lttng_userspace_probe_location_tracepoint *) zmalloc(sizeof(*location));
+       location = zmalloc<lttng_userspace_probe_location_tracepoint>();
        if (!location) {
                PERROR("zmalloc");
                goto error;
@@ -547,7 +547,7 @@ lttng_userspace_probe_location_lookup_method_function_elf_copy(
        LTTNG_ASSERT(lookup_method->type ==
                        LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_FUNCTION_ELF);
 
-       elf_method = (lttng_userspace_probe_location_lookup_method_elf *) zmalloc(sizeof(*elf_method));
+       elf_method = zmalloc<lttng_userspace_probe_location_lookup_method_elf>();
        if (!elf_method) {
                PERROR("Error allocating ELF userspace probe lookup method");
                goto error;
@@ -574,7 +574,7 @@ lttng_userspace_probe_location_lookup_method_tracepoint_sdt_copy(
        LTTNG_ASSERT(lookup_method->type ==
                        LTTNG_USERSPACE_PROBE_LOCATION_LOOKUP_METHOD_TYPE_TRACEPOINT_SDT);
 
-       sdt_method = (lttng_userspace_probe_location_lookup_method_sdt *) zmalloc(sizeof(*sdt_method));
+       sdt_method = zmalloc<lttng_userspace_probe_location_lookup_method_sdt>();
        if (!sdt_method) {
                PERROR("zmalloc");
                goto error;
index 5e9a442eb5058a98584c432d3bcebb351c25f683..766c9d30c7ff27f1a7ff796043f24aaf2a3ad90a 100644 (file)
@@ -407,7 +407,7 @@ static int create_ust_channel(struct lttng_consumer_channel *channel,
                nr_stream_fds = 1;
        else
                nr_stream_fds = lttng_ust_ctl_get_nr_stream_per_channel();
-       stream_fds = (int *) zmalloc(nr_stream_fds * sizeof(*stream_fds));
+       stream_fds = calloc<int>(nr_stream_fds);
        if (!stream_fds) {
                ret = -1;
                goto error_alloc;
@@ -1286,7 +1286,7 @@ int lttng_ustconsumer_recv_metadata(int sock, uint64_t key, uint64_t offset,
 
        DBG("UST consumer push metadata key %" PRIu64 " of len %" PRIu64, key, len);
 
-       metadata_str = (char *) zmalloc(len * sizeof(char));
+       metadata_str = calloc<char>(len);
        if (!metadata_str) {
                PERROR("zmalloc metadata string");
                ret_code = LTTCOMM_CONSUMERD_ENOMEM;
index eb6b001434300594b3f0af974f565b0d2301959c..b4b7f749f1ef1a6e5286225437f639d01f2966d2 100644 (file)
@@ -171,9 +171,8 @@ void utils_close_pipe(int *src)
  */
 char *utils_strdupdelim(const char *begin, const char *end)
 {
-       char *str;
+       char *str = zmalloc<char>(end - begin + 1);
 
-       str = (char *) zmalloc(end - begin + 1);
        if (str == NULL) {
                PERROR("zmalloc strdupdelim");
                goto error;
@@ -784,7 +783,7 @@ char *utils_get_user_home_dir(uid_t uid)
                goto end;
        }
 retry:
-       buf = (char *) zmalloc(buflen);
+       buf = zmalloc<char>(buflen);
        if (!buf) {
                goto end;
        }
@@ -934,7 +933,7 @@ char *utils_generate_optstring(const struct option *long_options,
                string_len += long_options[i].has_arg ? 1 : 0;
        }
 
-       optstring = (char *) zmalloc(string_len);
+       optstring = zmalloc<char>(string_len);
        if (!optstring) {
                goto end;
        }
@@ -1159,7 +1158,7 @@ enum lttng_error_code utils_user_id_from_name(const char *user_name, uid_t *uid)
                buflen = FALLBACK_USER_BUFLEN;
        }
 
-       buf = (char *) zmalloc(buflen);
+       buf = zmalloc<char>(buflen);
        if (!buf) {
                ret_val = LTTNG_ERR_NOMEM;
                goto end;
@@ -1173,7 +1172,7 @@ enum lttng_error_code utils_user_id_from_name(const char *user_name, uid_t *uid)
                case ERANGE:
                        buflen *= 2;
                        free(buf);
-                       buf = (char *) zmalloc(buflen);
+                       buf = zmalloc<char>(buflen);
                        if (!buf) {
                                ret_val = LTTNG_ERR_NOMEM;
                                goto end;
@@ -1224,7 +1223,7 @@ enum lttng_error_code utils_group_id_from_name(
                buflen = FALLBACK_GROUP_BUFLEN;
        }
 
-       buf = (char *) zmalloc(buflen);
+       buf = zmalloc<char>(buflen);
        if (!buf) {
                ret_val = LTTNG_ERR_NOMEM;
                goto end;
@@ -1238,7 +1237,7 @@ enum lttng_error_code utils_group_id_from_name(
                case ERANGE:
                        buflen *= 2;
                        free(buf);
-                       buf = (char *) zmalloc(buflen);
+                       buf = zmalloc<char>(buflen);
                        if (!buf) {
                                ret_val = LTTNG_ERR_NOMEM;
                                goto end;
index 080dbb4439659a33c10dc052e81f21b56251b4c9..3f3c53996ff2f461dda6b0d0030ee5f5dad89781 100644 (file)
@@ -143,12 +143,12 @@ struct lttng_notification_channel *lttng_notification_channel_create(
                goto end;
        }
 
-       sock_path = (char *) zmalloc(LTTNG_PATH_MAX);
+       sock_path = calloc<char>(LTTNG_PATH_MAX);
        if (!sock_path) {
                goto end;
        }
 
-       channel = (lttng_notification_channel *) zmalloc(sizeof(struct lttng_notification_channel));
+       channel = zmalloc<lttng_notification_channel>();
        if (!channel) {
                goto end;
        }
@@ -343,7 +343,7 @@ int enqueue_dropped_notification(
                goto end;
        }
 
-       pending_notification = (struct pending_notification *) zmalloc(sizeof(*pending_notification));
+       pending_notification = zmalloc<struct pending_notification>();
        if (!pending_notification) {
                ret = -1;
                goto end;
@@ -371,7 +371,7 @@ int enqueue_notification_from_current_message(
                goto end;
        }
 
-       pending_notification = (struct pending_notification *) zmalloc(sizeof(*pending_notification));
+       pending_notification = zmalloc<struct pending_notification>();
        if (!pending_notification) {
                ret = -1;
                goto error;
index 114758b0c8f3a38296600e9bba47d28929ccc0f2..b7a312be583e6750df64d2872f379c4fce4cfd52 100644 (file)
@@ -64,7 +64,7 @@ static
 struct lttng_clear_handle *lttng_clear_handle_create(int sessiond_socket)
 {
        int ret;
-       struct lttng_clear_handle *handle = (lttng_clear_handle *) zmalloc(sizeof(*handle));
+       struct lttng_clear_handle *handle = zmalloc<lttng_clear_handle>();
 
        if (!handle) {
                goto end;
index d937b2c73c3693a26dadb38962363b34323625d0..3882a587e830e12e61926b38c852ff7d08b9fb8d 100644 (file)
@@ -69,7 +69,7 @@ struct lttng_destruction_handle *lttng_destruction_handle_create(
                int sessiond_socket)
 {
        int ret;
-       struct lttng_destruction_handle *handle = (lttng_destruction_handle *) zmalloc(sizeof(*handle));
+       struct lttng_destruction_handle *handle = zmalloc<lttng_destruction_handle>();
 
        if (!handle) {
                goto end;
index e89aae4829464d4fed25d70354c41b64df40365d..c33adf1197e15485469921417f5654c3958028b5 100644 (file)
@@ -24,13 +24,13 @@ struct lttng_event *lttng_event_create(void)
        struct lttng_event *event;
        struct lttng_event_extended *event_extended;
 
-       event = (lttng_event *) zmalloc(sizeof(*event));
+       event = zmalloc<lttng_event>();
        if (!event) {
                PERROR("Error allocating event structure");
                goto end;
        }
 
-       event_extended = (lttng_event_extended *) zmalloc(sizeof(*event_extended));
+       event_extended = zmalloc<lttng_event_extended>();
        if (!event_extended) {
                PERROR("Error allocating event extended structure");
                goto error;
index 4a07f4212a463439ec80a1986b1fc9ea720c0ff6..02e2a6ff901a1e4d2fba83f426e644767cae41f8 100644 (file)
@@ -22,7 +22,7 @@
 
 struct lttng_load_session_attr *lttng_load_session_attr_create(void)
 {
-       return (lttng_load_session_attr *) zmalloc(sizeof(struct lttng_load_session_attr));
+       return zmalloc<lttng_load_session_attr>();
 }
 
 static
@@ -272,8 +272,7 @@ int lttng_load_session_attr_set_override_ctrl_url(
        }
 
        if (!attr->override_attr) {
-               attr->override_attr = (config_load_session_override_attr *) zmalloc(
-                       sizeof(struct config_load_session_override_attr));
+               attr->override_attr = zmalloc<config_load_session_override_attr>();
                if (!attr->override_attr) {
                        ret = -LTTNG_ERR_NOMEM;
                        goto end;
@@ -303,7 +302,7 @@ int lttng_load_session_attr_set_override_ctrl_url(
                uri[0].port = DEFAULT_NETWORK_CONTROL_PORT;
        }
 
-       url_str = (char *) zmalloc(PATH_MAX);
+       url_str = calloc<char>(PATH_MAX);
        if (!url_str) {
                /* FIXME: return valid error */
                ret = -LTTNG_ERR_NOMEM;
@@ -357,8 +356,7 @@ int lttng_load_session_attr_set_override_data_url(
        }
 
        if (!attr->override_attr) {
-               attr->override_attr = (config_load_session_override_attr *) zmalloc(
-                       sizeof(struct config_load_session_override_attr));
+               attr->override_attr = zmalloc<config_load_session_override_attr>();
                if (!attr->override_attr) {
                        ret = -LTTNG_ERR_NOMEM;
                        goto end;
@@ -388,7 +386,7 @@ int lttng_load_session_attr_set_override_data_url(
                uri[0].port = DEFAULT_NETWORK_DATA_PORT;
        }
 
-       url_str = (char *) zmalloc(PATH_MAX);
+       url_str = calloc<char>(PATH_MAX);
        if (!url_str) {
                ret = -LTTNG_ERR_NOMEM;
                goto end;
@@ -446,8 +444,7 @@ int lttng_load_session_attr_set_override_url(
        }
 
        if (!attr->override_attr) {
-               attr->override_attr = (config_load_session_override_attr *) zmalloc(
-                       sizeof(struct config_load_session_override_attr));
+               attr->override_attr = zmalloc<config_load_session_override_attr>();
                if (!attr->override_attr) {
                        ret = -LTTNG_ERR_NOMEM;
                        goto end;
@@ -583,8 +580,7 @@ int lttng_load_session_attr_set_override_session_name(
        }
 
        if (!attr->override_attr) {
-               attr->override_attr = (config_load_session_override_attr *) zmalloc(
-                       sizeof(struct config_load_session_override_attr));
+               attr->override_attr = zmalloc<config_load_session_override_attr>();
                if (!attr->override_attr) {
                        ret = -LTTNG_ERR_NOMEM;
                        goto end;
index 4821548e515c032a636b9d765f9e42429403cd33..e3234d5d4e3ef75a70761ea20420cf500f356b8a 100644 (file)
@@ -231,7 +231,7 @@ struct lttng_health *lttng_health_create(enum health_component hc,
        struct lttng_health *lh;
        int i;
 
-       lh = (lttng_health *) zmalloc(sizeof(*lh) + sizeof(lh->thread[0]) * nr_threads);
+       lh = zmalloc<lttng_health>(sizeof(*lh) + sizeof(lh->thread[0]) * nr_threads);
        if (!lh) {
                return NULL;
        }
index c5d47ebdc53d66b2182a6656b2ecb955fdf91942..057a91e3e57f73f0b0afc5fd26e8c9f731efbb1e 100644 (file)
@@ -266,7 +266,7 @@ int lttng_check_tracing_group(void)
        }
 
        /* Alloc group list of the right size */
-       grp_list = (gid_t *) zmalloc(grp_list_size * sizeof(gid_t));
+       grp_list = calloc<gid_t>(grp_list_size);
        if (!grp_list) {
                PERROR("malloc");
                goto end;
@@ -500,7 +500,7 @@ static int recv_sessiond_optional_data(size_t len, void **user_buf,
        size_t *user_len)
 {
        int ret = 0;
-       void *buf = NULL;
+       char *buf = NULL;
 
        if (len) {
                if (!user_len) {
@@ -508,7 +508,7 @@ static int recv_sessiond_optional_data(size_t len, void **user_buf,
                        goto end;
                }
 
-               buf = zmalloc(len);
+               buf = zmalloc<char>(len);
                if (!buf) {
                        ret = -ENOMEM;
                        goto end;
@@ -729,7 +729,7 @@ struct lttng_handle *lttng_create_handle(const char *session_name,
        int ret;
        struct lttng_handle *handle = NULL;
 
-       handle = (lttng_handle *) zmalloc(sizeof(struct lttng_handle));
+       handle = zmalloc<lttng_handle>();
        if (handle == NULL) {
                PERROR("malloc handle");
                goto end;
@@ -1576,13 +1576,13 @@ int lttng_enable_channel(struct lttng_handle *handle,
        /* Populate the channel extended attribute if necessary. */
        if (!channel->attr.extended.ptr) {
                struct lttng_channel_extended *extended =
-                               (struct lttng_channel_extended *) zmalloc(
-                                               sizeof(*extended));
+                               zmalloc<lttng_channel_extended>();
 
                if (!extended) {
                        ret = -LTTNG_ERR_NOMEM;
                        goto end;
                }
+
                lttng_channel_set_default_extended_attr(
                                &handle->domain, extended);
                channel->attr.extended.ptr = extended;
index b6a66392af2cd2e492d7f7eec0af567ed8d71f0d..106b8fb489947be591f31e6e44ab863f815ee9d3 100644 (file)
@@ -230,7 +230,7 @@ int lttng_rotate_session(const char *session_name,
                goto end;
        }
 
-       *rotation_handle = (lttng_rotation_handle *) zmalloc(sizeof(struct lttng_rotation_handle));
+       *rotation_handle = zmalloc<lttng_rotation_handle>();
        if (!*rotation_handle) {
                ret = -LTTNG_ERR_NOMEM;
                goto end;
@@ -350,7 +350,7 @@ end:
 static
 struct lttng_rotation_schedules *lttng_rotation_schedules_create(void)
 {
-       return (lttng_rotation_schedules *) zmalloc(sizeof(struct lttng_rotation_schedules));
+       return zmalloc<lttng_rotation_schedules>();
 }
 
 static
@@ -463,7 +463,7 @@ lttng_rotation_schedule_size_threshold_create(void)
 {
        struct lttng_rotation_schedule_size_threshold *schedule;
 
-       schedule = (lttng_rotation_schedule_size_threshold *) zmalloc(sizeof(*schedule));
+       schedule = zmalloc<lttng_rotation_schedule_size_threshold>();
        if (!schedule) {
                goto end;
        }
@@ -529,7 +529,7 @@ lttng_rotation_schedule_periodic_create(void)
 {
        struct lttng_rotation_schedule_periodic *schedule;
 
-       schedule = (lttng_rotation_schedule_periodic *) zmalloc(sizeof(*schedule));
+       schedule = zmalloc<lttng_rotation_schedule_periodic>();
        if (!schedule) {
                goto end;
        }
index 7843df300699afded1d46ed8da083f60d8fc4c49..32fcb1c2d772d968252e4a4706f15f468916784c 100644 (file)
@@ -17,7 +17,7 @@
 
 struct lttng_save_session_attr *lttng_save_session_attr_create(void)
 {
-       return (lttng_save_session_attr *) zmalloc(sizeof(struct lttng_save_session_attr));
+       return zmalloc<lttng_save_session_attr>();
 }
 
 void lttng_save_session_attr_destroy(struct lttng_save_session_attr *output)
index b9bac9aa84b0c2d3cc90c4efcf6593922dbbc1af..baec7357f6b8c3becf5a90df7937ed63aba64810 100644 (file)
@@ -120,7 +120,7 @@ int lttng_snapshot_list_output(const char *session_name,
                goto error;
        }
 
-       new_list = (lttng_snapshot_output_list *) zmalloc(sizeof(*new_list));
+       new_list = zmalloc<lttng_snapshot_output_list>();
        if (!new_list) {
                ret = -LTTNG_ERR_NOMEM;
                goto error;
@@ -240,7 +240,7 @@ struct lttng_snapshot_output *lttng_snapshot_output_create(void)
 {
        struct lttng_snapshot_output *output;
 
-       output = (lttng_snapshot_output *) zmalloc(sizeof(struct lttng_snapshot_output));
+       output = zmalloc<lttng_snapshot_output>();
        if (!output) {
                goto error;
        }
index 53deced1d36172bb678e40234149dcae23b6b8b4..4930e94ce57610469f9fcc9558425556b31d3cfd 100644 (file)
@@ -53,7 +53,7 @@ enum lttng_error_code lttng_session_get_tracker_handle(const char *session_name,
                goto error;
        }
 
-       handle = (lttng_process_attr_tracker_handle *) zmalloc(sizeof(*handle));
+       handle = zmalloc<lttng_process_attr_tracker_handle>();
        if (!handle) {
                ret_code = LTTNG_ERR_NOMEM;
                goto error;
@@ -779,7 +779,7 @@ int lttng_list_tracker_pids(struct lttng_handle *handle,
                goto end;
        }
 
-       pid_array = (int32_t *) zmalloc(pid_count * sizeof(int32_t));
+       pid_array = calloc<int32_t>(pid_count);
        if (!pid_array) {
                ret_code = LTTNG_ERR_NOMEM;
                goto end;
index 439d862d4b0fbbaf117dd2fa0be3fffa5699b9c6..2da5b6fe4e069911af17dbda6bb386a1873f3686 100644 (file)
@@ -285,7 +285,7 @@ int attach_session(uint64_t id)
        int i;
        ssize_t ret_len;
 
-       session = (live_session *) zmalloc(sizeof(struct live_session));
+       session = zmalloc<live_session>();
        if (!session) {
                goto error;
        }
@@ -327,8 +327,7 @@ int attach_session(uint64_t id)
                diag("Got session stream count == 0");
                goto error;
        }
-       session->streams = (viewer_stream *) zmalloc(session->stream_count *
-                       sizeof(struct viewer_stream));
+       session->streams = calloc<viewer_stream>(session->stream_count);
        if (!session->streams) {
                goto error;
        }
@@ -436,7 +435,7 @@ retry:
                goto error;
        }
 
-       data = (char *) zmalloc(len);
+       data = calloc<char>(len);
        if (!data) {
                PERROR("relay data zmalloc");
                goto error;
index 9cfdac4f31c08473d82ae10ad206dc2c28577191..35d0c82eb2979724d26e1b54efd0e849c54186b1 100644 (file)
@@ -165,7 +165,7 @@ static void test_create_ust_event_exclusion(void)
        ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
 
        /* set up an exclusion set */
-       exclusion = (lttng_event_exclusion *) zmalloc(sizeof(*exclusion) +
+       exclusion = zmalloc<lttng_event_exclusion>(sizeof(*exclusion) +
                LTTNG_SYMBOL_NAME_LEN * exclusion_count);
        ok(exclusion != NULL, "Create UST exclusion");
        if (!exclusion) {
@@ -185,7 +185,7 @@ static void test_create_ust_event_exclusion(void)
 
        ok(ret != LTTNG_OK, "Create UST event with identical exclusion names fails");
 
-       exclusion = (lttng_event_exclusion *) zmalloc(sizeof(*exclusion) +
+       exclusion = zmalloc<lttng_event_exclusion>(sizeof(*exclusion) +
                LTTNG_SYMBOL_NAME_LEN * exclusion_count);
        ok(exclusion != NULL, "Create UST exclusion");
        if (!exclusion) {
@@ -193,7 +193,7 @@ static void test_create_ust_event_exclusion(void)
                goto end;
        }
 
-       exclusion_copy = (lttng_event_exclusion *) zmalloc(sizeof(*exclusion) +
+       exclusion_copy = zmalloc<lttng_event_exclusion>(sizeof(*exclusion) +
                LTTNG_SYMBOL_NAME_LEN * exclusion_count);
        if (!exclusion_copy) {
                skip(2, "zmalloc failed");
index 3cb1a81604c585ae12fe898ebbb0109deffb8586..d11c2d9198d46605f54bab9073c1a8c7bdd03d42 100644 (file)
@@ -132,14 +132,14 @@ static int prepare_valid_results(void)
        }
 
        /* allocate memory for the expected results */
-       valid_tests_expected_results = (char **) zmalloc(sizeof(char *) * num_valid_tests);
+       valid_tests_expected_results = calloc<char *>(num_valid_tests);
        if (!valid_tests_expected_results) {
                PRINT_ERR("out of memory");
                ret = -1;
                goto end;
        }
        for (i = 0; i < num_valid_tests; i++) {
-               valid_tests_expected_results[i] = (char *) malloc(PATH_MAX);
+               valid_tests_expected_results[i] = calloc<char>(PATH_MAX);
                if (valid_tests_expected_results[i] == NULL) {
                        PRINT_ERR("malloc expected results");
                        ret = -1;
This page took 0.150626 seconds and 4 git commands to generate.