return ret;
}
src_file_len = layout->mmap_length;
- buf = (char *) zmalloc(src_file_len);
+ buf = calloc<char>(src_file_len);
if (!buf) {
return -1;
}
}
if (S_ISDIR(st.st_mode)) {
- char *subpath = (char *) zmalloc(PATH_MAX);
+ char *subpath = calloc<char>(PATH_MAX);
if (!subpath) {
PERROR("zmalloc 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;
{
struct relay_connection *conn;
- conn = (relay_connection *) zmalloc(sizeof(*conn));
+ conn = zmalloc<relay_connection>();
if (!conn) {
PERROR("zmalloc relay connection");
goto end;
{
struct ctf_trace *trace;
- trace = (ctf_trace *) zmalloc(sizeof(*trace));
+ trace = zmalloc<ctf_trace>();
if (!trace) {
PERROR("Failed to allocate ctf_trace");
goto end;
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;
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;
}
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",
}
reply.len = htobe64(len);
- data = (char *) zmalloc(len);
+ data = zmalloc<char>(len);
if (!data) {
PERROR("viewer metadata zmalloc");
goto error;
goto error;
}
- session = (relay_session *) zmalloc(sizeof(*session));
+ session = zmalloc<relay_session>();
if (!session) {
PERROR("Failed to allocate session");
goto error;
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;
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;
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;
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;
}
{
struct relay_viewer_session *vsession;
- vsession = (relay_viewer_session *) zmalloc(sizeof(*vsession));
+ vsession = zmalloc<relay_viewer_session>();
if (!vsession) {
goto end;
}
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;
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;
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));
struct thread_notifiers *notifiers;
struct lttng_thread *thread;
- notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers));
+ notifiers = zmalloc<thread_notifiers>();
if (!notifiers) {
goto error_alloc;
}
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;
}
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;
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;
}
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;
}
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;
LTTNG_ASSERT(sock);
- app = (agent_app *) zmalloc(sizeof(*app));
+ app = zmalloc<agent_app>();
if (!app) {
PERROR("Failed to allocate agent application instance");
goto error;
int ret;
struct agent *agt;
- agt = (agent *) zmalloc(sizeof(struct agent));
+ agt = zmalloc<agent>();
if (!agt) {
goto error;
}
goto error;
}
- event = (agent_event *) zmalloc(sizeof(*event));
+ event = zmalloc<agent_event>();
if (!event) {
goto error;
}
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;
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;
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;
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;
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;
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;
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;
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;
goto error;
}
- uris = (lttng_uri *) zmalloc(len);
+ uris = calloc<lttng_uri>(nb_uri);
if (uris == NULL) {
ret = LTTNG_ERR_FATAL;
goto error;
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) {
}
}
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;
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;
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;
}
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;
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;
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;
* 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;
}
LTTNG_ASSERT(fd);
- socket = (consumer_socket *) zmalloc(sizeof(struct consumer_socket));
+ socket = zmalloc<consumer_socket>();
if (socket == NULL) {
PERROR("zmalloc consumer socket");
goto error;
{
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;
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);
struct lttng_thread *thread;
struct thread_notifiers *notifiers;
- notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers));
+ notifiers = zmalloc<thread_notifiers>();
if (!notifiers) {
goto error;
}
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;
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,
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,
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,
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;
struct thread_notifiers *notifiers;
struct lttng_thread *thread;
- notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers));
+ notifiers = zmalloc<thread_notifiers>();
if (!notifiers) {
goto error_alloc;
}
* 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;
}
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");
LTTNG_ASSERT(ht);
- ksyscall = (struct syscall *) zmalloc(sizeof(*ksyscall));
+ ksyscall = zmalloc<struct syscall>();
if (!ksyscall) {
ret = -LTTNG_ERR_NOMEM;
goto error;
* 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;
struct thread_notifiers *notifiers = NULL;
struct lttng_thread *thread;
- notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers));
+ notifiers = zmalloc<thread_notifiers>();
if (!notifiers) {
goto error_alloc;
}
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);
struct thread_notifiers *notifiers = NULL;
struct lttng_thread *thread;
- notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers));
+ notifiers = zmalloc<thread_notifiers>();
if (!notifiers) {
goto error_alloc;
}
struct thread_notifiers *notifiers = NULL;
struct lttng_thread *thread;
- notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers));
+ notifiers = zmalloc<thread_notifiers>();
if (!notifiers) {
goto error_alloc;
}
/* 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;
/* 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;
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;
/* 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;
{
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;
}
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;
LTTNG_ASSERT(name);
- session_info = (struct session_info *) zmalloc(sizeof(*session_info));
+ session_info = zmalloc<struct session_info>();
if (!session_info) {
goto end;
}
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;
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;
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;
}
}
}
- 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;
{
struct lttng_session_trigger_list *list;
- list = (lttng_session_trigger_list *) zmalloc(sizeof(*list));
+ list = zmalloc<lttng_session_trigger_list>();
if (!list) {
goto end;
}
{
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;
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;
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;
}
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;
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;
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;
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;
DBG("Handling new notification channel client connection");
- client = (notification_client *) zmalloc(sizeof(*client));
+ client = zmalloc<notification_client>();
if (!client) {
/* Fatal error. */
ret = -1;
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;
*/
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;
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;
}
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;
}
struct thread_notifiers *notifiers;
struct lttng_pipe *quit_pipe;
- notifiers = (thread_notifiers *) zmalloc(sizeof(*notifiers));
+ notifiers = zmalloc<thread_notifiers>();
if (!notifiers) {
goto error_alloc;
}
(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);
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;
}
{
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;
{
struct rotation_thread_handle *handle;
- handle = (rotation_thread_handle *) zmalloc(sizeof(*handle));
+ handle = zmalloc<rotation_thread_handle>();
if (!handle) {
goto end;
}
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);
{
char *uri;
- uri = (char *) zmalloc(PATH_MAX);
+ uri = calloc<char>(PATH_MAX);
if (!uri) {
ret = LTTNG_ERR_NOMEM;
goto end;
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;
struct snapshot_output *snapshot_output_alloc(void)
{
- return (snapshot_output *) zmalloc(sizeof(struct snapshot_output));
+ return zmalloc<snapshot_output>();
}
/*
int ret;
struct lttng_thread *thread;
- thread = (lttng_thread *) zmalloc(sizeof(*thread));
+ thread = zmalloc<lttng_thread>();
if (!thread) {
goto error_alloc;
}
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;
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;
{
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
{
struct process_attr_tracker *tracker;
- tracker = (process_attr_tracker *) zmalloc(sizeof(*tracker));
+ tracker = zmalloc<process_attr_tracker>();
if (!tracker) {
return NULL;
}
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;
}
/* 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;
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;
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;
{
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;
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;
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;
{
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;
}
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;
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;
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;
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 {
goto error;
}
- lta = (ust_app *) zmalloc(sizeof(struct ust_app));
+ lta = zmalloc<ust_app>();
if (lta == NULL) {
PERROR("malloc");
goto error_free_pipe;
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;
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;
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];
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
return NULL;
}
- event = (ust_registry_event *) zmalloc(sizeof(*event));
+ event = zmalloc<ust_registry_event>();
if (!event) {
PERROR("zmalloc ust registry event");
goto error;
}
/* 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;
LTTNG_ASSERT(session);
- chan = (ust_registry_channel *) zmalloc(sizeof(*chan));
+ chan = zmalloc<ust_registry_channel>();
if (!chan) {
PERROR("zmalloc ust registry channel");
ret = -ENOMEM;
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;
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);
}
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;
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;
}
length += sizeof(preamble);
- ret = (char *) zmalloc(length);
+ ret = calloc<char>(length);
if (!ret) {
return NULL;
}
}
/* 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");
#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");
* 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;
*/
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;
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;
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;
}
goto error;
}
- path = (lttng_action_path *) zmalloc(sizeof(*path));
+ path = zmalloc<lttng_action_path>();
if (!path) {
goto error;
}
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;
}
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;
}
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;
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,
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(
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;
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,
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(
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;
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,
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(
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;
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,
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(
#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
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;
}
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;
}
*channel = *src;
if (src->attr.extended.ptr) {
- extended = (struct lttng_channel_extended *) zmalloc(
- sizeof(*extended));
+ extended = zmalloc<lttng_channel_extended>();
if (!extended) {
goto end;
}
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;
}
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) {
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;
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;
/*
* 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;
}
}
/* 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");
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;
navail = n + 1;
}
- ret = (char *) malloc(navail);
+ ret = malloc<char>(navail);
if (!ret) {
goto end;
}
{
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;
}
{
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;
}
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;
}
goto end;
}
- descriptor = (lttng_capture_descriptor *) malloc(sizeof(*descriptor));
+ descriptor = malloc<lttng_capture_descriptor>();
if (descriptor == NULL) {
status = LTTNG_CONDITION_STATUS_ERROR;
goto end;
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;
}
{
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;
}
{
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;
}
{
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;
}
{
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;
}
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;
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;
}
continue;
}
- exclusions = (char **) zmalloc(exclusion_count * sizeof(char *));
+ exclusions = calloc<char *>(exclusion_count);
if (!exclusions) {
exclusion_count = 0;
ret = -LTTNG_ERR_NOMEM;
/* 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;
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;
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;
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;
}
}
- channel = (lttng_consumer_channel *) zmalloc(sizeof(*channel));
+ channel = zmalloc<lttng_consumer_channel>();
if (channel == NULL) {
PERROR("malloc struct lttng_consumer_channel");
goto end;
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;
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;
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);
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;
}
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;
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;
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;
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;
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;
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;
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");
{
struct lttng_event_expr *expr;
- expr = (lttng_event_expr *) zmalloc(size);
+ expr = zmalloc<lttng_event_expr>(size);
if (!expr) {
goto end;
}
{
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
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;
}
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;
* 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;
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;
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;
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;
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;
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;
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;
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;
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;
goto end;
}
- handle = (fd_handle *) zmalloc(sizeof(*handle));
+ handle = zmalloc<fd_handle>();
if (!handle) {
PERROR("Failed to allocate fd_handle");
goto end;
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;
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;
}
}
- handle = (fs_handle_tracked *) zmalloc(sizeof(*handle));
+ handle = zmalloc<fs_handle_tracked>();
if (!handle) {
goto end;
}
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;
* 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;
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;
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;
}
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;
goto end;
}
- it = (bytecode_symbol_iterator *) zmalloc(sizeof(*it));
+ it = zmalloc<bytecode_symbol_iterator>();
if (!it) {
goto end;
}
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;
}
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));
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));
{
struct filter_ast *ast;
- ast = (filter_ast *) zmalloc(sizeof(*ast));
+ ast = zmalloc<filter_ast>();
if (!ast)
return NULL;
memset(ast, 0, sizeof(*ast));
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));
{
struct ir_op *op;
- op = (ir_op *) zmalloc(sizeof(struct ir_op));
+ op = zmalloc<ir_op>();
if (!op)
return NULL;
switch (child->data_type) {
{
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;
{
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;
{
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;
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;
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;
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;
}
/* 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;
{
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;
goto error;
}
- op = (ir_op *) zmalloc(sizeof(struct ir_op));
+ op = zmalloc<ir_op>();
if (!op)
return NULL;
op->op = IR_OP_UNARY;
goto error;
}
- op = (ir_op *) zmalloc(sizeof(struct ir_op));
+ op = zmalloc<ir_op>();
if (!op)
return NULL;
op->op = IR_OP_BINARY;
goto error;
}
- op = (ir_op *) zmalloc(sizeof(struct ir_op));
+ op = zmalloc<ir_op>();
if (!op)
return NULL;
op->op = IR_OP_LOGICAL;
goto error;
}
- op = (ir_op *) zmalloc(sizeof(struct ir_op));
+ op = zmalloc<ir_op>();
if (!op)
return NULL;
op->op = IR_OP_BINARY;
}
pthread_mutex_unlock(&seed_lock);
- ht = (lttng_ht *) zmalloc(sizeof(*ht));
+ ht = zmalloc<lttng_ht>();
if (ht == NULL) {
PERROR("zmalloc lttng_ht");
goto error;
{
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;
}
{
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;
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;
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;
goto end;
}
- lower_str = (char *) zmalloc(len + 1);
+ lower_str = zmalloc<char>(len + 1);
if (!lower_str) {
PERROR("zmalloc");
ret = -errno;
int error = 0;
#if !INI_USE_STACK
- line = (char*)zmalloc(INI_MAX_LINE);
+ line = zmalloc<char>(INI_MAX_LINE);
if (!line) {
return -2;
}
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;
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;
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;
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;
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;
{
struct lttng_trace_archive_location *location;
- location = (lttng_trace_archive_location *) zmalloc(sizeof(*location));
+ location = zmalloc<lttng_trace_archive_location>();
if (!location) {
goto end;
}
{
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;
}
{
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;
}
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;
}
* 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;
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;
goto error;
}
- elf = (lttng_elf *) zmalloc(sizeof(struct lttng_elf));
+ elf = zmalloc<lttng_elf>();
if (!elf) {
PERROR("Error allocating struct lttng_elf");
goto error;
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;
#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
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 */
{
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;
goto end;
}
- notification = (lttng_notification *) zmalloc(sizeof(struct lttng_notification));
+ notification = zmalloc<lttng_notification>();
if (!notification) {
goto end;
}
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;
}
/* 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;
}
/* 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;
int ret;
struct lttng_pipe *p;
- p = (lttng_pipe *) zmalloc(sizeof(*p));
+ p = zmalloc<lttng_pipe>();
if (!p) {
PERROR("zmalloc pipe create");
goto end;
buf_size += size;
}
- buf = (char *) zmalloc(buf_size);
+ buf = calloc<char>(buf_size);
if (buf == NULL) {
PERROR("zmalloc relayd send command buf");
ret = -1;
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;
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;
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;
ret = 0;
goto end;
}
- worker = (run_as_worker_data *) zmalloc(sizeof(*worker));
+ worker = zmalloc<run_as_worker_data>();
if (!worker) {
ret = -ENOMEM;
goto end;
}
*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;
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;
goto end;
}
- new_uri = (lttng_uri *) zmalloc(sizeof(*new_uri));
+ new_uri = zmalloc<lttng_uri>();
if (!new_uri) {
goto end;
}
* 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;
{
struct lttng_session_descriptor *descriptor;
- descriptor = (lttng_session_descriptor *) zmalloc(sizeof(*descriptor));
+ descriptor = zmalloc<lttng_session_descriptor>();
if (!descriptor) {
goto error;
}
{
struct lttng_session_descriptor_snapshot *descriptor;
- descriptor = (lttng_session_descriptor_snapshot *) zmalloc(sizeof(*descriptor));
+ descriptor = zmalloc<lttng_session_descriptor_snapshot>();
if (!descriptor) {
goto error;
}
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;
}
}
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;
*/
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;
{
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;
} 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;
}
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;
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;
}
const char *i;
LTTNG_ASSERT(input);
- output = (char *) zmalloc(strlen(input) + 1);
+ output = calloc<char>(strlen(input) + 1);
if (!output) {
goto end;
}
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;
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;
}
}
/* 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;
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;
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;
{
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;
{
struct lttng_trace_chunk_registry *registry;
- registry = (lttng_trace_chunk_registry *) zmalloc(sizeof(*registry));
+ registry = zmalloc<lttng_trace_chunk_registry>();
if (!registry) {
goto end;
}
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;
{
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;
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;
goto end;
}
- new_value = (process_attr_value *) zmalloc(sizeof(*new_value));
+ new_value = zmalloc<process_attr_value>();
if (!new_value) {
goto end;
}
goto end;
}
- trigger = (lttng_trigger *) zmalloc(sizeof(struct lttng_trigger));
+ trigger = zmalloc<lttng_trigger>();
if (!trigger) {
goto end;
}
{
struct lttng_triggers *triggers = NULL;
- triggers = (lttng_triggers *) zmalloc(sizeof(*triggers));
+ triggers = zmalloc<lttng_triggers>();
if (!triggers) {
goto end;
}
}
/* 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;
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;
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;
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;
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;
goto error;
}
- location = (lttng_userspace_probe_location_tracepoint *) zmalloc(sizeof(*location));
+ location = zmalloc<lttng_userspace_probe_location_tracepoint>();
if (!location) {
PERROR("zmalloc");
goto error;
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;
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;
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;
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;
*/
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;
goto end;
}
retry:
- buf = (char *) zmalloc(buflen);
+ buf = zmalloc<char>(buflen);
if (!buf) {
goto end;
}
string_len += long_options[i].has_arg ? 1 : 0;
}
- optstring = (char *) zmalloc(string_len);
+ optstring = zmalloc<char>(string_len);
if (!optstring) {
goto end;
}
buflen = FALLBACK_USER_BUFLEN;
}
- buf = (char *) zmalloc(buflen);
+ buf = zmalloc<char>(buflen);
if (!buf) {
ret_val = LTTNG_ERR_NOMEM;
goto end;
case ERANGE:
buflen *= 2;
free(buf);
- buf = (char *) zmalloc(buflen);
+ buf = zmalloc<char>(buflen);
if (!buf) {
ret_val = LTTNG_ERR_NOMEM;
goto end;
buflen = FALLBACK_GROUP_BUFLEN;
}
- buf = (char *) zmalloc(buflen);
+ buf = zmalloc<char>(buflen);
if (!buf) {
ret_val = LTTNG_ERR_NOMEM;
goto end;
case ERANGE:
buflen *= 2;
free(buf);
- buf = (char *) zmalloc(buflen);
+ buf = zmalloc<char>(buflen);
if (!buf) {
ret_val = LTTNG_ERR_NOMEM;
goto end;
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;
}
goto end;
}
- pending_notification = (struct pending_notification *) zmalloc(sizeof(*pending_notification));
+ pending_notification = zmalloc<struct pending_notification>();
if (!pending_notification) {
ret = -1;
goto end;
goto end;
}
- pending_notification = (struct pending_notification *) zmalloc(sizeof(*pending_notification));
+ pending_notification = zmalloc<struct pending_notification>();
if (!pending_notification) {
ret = -1;
goto error;
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;
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;
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;
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
}
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;
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;
}
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;
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;
}
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;
}
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;
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;
}
}
/* 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;
size_t *user_len)
{
int ret = 0;
- void *buf = NULL;
+ char *buf = NULL;
if (len) {
if (!user_len) {
goto end;
}
- buf = zmalloc(len);
+ buf = zmalloc<char>(len);
if (!buf) {
ret = -ENOMEM;
goto end;
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;
/* 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;
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;
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
{
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;
}
{
struct lttng_rotation_schedule_periodic *schedule;
- schedule = (lttng_rotation_schedule_periodic *) zmalloc(sizeof(*schedule));
+ schedule = zmalloc<lttng_rotation_schedule_periodic>();
if (!schedule) {
goto end;
}
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)
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;
{
struct lttng_snapshot_output *output;
- output = (lttng_snapshot_output *) zmalloc(sizeof(struct lttng_snapshot_output));
+ output = zmalloc<lttng_snapshot_output>();
if (!output) {
goto error;
}
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;
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;
int i;
ssize_t ret_len;
- session = (live_session *) zmalloc(sizeof(struct live_session));
+ session = zmalloc<live_session>();
if (!session) {
goto error;
}
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;
}
goto error;
}
- data = (char *) zmalloc(len);
+ data = calloc<char>(len);
if (!data) {
PERROR("relay data zmalloc");
goto error;
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) {
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) {
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");
}
/* 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;