return (strdup (static_buffer));
/* Allocate a buffer large enough to hold the string. */
- alloc_buffer = malloc (alloc_buffer_size);
+ alloc_buffer = calloc (1, alloc_buffer_size);
if (alloc_buffer == NULL)
return (NULL);
- memset (alloc_buffer, 0, alloc_buffer_size);
/* Print again into this new buffer. */
va_start (ap, format);
if (buffer_size < 3)
return (EINVAL);
- temp = malloc (buffer_size);
+ temp = calloc (1, buffer_size);
if (temp == NULL)
return (ENOMEM);
- memset (temp, 0, buffer_size);
temp[0] = '"';
j = 1;
return (NULL);
}
- root = malloc (sizeof (*root));
+ root = calloc (1, sizeof (*root));
if (root == NULL)
{
- ERROR ("configfile: malloc failed.");
+ ERROR ("configfile: calloc failed.");
closedir (dh);
return (NULL);
}
- memset (root, 0, sizeof (oconfig_item_t));
while ((de = readdir (dh)) != NULL)
{
return (NULL);
}
- root = malloc (sizeof (*root));
+ root = calloc (1, sizeof (*root));
if (root == NULL)
{
- ERROR ("configfile: malloc failed.");
+ ERROR ("configfile: calloc failed.");
return (NULL);
}
- memset (root, '\0', sizeof (oconfig_item_t));
/* wordexp() might return a sorted list already. That's not
* documented though, so let's make sure we get what we want. */
return (-1);
}
- m = malloc (sizeof (*m));
+ m = calloc (1, sizeof (*m));
if (m == NULL)
{
- ERROR ("fc_config_add_match: malloc failed.");
+ ERROR ("fc_config_add_match: calloc failed.");
return (-1);
}
- memset (m, 0, sizeof (*m));
sstrncpy (m->name, ptr->name, sizeof (m->name));
memcpy (&m->proc, &ptr->proc, sizeof (m->proc));
return (-1);
}
- t = malloc (sizeof (*t));
+ t = calloc (1, sizeof (*t));
if (t == NULL)
{
- ERROR ("fc_config_add_target: malloc failed.");
+ ERROR ("fc_config_add_target: calloc failed.");
return (-1);
}
- memset (t, 0, sizeof (*t));
sstrncpy (t->name, ptr->name, sizeof (t->name));
memcpy (&t->proc, &ptr->proc, sizeof (t->proc));
return (-1);
}
- rule = malloc (sizeof (*rule));
+ rule = calloc (1, sizeof (*rule));
if (rule == NULL)
{
- ERROR ("fc_config_add_rule: malloc failed.");
+ ERROR ("fc_config_add_rule: calloc failed.");
return (-1);
}
- memset (rule, 0, sizeof (*rule));
- rule->next = NULL;
if (ci->values_num == 1)
{
if (chain == NULL)
{
- chain = malloc (sizeof (*chain));
+ chain = calloc (1, sizeof (*chain));
if (chain == NULL)
{
- ERROR ("fc_config_add_chain: malloc failed.");
+ ERROR ("fc_config_add_chain: calloc failed.");
return (-1);
}
- memset (chain, 0, sizeof (*chain));
sstrncpy (chain->name, ci->values[0].value.string, sizeof (chain->name));
- chain->rules = NULL;
- chain->targets = NULL;
- chain->next = NULL;
}
for (i = 0; i < ci->children_num; i++)
DEBUG ("fc_register_match (%s);", name);
- m = malloc (sizeof (*m));
+ m = calloc (1, sizeof (*m));
if (m == NULL)
return (-ENOMEM);
- memset (m, 0, sizeof (*m));
sstrncpy (m->name, name, sizeof (m->name));
memcpy (&m->proc, &proc, sizeof (m->proc));
- m->next = NULL;
if (match_list_head == NULL)
{
DEBUG ("fc_register_target (%s);", name);
- t = malloc (sizeof (*t));
+ t = calloc (1, sizeof (*t));
if (t == NULL)
return (-ENOMEM);
- memset (t, 0, sizeof (*t));
sstrncpy (t->name, name, sizeof (t->name));
memcpy (&t->proc, &proc, sizeof (t->proc));
- t->next = NULL;
if (target_list_head == NULL)
{
{
meta_entry_t *e;
- e = malloc (sizeof (*e));
+ e = calloc (1, sizeof (*e));
if (e == NULL)
{
- ERROR ("md_entry_alloc: malloc failed.");
+ ERROR ("md_entry_alloc: calloc failed.");
return (NULL);
}
- memset (e, 0, sizeof (*e));
e->key = md_strdup (key);
if (e->key == NULL)
{
meta_data_t *md;
- md = malloc (sizeof (*md));
+ md = calloc (1, sizeof (*md));
if (md == NULL)
{
- ERROR ("meta_data_create: malloc failed.");
+ ERROR ("meta_data_create: calloc failed.");
return (NULL);
}
- memset (md, 0, sizeof (*md));
- md->head = NULL;
pthread_mutex_init (&md->lock, /* attr = */ NULL);
return (md);
{
callback_func_t *cf;
- cf = malloc (sizeof (*cf));
+ cf = calloc (1, sizeof (*cf));
if (cf == NULL)
{
- ERROR ("plugin: create_register_callback: malloc failed.");
+ ERROR ("plugin: create_register_callback: calloc failed.");
return (-1);
}
- memset (cf, 0, sizeof (*cf));
cf->cf_callback = callback;
if (ud == NULL)
read_func_t *rf;
int status;
- rf = malloc (sizeof (*rf));
+ rf = calloc (1, sizeof (*rf));
if (rf == NULL)
{
- ERROR ("plugin_register_read: malloc failed.");
+ ERROR ("plugin_register_read: calloc failed.");
return (ENOMEM);
}
- memset (rf, 0, sizeof (read_func_t));
rf->rf_callback = (void *) callback;
rf->rf_udata.data = NULL;
rf->rf_udata.free_func = NULL;
read_func_t *rf;
int status;
- rf = malloc (sizeof (*rf));
+ rf = calloc (1,sizeof (*rf));
if (rf == NULL)
{
- ERROR ("plugin_register_complex_read: malloc failed.");
+ ERROR ("plugin_register_complex_read: calloc failed.");
return (ENOMEM);
}
- memset (rf, 0, sizeof (read_func_t));
rf->rf_callback = (void *) callback;
if (group != NULL)
sstrncpy (rf->rf_group, group, sizeof (rf->rf_group));
return (-1);
}
- meta = malloc (sizeof (*meta));
+ meta = calloc (1, sizeof (*meta));
if (meta == NULL)
{
- ERROR ("plugin_notification_meta_add: malloc failed.");
+ ERROR ("plugin_notification_meta_add: calloc failed.");
return (-1);
}
- memset (meta, 0, sizeof (notification_meta_t));
sstrncpy (meta->name, name, sizeof (meta->name));
meta->type = type;
if (fields[0][0] == '#')
return;
- ds = malloc (sizeof (*ds));
+ ds = calloc (1, sizeof (*ds));
if (ds == NULL)
return;
- memset (ds, '\0', sizeof (data_set_t));
-
sstrncpy (ds->type, fields[0], sizeof (ds->type));
ds->ds_num = fields_num - 1;
if (t == NULL)
return (NULL);
- iter = malloc (sizeof (*iter));
+ iter = calloc (1, sizeof (*iter));
if (iter == NULL)
return (NULL);
- memset (iter, '\0', sizeof (c_avl_iterator_t));
iter->tree = t;
return (iter);
{
cache_entry_t *ce;
- ce = malloc (sizeof (*ce));
+ ce = calloc (1, sizeof (*ce));
if (ce == NULL)
{
- ERROR ("utils_cache: cache_alloc: malloc failed.");
+ ERROR ("utils_cache: cache_alloc: calloc failed.");
return (NULL);
}
- memset (ce, '\0', sizeof (cache_entry_t));
ce->values_num = values_num;
ce->values_gauge = calloc (values_num, sizeof (*ce->values_gauge));
if (compare == NULL)
return (NULL);
- h = malloc (sizeof (*h));
+ h = calloc (1, sizeof (*h));
if (h == NULL)
return (NULL);
- memset (h, 0, sizeof (*h));
pthread_mutex_init (&h->lock, /* attr = */ NULL);
h->compare = compare;
-
+
h->list = NULL;
h->list_len = 0;
h->list_size = 0;
ignorelist_item_t *entry;
int status;
- re = malloc (sizeof (*re));
+ re = calloc (1, sizeof (*re));
if (re == NULL)
{
- ERROR ("ignorelist_append_regex: malloc failed.");
+ ERROR ("ignorelist_append_regex: calloc failed.");
return (ENOMEM);
}
- memset (re, 0, sizeof (*re));
status = regcomp (re, re_str, REG_EXTENDED);
if (status != 0)
return (status);
}
- entry = malloc (sizeof (*entry));
+ entry = calloc (1, sizeof (*entry));
if (entry == NULL)
{
- ERROR ("ignorelist_append_regex: malloc failed.");
+ ERROR ("ignorelist_append_regex: calloc failed.");
regfree (re);
sfree (re);
return (ENOMEM);
}
- memset (entry, 0, sizeof (*entry));
entry->rmatch = re;
ignorelist_append (il, entry);
ignorelist_item_t *new;
/* create new entry */
- if ((new = malloc(sizeof (*new))) == NULL )
+ if ((new = calloc(1, sizeof (*new))) == NULL )
{
ERROR ("cannot allocate new entry");
return (1);
}
- memset (new, '\0', sizeof(ignorelist_item_t));
new->smatch = sstrdup(entry);
/* append new entry */
{
ignorelist_t *il;
- il = malloc (sizeof (*il));
+ il = calloc (1, sizeof (*il));
if (il == NULL)
return NULL;
- memset (il, 0, sizeof (*il));
/*
* ->ignore == 0 => collect
{
llist_t *ret;
- ret = malloc (sizeof (*ret));
+ ret = calloc (1, sizeof (*ret));
if (ret == NULL)
return (NULL);
- memset (ret, '\0', sizeof (llist_t));
-
return (ret);
}
DEBUG ("utils_match: match_create_callback: regex = %s, excluderegex = %s",
regex, excluderegex);
- obj = malloc (sizeof (*obj));
+ obj = calloc (1, sizeof (*obj));
if (obj == NULL)
return (NULL);
- memset (obj, '\0', sizeof (cu_match_t));
status = regcomp (&obj->regex, regex, REG_EXTENDED | REG_NEWLINE);
if (status != 0)
cu_match_value_t *user_data;
cu_match_t *obj;
- user_data = malloc (sizeof (*user_data));
+ user_data = calloc (1, sizeof (*user_data));
if (user_data == NULL)
return (NULL);
- memset (user_data, '\0', sizeof (cu_match_value_t));
user_data->ds_type = match_ds_type;
obj = match_create_callback (regex, excluderegex,
{
cu_tail_t *obj;
- obj = malloc (sizeof (*obj));
+ obj = calloc (1, sizeof (*obj));
if (obj == NULL)
return (NULL);
- memset (obj, '\0', sizeof (cu_tail_t));
obj->file = strdup (file);
if (obj->file == NULL)
{
cu_tail_match_t *obj;
- obj = malloc (sizeof (*obj));
+ obj = calloc (1, sizeof (*obj));
if (obj == NULL)
return (NULL);
- memset (obj, '\0', sizeof (cu_tail_match_t));
obj->tail = cu_tail_create (filename);
if (obj->tail == NULL)
if (match == NULL)
return (-1);
- user_data = malloc (sizeof (*user_data));
+ user_data = calloc (1, sizeof (*user_data));
if (user_data == NULL)
{
match_destroy (match);
return (-1);
}
- memset (user_data, '\0', sizeof (cu_tail_match_simple_t));
sstrncpy (user_data->plugin, plugin, sizeof (user_data->plugin));
if (plugin_instance != NULL)