From 1ebf2f31bd2e080e6f42de640f0a3899a61501c0 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Mon, 28 Mar 2016 19:12:10 +0200 Subject: [PATCH] treewide: cleanup malloc calls - Remove unnecessary casts - Use the size of the variable for mallocs size --- src/barometer.c | 4 ++-- src/ceph.c | 8 ++++---- src/cpu.c | 3 +-- src/curl.c | 6 +++--- src/curl_json.c | 6 +++--- src/curl_xml.c | 6 +++--- src/daemon/common.c | 4 ++-- src/daemon/configfile.c | 8 ++++---- src/daemon/filter_chain.c | 14 +++++++------- src/daemon/meta_data.c | 6 +++--- src/daemon/plugin.c | 12 ++++++------ src/daemon/types_list.c | 2 +- src/daemon/utils_avltree.c | 6 +++--- src/daemon/utils_cache.c | 4 ++-- src/daemon/utils_ignorelist.c | 2 +- src/daemon/utils_llist.c | 4 ++-- src/daemon/utils_match.c | 6 +++--- src/daemon/utils_subst.c | 2 +- src/daemon/utils_tail.c | 2 +- src/daemon/utils_tail_match.c | 4 ++-- src/dbi.c | 25 +++++++++++-------------- src/dns.c | 2 +- src/email.c | 10 +++++----- src/exec.c | 7 +++---- src/filecount.c | 2 +- src/gmond.c | 2 +- src/interface.c | 5 ++--- src/ipc.c | 2 +- src/iptables.c | 2 +- src/java.c | 6 +++--- src/libcollectdclient/client.c | 8 ++++---- src/liboconfig/oconfig.c | 2 +- src/liboconfig/parser.y | 8 ++++---- src/match_empty_counter.c | 2 +- src/match_hashed.c | 2 +- src/match_regex.c | 4 ++-- src/match_timediff.c | 2 +- src/match_value.c | 2 +- src/memcachec.c | 4 ++-- src/mysql.c | 2 +- src/netapp.c | 4 ++-- src/netlink.c | 2 +- src/network.c | 8 ++++---- src/nut.c | 4 ++-- src/onewire.c | 4 ++-- src/openvpn.c | 2 +- src/oracle.c | 2 +- src/perl.c | 16 ++++++++-------- src/ping.c | 2 +- src/postgresql.c | 2 +- src/powerdns.c | 4 ++-- src/processes.c | 6 +++--- src/rrdtool.c | 4 ++-- src/sensors.c | 4 ++-- src/sigrok.c | 6 +++--- src/snmp.c | 8 ++++---- src/tail_csv.c | 2 +- src/target_notification.c | 2 +- src/target_replace.c | 6 +++--- src/target_scale.c | 2 +- src/target_set.c | 2 +- src/tcpconns.c | 4 ++-- src/teamspeak2.c | 2 +- src/threshold.c | 2 +- src/unixsock.c | 2 +- src/utils_cmd_putval.c | 2 +- src/utils_db_query.c | 4 ++-- src/utils_dns.c | 2 +- src/utils_mount.c | 13 ++++++------- src/utils_rrdcreate.c | 4 ++-- src/virt.c | 2 +- src/zone.c | 4 ++-- 72 files changed, 167 insertions(+), 174 deletions(-) diff --git a/src/barometer.c b/src/barometer.c index 0e8deaf8..f14ac049 100644 --- a/src/barometer.c +++ b/src/barometer.c @@ -343,9 +343,9 @@ static temperature_list_t * temp_list = NULL; */ static int temp_list_add(temperature_list_t * list, const char * sensor) { - temperature_list_t * new_temp; + temperature_list_t *new_temp; - new_temp = (temperature_list_t *) malloc(sizeof(*new_temp)); + new_temp = malloc(sizeof (*new_temp)); if(new_temp == NULL) return -1; diff --git a/src/ceph.c b/src/ceph.c index b1ca3b66..04a39743 100644 --- a/src/ceph.c +++ b/src/ceph.c @@ -623,7 +623,7 @@ static int ceph_daemon_add_ds_entry(struct ceph_daemon *d, const char *name, return -ENOMEM; } - d->ds_names[d->ds_num] = malloc(sizeof(char) * DATA_MAX_NAME_LEN); + d->ds_names[d->ds_num] = malloc(DATA_MAX_NAME_LEN); if(!d->ds_names[d->ds_num]) { return -ENOMEM; @@ -747,7 +747,7 @@ static int cc_add_daemon_config(oconfig_item_t *ci) } g_daemons = tmp; - nd = malloc(sizeof(*nd)); + nd = malloc(sizeof (*nd)); if(!nd) { return ENOMEM; @@ -845,7 +845,7 @@ node_handler_define_schema(void *arg, const char *val, const char *key) static int add_last(struct ceph_daemon *d, const char *ds_n, double cur_sum, uint64_t cur_count) { - d->last_poll_data[d->last_idx] = malloc(1 * sizeof(struct last_data)); + d->last_poll_data[d->last_idx] = malloc(sizeof (*d->last_poll_data[d->last_idx])); if(!d->last_poll_data[d->last_idx]) { return -ENOMEM; @@ -873,7 +873,7 @@ static int update_last(struct ceph_daemon *d, const char *ds_n, int index, if(!d->last_poll_data) { - d->last_poll_data = malloc(1 * sizeof(struct last_data *)); + d->last_poll_data = malloc(sizeof (*d->last_poll_data)); if(!d->last_poll_data) { return -ENOMEM; diff --git a/src/cpu.c b/src/cpu.c index 7f8c9858..9c432d17 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -814,8 +814,7 @@ static int cpu_read (void) if (pnumcpu != numcpu || perfcpu == NULL) { - if (perfcpu != NULL) - free(perfcpu); + free(perfcpu); perfcpu = malloc(numcpu * sizeof(perfstat_cpu_t)); } pnumcpu = numcpu; diff --git a/src/curl.c b/src/curl.c index 16ae3aba..f6127a9f 100644 --- a/src/curl.c +++ b/src/curl.c @@ -270,7 +270,7 @@ static int cc_config_add_match (web_page_t *page, /* {{{ */ WARNING ("curl plugin: Ignoring arguments for the `Match' block."); } - match = (web_match_t *) malloc (sizeof (*match)); + match = malloc (sizeof (*match)); if (match == NULL) { ERROR ("curl plugin: malloc failed."); @@ -388,7 +388,7 @@ static int cc_page_init_curl (web_page_t *wp) /* {{{ */ if (wp->pass != NULL) credentials_size += strlen (wp->pass); - wp->credentials = (char *) malloc (credentials_size); + wp->credentials = malloc (credentials_size); if (wp->credentials == NULL) { ERROR ("curl plugin: malloc failed."); @@ -436,7 +436,7 @@ static int cc_config_add_page (oconfig_item_t *ci) /* {{{ */ return (-1); } - page = (web_page_t *) malloc (sizeof (*page)); + page = malloc (sizeof (*page)); if (page == NULL) { ERROR ("curl plugin: malloc failed."); diff --git a/src/curl_json.c b/src/curl_json.c index 45898c3e..4fa6f33b 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -474,7 +474,7 @@ static int cj_config_add_key (cj_t *db, /* {{{ */ return (-1); } - key = (cj_key_t *) malloc (sizeof (*key)); + key = malloc (sizeof (*key)); if (key == NULL) { ERROR ("curl_json plugin: malloc failed."); @@ -615,7 +615,7 @@ static int cj_init_curl (cj_t *db) /* {{{ */ if (db->pass != NULL) credentials_size += strlen (db->pass); - db->credentials = (char *) malloc (credentials_size); + db->credentials = malloc (credentials_size); if (db->credentials == NULL) { ERROR ("curl_json plugin: malloc failed."); @@ -667,7 +667,7 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */ return (-1); } - db = (cj_t *) malloc (sizeof (*db)); + db = malloc (sizeof (*db)); if (db == NULL) { ERROR ("curl_json plugin: malloc failed."); diff --git a/src/curl_xml.c b/src/curl_xml.c index 39d6fd04..ab18b780 100644 --- a/src/curl_xml.c +++ b/src/curl_xml.c @@ -686,7 +686,7 @@ static int cx_config_add_values (const char *name, cx_xpath_t *xpath, /* {{{ */ sfree (xpath->values); xpath->values_len = 0; - xpath->values = (cx_values_t *) malloc (sizeof (cx_values_t) * ci->values_num); + xpath->values = malloc (sizeof (cx_values_t) * ci->values_num); if (xpath->values == NULL) return (-1); xpath->values_len = (size_t) ci->values_num; @@ -873,7 +873,7 @@ static int cx_init_curl (cx_t *db) /* {{{ */ if (db->pass != NULL) credentials_size += strlen (db->pass); - db->credentials = (char *) malloc (credentials_size); + db->credentials = malloc (credentials_size); if (db->credentials == NULL) { ERROR ("curl_xml plugin: malloc failed."); @@ -923,7 +923,7 @@ static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */ return (-1); } - db = (cx_t *) malloc (sizeof (*db)); + db = malloc (sizeof (*db)); if (db == NULL) { ERROR ("curl_xml plugin: malloc failed."); diff --git a/src/daemon/common.c b/src/daemon/common.c index dd4f9b15..2f6da957 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -144,7 +144,7 @@ char *sstrdup (const char *s) /* Do not use `strdup' here, because it's not specified in POSIX. It's * ``only'' an XSI extension. */ sz = strlen (s) + 1; - r = (char *) malloc (sizeof (char) * sz); + r = malloc (sz); if (r == NULL) { ERROR ("sstrdup: Out of memory."); @@ -409,7 +409,7 @@ int escape_string (char *buffer, size_t buffer_size) if (buffer_size < 3) return (EINVAL); - temp = (char *) malloc (buffer_size); + temp = malloc (buffer_size); if (temp == NULL) return (ENOMEM); memset (temp, 0, buffer_size); diff --git a/src/daemon/configfile.c b/src/daemon/configfile.c index 8a7621d2..5f49a9e6 100644 --- a/src/daemon/configfile.c +++ b/src/daemon/configfile.c @@ -717,7 +717,7 @@ static oconfig_item_t *cf_read_dir (const char *dir, return (NULL); } - root = (oconfig_item_t *) malloc (sizeof (oconfig_item_t)); + root = malloc (sizeof (*root)); if (root == NULL) { ERROR ("configfile: malloc failed."); @@ -835,7 +835,7 @@ static oconfig_item_t *cf_read_generic (const char *path, return (NULL); } - root = (oconfig_item_t *) malloc (sizeof (oconfig_item_t)); + root = malloc (sizeof (*root)); if (root == NULL) { ERROR ("configfile: malloc failed."); @@ -1067,7 +1067,7 @@ void cf_register (const char *type, cf_unregister (type); /* This pointer will be free'd in `cf_unregister' */ - if ((cf_cb = (cf_callback_t *) malloc (sizeof (cf_callback_t))) == NULL) + if ((cf_cb = malloc (sizeof (*cf_cb))) == NULL) return; cf_cb->type = type; @@ -1084,7 +1084,7 @@ int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *)) { cf_complex_callback_t *new; - new = (cf_complex_callback_t *) malloc (sizeof (cf_complex_callback_t)); + new = malloc (sizeof (*new)); if (new == NULL) return (-1); diff --git a/src/daemon/filter_chain.c b/src/daemon/filter_chain.c index ecc7f165..b599d70e 100644 --- a/src/daemon/filter_chain.c +++ b/src/daemon/filter_chain.c @@ -174,7 +174,7 @@ static char *fc_strdup (const char *orig) /* {{{ */ return (NULL); sz = strlen (orig) + 1; - dest = (char *) malloc (sz); + dest = malloc (sz); if (dest == NULL) return (NULL); @@ -235,7 +235,7 @@ static int fc_config_add_match (fc_match_t **matches_head, /* {{{ */ return (-1); } - m = (fc_match_t *) malloc (sizeof (*m)); + m = malloc (sizeof (*m)); if (m == NULL) { ERROR ("fc_config_add_match: malloc failed."); @@ -307,7 +307,7 @@ static int fc_config_add_target (fc_target_t **targets_head, /* {{{ */ return (-1); } - t = (fc_target_t *) malloc (sizeof (*t)); + t = malloc (sizeof (*t)); if (t == NULL) { ERROR ("fc_config_add_target: malloc failed."); @@ -373,7 +373,7 @@ static int fc_config_add_rule (fc_chain_t *chain, /* {{{ */ return (-1); } - rule = (fc_rule_t *) malloc (sizeof (*rule)); + rule = malloc (sizeof (*rule)); if (rule == NULL) { ERROR ("fc_config_add_rule: malloc failed."); @@ -469,7 +469,7 @@ static int fc_config_add_chain (const oconfig_item_t *ci) /* {{{ */ if (chain == NULL) { - chain = (fc_chain_t *) malloc (sizeof (*chain)); + chain = malloc (sizeof (*chain)); if (chain == NULL) { ERROR ("fc_config_add_chain: malloc failed."); @@ -824,7 +824,7 @@ int fc_register_match (const char *name, match_proc_t proc) /* {{{ */ DEBUG ("fc_register_match (%s);", name); - m = (fc_match_t *) malloc (sizeof (*m)); + m = malloc (sizeof (*m)); if (m == NULL) return (-ENOMEM); memset (m, 0, sizeof (*m)); @@ -858,7 +858,7 @@ int fc_register_target (const char *name, target_proc_t proc) /* {{{ */ DEBUG ("fc_register_target (%s);", name); - t = (fc_target_t *) malloc (sizeof (*t)); + t = malloc (sizeof (*t)); if (t == NULL) return (-ENOMEM); memset (t, 0, sizeof (*t)); diff --git a/src/daemon/meta_data.c b/src/daemon/meta_data.c index e1d0ec5b..10678640 100644 --- a/src/daemon/meta_data.c +++ b/src/daemon/meta_data.c @@ -71,7 +71,7 @@ static char *md_strdup (const char *orig) /* {{{ */ return (NULL); sz = strlen (orig) + 1; - dest = (char *) malloc (sz); + dest = malloc (sz); if (dest == NULL) return (NULL); @@ -84,7 +84,7 @@ static meta_entry_t *md_entry_alloc (const char *key) /* {{{ */ { meta_entry_t *e; - e = (meta_entry_t *) malloc (sizeof (*e)); + e = malloc (sizeof (*e)); if (e == NULL) { ERROR ("md_entry_alloc: malloc failed."); @@ -220,7 +220,7 @@ meta_data_t *meta_data_create (void) /* {{{ */ { meta_data_t *md; - md = (meta_data_t *) malloc (sizeof (*md)); + md = malloc (sizeof (*md)); if (md == NULL) { ERROR ("meta_data_create: malloc failed."); diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index e7993f1e..6c8b6b0e 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -368,7 +368,7 @@ static int create_register_callback (llist_t **list, /* {{{ */ { callback_func_t *cf; - cf = (callback_func_t *) malloc (sizeof (*cf)); + cf = malloc (sizeof (*cf)); if (cf == NULL) { ERROR ("plugin: create_register_callback: malloc failed."); @@ -1351,7 +1351,7 @@ static char *plugin_flush_callback_name (const char *name) prefix_size = strlen(flush_prefix); name_size = strlen(name); - flush_name = malloc (sizeof(char) * (name_size + prefix_size + 1)); + flush_name = malloc (name_size + prefix_size + 1); if (flush_name == NULL) { ERROR ("plugin_flush_callback_name: malloc failed."); @@ -1384,7 +1384,7 @@ int plugin_register_flush (const char *name, if (flush_name == NULL) return (-1); - cb = malloc(sizeof(flush_callback_t)); + cb = malloc(sizeof (*cb)); if (cb == NULL) { ERROR ("plugin_register_flush: malloc failed."); @@ -1477,12 +1477,12 @@ int plugin_register_data_set (const data_set_t *ds) return (-1); } - ds_copy = (data_set_t *) malloc (sizeof (data_set_t)); + ds_copy = malloc (sizeof (*ds_copy)); if (ds_copy == NULL) return (-1); memcpy(ds_copy, ds, sizeof (data_set_t)); - ds_copy->ds = (data_source_t *) malloc (sizeof (data_source_t) + ds_copy->ds = malloc (sizeof (*ds_copy->ds) * ds->ds_num); if (ds_copy->ds == NULL) { @@ -2578,7 +2578,7 @@ static int plugin_notification_meta_add (notification_t *n, return (-1); } - meta = (notification_meta_t *) malloc (sizeof (notification_meta_t)); + meta = malloc (sizeof (*meta)); if (meta == NULL) { ERROR ("plugin_notification_meta_add: malloc failed."); diff --git a/src/daemon/types_list.c b/src/daemon/types_list.c index eb50bb8a..3ac38f23 100644 --- a/src/daemon/types_list.c +++ b/src/daemon/types_list.c @@ -112,7 +112,7 @@ static void parse_line (char *buf) if (fields[0][0] == '#') return; - ds = (data_set_t *) malloc (sizeof (data_set_t)); + ds = malloc (sizeof (*ds)); if (ds == NULL) return; diff --git a/src/daemon/utils_avltree.c b/src/daemon/utils_avltree.c index fcfbb945..bf6880ca 100644 --- a/src/daemon/utils_avltree.c +++ b/src/daemon/utils_avltree.c @@ -485,7 +485,7 @@ c_avl_tree_t *c_avl_create (int (*compare) (const void *, const void *)) if (compare == NULL) return (NULL); - if ((t = (c_avl_tree_t *) malloc (sizeof (c_avl_tree_t))) == NULL) + if ((t = malloc (sizeof (*t))) == NULL) return (NULL); t->root = NULL; @@ -509,7 +509,7 @@ int c_avl_insert (c_avl_tree_t *t, void *key, void *value) c_avl_node_t *nptr; int cmp; - if ((new = (c_avl_node_t *) malloc (sizeof (c_avl_node_t))) == NULL) + if ((new = malloc (sizeof (*new))) == NULL) return (-1); new->key = key; @@ -665,7 +665,7 @@ c_avl_iterator_t *c_avl_get_iterator (c_avl_tree_t *t) if (t == NULL) return (NULL); - iter = (c_avl_iterator_t *) malloc (sizeof (c_avl_iterator_t)); + iter = malloc (sizeof (*iter)); if (iter == NULL) return (NULL); memset (iter, '\0', sizeof (c_avl_iterator_t)); diff --git a/src/daemon/utils_cache.c b/src/daemon/utils_cache.c index 07568073..7f0d228f 100644 --- a/src/daemon/utils_cache.c +++ b/src/daemon/utils_cache.c @@ -83,7 +83,7 @@ static cache_entry_t *cache_alloc (size_t values_num) { cache_entry_t *ce; - ce = (cache_entry_t *) malloc (sizeof (cache_entry_t)); + ce = malloc (sizeof (*ce)); if (ce == NULL) { ERROR ("utils_cache: cache_alloc: malloc failed."); @@ -499,7 +499,7 @@ int uc_get_rate_by_name (const char *name, gauge_t **ret_values, size_t *ret_val else { ret_num = ce->values_num; - ret = (gauge_t *) malloc (ret_num * sizeof (gauge_t)); + ret = malloc (ret_num * sizeof (*ret)); if (ret == NULL) { ERROR ("utils_cache: uc_get_rate_by_name: malloc failed."); diff --git a/src/daemon/utils_ignorelist.c b/src/daemon/utils_ignorelist.c index 12688380..011b3d3d 100644 --- a/src/daemon/utils_ignorelist.c +++ b/src/daemon/utils_ignorelist.c @@ -134,7 +134,7 @@ static int ignorelist_append_string(ignorelist_t *il, const char *entry) ignorelist_item_t *new; /* create new entry */ - if ((new = malloc(sizeof(ignorelist_item_t))) == NULL ) + if ((new = malloc(sizeof (*new))) == NULL ) { ERROR ("cannot allocate new entry"); return (1); diff --git a/src/daemon/utils_llist.c b/src/daemon/utils_llist.c index 4265286b..40dd0eaa 100644 --- a/src/daemon/utils_llist.c +++ b/src/daemon/utils_llist.c @@ -48,7 +48,7 @@ llist_t *llist_create (void) { llist_t *ret; - ret = (llist_t *) malloc (sizeof (llist_t)); + ret = malloc (sizeof (*ret)); if (ret == NULL) return (NULL); @@ -78,7 +78,7 @@ llentry_t *llentry_create (char *key, void *value) { llentry_t *e; - e = (llentry_t *) malloc (sizeof (llentry_t)); + e = malloc (sizeof (*e)); if (e) { e->key = key; diff --git a/src/daemon/utils_match.c b/src/daemon/utils_match.c index 5083b05a..c1d99e15 100644 --- a/src/daemon/utils_match.c +++ b/src/daemon/utils_match.c @@ -63,7 +63,7 @@ static char *match_substr (const char *str, int begin, int end) } ret_len = end - begin; - ret = (char *) malloc (sizeof (char) * (ret_len + 1)); + ret = malloc (ret_len + 1); if (ret == NULL) { ERROR ("utils_match: match_substr: malloc failed."); @@ -238,7 +238,7 @@ cu_match_t *match_create_callback (const char *regex, const char *excluderegex, DEBUG ("utils_match: match_create_callback: regex = %s, excluderegex = %s", regex, excluderegex); - obj = (cu_match_t *) malloc (sizeof (cu_match_t)); + obj = malloc (sizeof (*obj)); if (obj == NULL) return (NULL); memset (obj, '\0', sizeof (cu_match_t)); @@ -275,7 +275,7 @@ cu_match_t *match_create_simple (const char *regex, cu_match_value_t *user_data; cu_match_t *obj; - user_data = (cu_match_value_t *) malloc (sizeof (cu_match_value_t)); + user_data = malloc (sizeof (*user_data)); if (user_data == NULL) return (NULL); memset (user_data, '\0', sizeof (cu_match_value_t)); diff --git a/src/daemon/utils_subst.c b/src/daemon/utils_subst.c index cfa1c764..9284f733 100644 --- a/src/daemon/utils_subst.c +++ b/src/daemon/utils_subst.c @@ -102,7 +102,7 @@ char *asubst (const char *string, int off1, int off2, const char *replacement) len = off1 + strlen (replacement) + strlen (string) - off2 + 1; - buf = (char *)malloc (len); + buf = malloc (len); if (NULL == buf) return NULL; diff --git a/src/daemon/utils_tail.c b/src/daemon/utils_tail.c index fe5dca89..c4b73c35 100644 --- a/src/daemon/utils_tail.c +++ b/src/daemon/utils_tail.c @@ -119,7 +119,7 @@ cu_tail_t *cu_tail_create (const char *file) { cu_tail_t *obj; - obj = (cu_tail_t *) malloc (sizeof (cu_tail_t)); + obj = malloc (sizeof (*obj)); if (obj == NULL) return (NULL); memset (obj, '\0', sizeof (cu_tail_t)); diff --git a/src/daemon/utils_tail_match.c b/src/daemon/utils_tail_match.c index 8776ad11..c8fd05ef 100644 --- a/src/daemon/utils_tail_match.c +++ b/src/daemon/utils_tail_match.c @@ -126,7 +126,7 @@ cu_tail_match_t *tail_match_create (const char *filename) { cu_tail_match_t *obj; - obj = (cu_tail_match_t *) malloc (sizeof (cu_tail_match_t)); + obj = malloc (sizeof (*obj)); if (obj == NULL) return (NULL); memset (obj, '\0', sizeof (cu_tail_match_t)); @@ -212,7 +212,7 @@ int tail_match_add_match_simple (cu_tail_match_t *obj, if (match == NULL) return (-1); - user_data = (cu_tail_match_simple_t *) malloc (sizeof (cu_tail_match_simple_t)); + user_data = malloc (sizeof (*user_data)); if (user_data == NULL) { match_destroy (match); diff --git a/src/dbi.c b/src/dbi.c index 94d0762d..dab47d66 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -294,7 +294,7 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */ return (-1); } - db = (cdbi_database_t *) malloc (sizeof (*db)); + db = malloc (sizeof (*db)); if (db == NULL) { ERROR ("dbi plugin: malloc failed."); @@ -357,12 +357,11 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */ while ((status == 0) && (db->queries_num > 0)) { size_t j; - db->q_prep_areas = (udb_query_preparation_area_t **) calloc ( - db->queries_num, sizeof (*db->q_prep_areas)); + db->q_prep_areas = calloc (db->queries_num, sizeof (*db->q_prep_areas)); if (db->q_prep_areas == NULL) { - WARNING ("dbi plugin: malloc failed"); + WARNING ("dbi plugin: calloc failed"); status = -1; break; } @@ -548,35 +547,33 @@ static int cdbi_read_database_query (cdbi_database_t *db, /* {{{ */ } /* Allocate `column_names' and `column_values'. {{{ */ - column_names = (char **) calloc (column_num, sizeof (char *)); + column_names = calloc (column_num, sizeof (*column_names)); if (column_names == NULL) { - ERROR ("dbi plugin: malloc failed."); + ERROR ("dbi plugin: calloc failed."); BAIL_OUT (-1); } - column_names[0] = (char *) calloc (column_num, - DATA_MAX_NAME_LEN * sizeof (char)); + column_names[0] = calloc (column_num, DATA_MAX_NAME_LEN); if (column_names[0] == NULL) { - ERROR ("dbi plugin: malloc failed."); + ERROR ("dbi plugin: calloc failed."); BAIL_OUT (-1); } for (i = 1; i < column_num; i++) column_names[i] = column_names[i - 1] + DATA_MAX_NAME_LEN; - column_values = (char **) calloc (column_num, sizeof (char *)); + column_values = calloc (column_num, sizeof (*column_values)); if (column_values == NULL) { - ERROR ("dbi plugin: malloc failed."); + ERROR ("dbi plugin: calloc failed."); BAIL_OUT (-1); } - column_values[0] = (char *) calloc (column_num, - DATA_MAX_NAME_LEN * sizeof (char)); + column_values[0] = calloc (column_num, DATA_MAX_NAME_LEN); if (column_values[0] == NULL) { - ERROR ("dbi plugin: malloc failed."); + ERROR ("dbi plugin: calloc failed."); BAIL_OUT (-1); } for (i = 1; i < column_num; i++) diff --git a/src/dns.c b/src/dns.c index 3421c475..f48be009 100644 --- a/src/dns.c +++ b/src/dns.c @@ -94,7 +94,7 @@ static counter_list_t *counter_list_create (counter_list_t **list, { counter_list_t *entry; - entry = (counter_list_t *) malloc (sizeof (counter_list_t)); + entry = malloc (sizeof (*entry)); if (entry == NULL) return (NULL); diff --git a/src/email.c b/src/email.c index 81ae29c3..8898c087 100644 --- a/src/email.c +++ b/src/email.c @@ -219,7 +219,7 @@ static int email_config (const char *key, const char *value) static void type_list_incr (type_list_t *list, char *name, int incr) { if (NULL == list->head) { - list->head = (type_t *)smalloc (sizeof (type_t)); + list->head = smalloc (sizeof (*list->head)); list->head->name = sstrdup (name); list->head->value = incr; @@ -236,7 +236,7 @@ static void type_list_incr (type_list_t *list, char *name, int incr) } if (NULL == ptr) { - list->tail->next = (type_t *)smalloc (sizeof (type_t)); + list->tail->next = smalloc (sizeof (*list->tail->next)); list->tail = list->tail->next; list->tail->name = sstrdup (name); @@ -482,10 +482,10 @@ static void *open_connection (void __attribute__((unused)) *arg) available_collectors = max_conns; collectors = - (collector_t **)smalloc (max_conns * sizeof (collector_t *)); + smalloc (max_conns * sizeof (*collectors)); for (i = 0; i < max_conns; ++i) { - collectors[i] = (collector_t *)smalloc (sizeof (collector_t)); + collectors[i] = smalloc (sizeof (*collectors[i])); collectors[i]->socket = NULL; if (0 != (err = plugin_thread_create (&collectors[i]->thread, @@ -695,7 +695,7 @@ static void copy_type_list (type_list_t *l1, type_list_t *l2) for (ptr1 = l1->head, ptr2 = l2->head; NULL != ptr1; ptr1 = ptr1->next, last = ptr2, ptr2 = ptr2->next) { if (NULL == ptr2) { - ptr2 = (type_t *)smalloc (sizeof (type_t)); + ptr2 = smalloc (sizeof (*ptr2)); ptr2->name = NULL; ptr2->next = NULL; diff --git a/src/exec.c b/src/exec.c index f080ad67..4c45dc15 100644 --- a/src/exec.c +++ b/src/exec.c @@ -126,7 +126,7 @@ static int exec_config_exec (oconfig_item_t *ci) /* {{{ */ return (-1); } - pl = (program_list_t *) malloc (sizeof (program_list_t)); + pl = malloc (sizeof (*pl)); if (pl == NULL) { ERROR ("exec plugin: malloc failed."); @@ -163,7 +163,7 @@ static int exec_config_exec (oconfig_item_t *ci) /* {{{ */ return (-1); } - pl->argv = (char **) malloc (ci->values_num * sizeof (char *)); + pl->argv = malloc (ci->values_num * sizeof (*pl->argv)); if (pl->argv == NULL) { ERROR ("exec plugin: malloc failed."); @@ -869,8 +869,7 @@ static int exec_notification (const notification_t *n, /* {{{ */ if (pl->pid != 0) continue; - pln = (program_list_and_notification_t *) malloc (sizeof - (program_list_and_notification_t)); + pln = malloc (sizeof (*pln)); if (pln == NULL) { ERROR ("exec plugin: malloc failed."); diff --git a/src/filecount.c b/src/filecount.c index 9ea8af7a..7c96a48f 100644 --- a/src/filecount.c +++ b/src/filecount.c @@ -344,7 +344,7 @@ static int fc_config_add_dir (oconfig_item_t *ci) } /* Initialize `dir' */ - dir = (fc_directory_conf_t *) malloc (sizeof (*dir)); + dir = malloc (sizeof (*dir)); if (dir == NULL) { ERROR ("filecount plugin: malloc failed."); diff --git a/src/gmond.c b/src/gmond.c index f86d8f7a..9b5ceb76 100644 --- a/src/gmond.c +++ b/src/gmond.c @@ -454,7 +454,7 @@ static staging_entry_t *staging_entry_get (const char *host, /* {{{ */ return (se); /* insert new entry */ - se = (staging_entry_t *) malloc (sizeof (*se)); + se = malloc (sizeof (*se)); if (se == NULL) return (NULL); memset (se, 0, sizeof (*se)); diff --git a/src/interface.c b/src/interface.c index 90dc139d..d05dd723 100644 --- a/src/interface.c +++ b/src/interface.c @@ -368,9 +368,8 @@ static int interface_read (void) if (pnif != nif || ifstat == NULL) { - if (ifstat != NULL) - free(ifstat); - ifstat = malloc(nif * sizeof(perfstat_netinterface_t)); + free(ifstat); + ifstat = malloc(nif * sizeof (*ifstat)); } pnif = nif; diff --git a/src/ipc.c b/src/ipc.c index 645d4b08..00b3a5f8 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -213,7 +213,7 @@ static caddr_t ipc_get_info (cid_t cid, int cmd, int version, int stsize, int *n *nmemb = size / stsize; - buff = (caddr_t)malloc (size); + buff = malloc (size); if (buff == NULL) { ERROR ("ipc plugin: ipc_get_info malloc failed."); return (NULL); diff --git a/src/iptables.c b/src/iptables.c index 05e3e24b..1e35851a 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -215,7 +215,7 @@ static int iptables_config (const char *key, const char *value) } chain_list = list; - final = (ip_chain_t *) malloc( sizeof(temp) ); + final = malloc(sizeof (*final)); if (final == NULL) { char errbuf[1024]; diff --git a/src/java.c b/src/java.c index 6b92f54e..cd01534d 100644 --- a/src/java.c +++ b/src/java.c @@ -1801,7 +1801,7 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{ return (NULL); } - cbi = (cjni_callback_info_t *) malloc (sizeof (*cbi)); + cbi = malloc (sizeof (*cbi)); if (cbi == NULL) { ERROR ("java plugin: cjni_callback_info_create: malloc failed."); @@ -2067,7 +2067,7 @@ static JNIEnv *cjni_thread_attach (void) /* {{{ */ if (cjni_env == NULL) { /* This pointer is free'd in `cjni_jvm_env_destroy'. */ - cjni_env = (cjni_jvm_env_t *) malloc (sizeof (*cjni_env)); + cjni_env = malloc (sizeof (*cjni_env)); if (cjni_env == NULL) { ERROR ("java plugin: cjni_thread_attach: malloc failed."); @@ -2801,7 +2801,7 @@ static int cjni_match_target_create (const oconfig_item_t *ci, /* {{{ */ /* Allocate a new callback info structure. This is going to be our user_data * pointer. */ - cbi_ret = (cjni_callback_info_t *) malloc (sizeof (*cbi_ret)); + cbi_ret = malloc (sizeof (*cbi_ret)); if (cbi_ret == NULL) { ERROR ("java plugin: cjni_match_target_create: malloc failed."); diff --git a/src/libcollectdclient/client.c b/src/libcollectdclient/client.c index 77819c21..aeb8f22a 100644 --- a/src/libcollectdclient/client.c +++ b/src/libcollectdclient/client.c @@ -312,7 +312,7 @@ static int lcc_receive (lcc_connection_t *c, /* {{{ */ /* Allocate space for the char-pointers */ res.lines_num = (size_t) res.status; res.status = 0; - res.lines = (char **) malloc (res.lines_num * sizeof (char *)); + res.lines = malloc (res.lines_num * sizeof (*res.lines)); if (res.lines == NULL) { lcc_set_errno (c, ENOMEM); @@ -584,7 +584,7 @@ int lcc_connect (const char *address, lcc_connection_t **ret_con) /* {{{ */ if (ret_con == NULL) return (-1); - c = (lcc_connection_t *) malloc (sizeof (*c)); + c = malloc (sizeof (*c)); if (c == NULL) return (-1); memset (c, 0, sizeof (*c)); @@ -687,7 +687,7 @@ int lcc_getval (lcc_connection_t *c, lcc_identifier_t *ident, /* {{{ */ /* Allocate space for the values */ if (ret_values != NULL) { - values = (gauge_t *) malloc (values_num * sizeof (*values)); + values = malloc (values_num * sizeof (*values)); if (values == NULL) BAIL_OUT (ENOMEM); } @@ -894,7 +894,7 @@ int lcc_listval (lcc_connection_t *c, /* {{{ */ } ident_num = res.lines_num; - ident = (lcc_identifier_t *) malloc (ident_num * sizeof (*ident)); + ident = malloc (ident_num * sizeof (*ident)); if (ident == NULL) { lcc_response_free (&res); diff --git a/src/liboconfig/oconfig.c b/src/liboconfig/oconfig.c index 89ccdecb..48f0b25f 100644 --- a/src/liboconfig/oconfig.c +++ b/src/liboconfig/oconfig.c @@ -106,7 +106,7 @@ oconfig_item_t *oconfig_clone (const oconfig_item_t *ci_orig) { oconfig_item_t *ci_copy; - ci_copy = (oconfig_item_t *) malloc (sizeof (*ci_copy)); + ci_copy = malloc (sizeof (*ci_copy)); if (ci_copy == NULL) { fprintf (stderr, "malloc failed.\n"); diff --git a/src/liboconfig/parser.y b/src/liboconfig/parser.y index 803eec26..57e9ddff 100644 --- a/src/liboconfig/parser.y +++ b/src/liboconfig/parser.y @@ -208,15 +208,15 @@ statement_list: entire_file: statement_list { - ci_root = malloc (sizeof (oconfig_item_t)); - memset (ci_root, '\0', sizeof (oconfig_item_t)); + ci_root = malloc (sizeof (*ci_root)); + memset (ci_root, '\0', sizeof (*ci_root)); ci_root->children = $1.statement; ci_root->children_num = $1.statement_num; } | /* epsilon */ { - ci_root = malloc (sizeof (oconfig_item_t)); - memset (ci_root, '\0', sizeof (oconfig_item_t)); + ci_root = malloc (sizeof (*ci_root)); + memset (ci_root, '\0', sizeof (*ci_root)); ci_root->children = NULL; ci_root->children_num = 0; } diff --git a/src/match_empty_counter.c b/src/match_empty_counter.c index e30ff91b..4a5dc8c0 100644 --- a/src/match_empty_counter.c +++ b/src/match_empty_counter.c @@ -46,7 +46,7 @@ static int mec_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ { mec_match_t *m; - m = (mec_match_t *) malloc (sizeof (*m)); + m = malloc (sizeof (*m)); if (m == NULL) { ERROR ("mec_create: malloc failed."); diff --git a/src/match_hashed.c b/src/match_hashed.c index ba0c47c3..049dd28d 100644 --- a/src/match_hashed.c +++ b/src/match_hashed.c @@ -101,7 +101,7 @@ static int mh_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ mh_match_t *m; int i; - m = (mh_match_t *) malloc (sizeof (*m)); + m = malloc (sizeof (*m)); if (m == NULL) { ERROR ("mh_create: malloc failed."); diff --git a/src/match_regex.c b/src/match_regex.c index 4fa6ce78..7429ffaf 100644 --- a/src/match_regex.c +++ b/src/match_regex.c @@ -140,7 +140,7 @@ static int mr_config_add_regex (mr_regex_t **re_head, /* {{{ */ return (-1); } - re = (mr_regex_t *) malloc (sizeof (*re)); + re = malloc (sizeof (*re)); if (re == NULL) { log_err ("mr_config_add_regex: malloc failed."); @@ -194,7 +194,7 @@ static int mr_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ int status; int i; - m = (mr_match_t *) malloc (sizeof (*m)); + m = malloc (sizeof (*m)); if (m == NULL) { log_err ("mr_create: malloc failed."); diff --git a/src/match_timediff.c b/src/match_timediff.c index 996201ad..2b5f530a 100644 --- a/src/match_timediff.c +++ b/src/match_timediff.c @@ -52,7 +52,7 @@ static int mt_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ int status; int i; - m = (mt_match_t *) malloc (sizeof (*m)); + m = malloc (sizeof (*m)); if (m == NULL) { ERROR ("mt_create: malloc failed."); diff --git a/src/match_value.c b/src/match_value.c index 9ffcecaa..9b13aa86 100644 --- a/src/match_value.c +++ b/src/match_value.c @@ -200,7 +200,7 @@ static int mv_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ int status; int i; - m = (mv_match_t *) malloc (sizeof (*m)); + m = malloc (sizeof (*m)); if (m == NULL) { ERROR ("mv_create: malloc failed."); diff --git a/src/memcachec.c b/src/memcachec.c index 013b6c4e..a23d4956 100644 --- a/src/memcachec.c +++ b/src/memcachec.c @@ -206,7 +206,7 @@ static int cmc_config_add_match (web_page_t *page, /* {{{ */ WARNING ("memcachec plugin: Ignoring arguments for the `Match' block."); } - match = (web_match_t *) malloc (sizeof (*match)); + match = malloc (sizeof (*match)); if (match == NULL) { ERROR ("memcachec plugin: malloc failed."); @@ -305,7 +305,7 @@ static int cmc_config_add_page (oconfig_item_t *ci) /* {{{ */ return (-1); } - page = (web_page_t *) malloc (sizeof (*page)); + page = malloc (sizeof (*page)); if (page == NULL) { ERROR ("memcachec plugin: malloc failed."); diff --git a/src/mysql.c b/src/mysql.c index 38507456..029796e6 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -113,7 +113,7 @@ static int mysql_config_database (oconfig_item_t *ci) /* {{{ */ return (-1); } - db = (mysql_database_t *) malloc (sizeof (*db)); + db = malloc (sizeof (*db)); if (db == NULL) { ERROR ("mysql plugin: malloc failed."); diff --git a/src/netapp.c b/src/netapp.c index 8a8a7fe4..555abcc8 100644 --- a/src/netapp.c +++ b/src/netapp.c @@ -464,7 +464,7 @@ static disk_t *get_disk(cfg_disk_t *cd, const char *name) /* {{{ */ return d; } - d = malloc(sizeof(*d)); + d = malloc (sizeof (*d)); if (d == NULL) return (NULL); memset (d, 0, sizeof (*d)); @@ -2827,7 +2827,7 @@ static host_config_t *cna_alloc_host (void) /* {{{ */ { host_config_t *host; - host = malloc(sizeof(*host)); + host = malloc (sizeof (*host)); if (! host) return (NULL); memset (host, 0, sizeof (*host)); diff --git a/src/netlink.c b/src/netlink.c index d4661ce8..c5f66f83 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -109,7 +109,7 @@ static int add_ignorelist (const char *dev, const char *type, { ir_ignorelist_t *entry; - entry = (ir_ignorelist_t *) malloc (sizeof (ir_ignorelist_t)); + entry = malloc (sizeof (*entry)); if (entry == NULL) return (-1); diff --git a/src/network.c b/src/network.c index 086f04ec..ed382a06 100644 --- a/src/network.c +++ b/src/network.c @@ -618,14 +618,14 @@ static int write_part_values (char **ret_buffer, int *ret_buffer_len, if (*ret_buffer_len < packet_len) return (-1); - pkg_values_types = (uint8_t *) malloc (num_values * sizeof (uint8_t)); + pkg_values_types = malloc (num_values * sizeof (*pkg_values_types)); if (pkg_values_types == NULL) { ERROR ("network plugin: write_part_values: malloc failed."); return (-1); } - pkg_values = (value_t *) malloc (num_values * sizeof (value_t)); + pkg_values = malloc (num_values * sizeof (*pkg_values)); if (pkg_values == NULL) { free (pkg_values_types); @@ -2495,7 +2495,7 @@ static int network_receive (void) /* {{{ */ * these entries in the dispatch thread but put them in * another list, so we don't have to allocate more and * more of these structures. */ - ent = malloc (sizeof (receive_list_entry_t)); + ent = malloc (sizeof (*ent)); if (ent == NULL) { ERROR ("network plugin: malloc failed."); @@ -2503,7 +2503,7 @@ static int network_receive (void) /* {{{ */ break; } memset (ent, 0, sizeof (receive_list_entry_t)); - ent->data = malloc (network_config_packet_size); + ent->data = malloc (*ent->data); if (ent->data == NULL) { sfree (ent); diff --git a/src/nut.c b/src/nut.c index d5ecc98d..9540d7c4 100644 --- a/src/nut.c +++ b/src/nut.c @@ -80,7 +80,7 @@ static int nut_add_ups (const char *name) DEBUG ("nut plugin: nut_add_ups (name = %s);", name); - ups = (nut_ups_t *) malloc (sizeof (nut_ups_t)); + ups = malloc (sizeof (*ups)); if (ups == NULL) { ERROR ("nut plugin: nut_add_ups: malloc failed."); @@ -152,7 +152,7 @@ static int nut_read_one (nut_ups_t *ups) /* (Re-)Connect if we have no connection */ if (ups->conn == NULL) { - ups->conn = (collectd_upsconn_t *) malloc (sizeof (collectd_upsconn_t)); + ups->conn = malloc (sizeof (*ups->conn)); if (ups->conn == NULL) { ERROR ("nut plugin: malloc failed."); diff --git a/src/onewire.c b/src/onewire.c index 3c441ecb..42bd1eb8 100644 --- a/src/onewire.c +++ b/src/onewire.c @@ -176,11 +176,11 @@ static int direct_list_insert(const char * config) { regmatch_t pmatch[3]; size_t nmatch = 3; - direct_access_element_t *element = NULL; + direct_access_element_t *element; DEBUG ("onewire plugin: direct_list_insert <%s>", config); - element = (direct_access_element_t *) malloc (sizeof(*element)); + element = malloc (sizeof (*element)); if (element == NULL) { ERROR ("onewire plugin: direct_list_insert - cannot allocate element"); diff --git a/src/openvpn.c b/src/openvpn.c index 8bccce38..ec76a7aa 100644 --- a/src/openvpn.c +++ b/src/openvpn.c @@ -699,7 +699,7 @@ static int openvpn_config (const char *key, const char *value) } /* create a new vpn element since file, version and name are ok */ - temp = (vpn_status_t *) malloc (sizeof (vpn_status_t)); + temp = malloc (sizeof (*temp)); if (temp == NULL) { char errbuf[1024]; diff --git a/src/oracle.c b/src/oracle.c index ab0812b7..84d9ed49 100644 --- a/src/oracle.c +++ b/src/oracle.c @@ -198,7 +198,7 @@ static int o_config_add_database (oconfig_item_t *ci) /* {{{ */ return (-1); } - db = (o_database_t *) malloc (sizeof (*db)); + db = malloc (sizeof (*db)); if (db == NULL) { ERROR ("oracle plugin: malloc failed."); diff --git a/src/perl.c b/src/perl.c index c25bfe89..920e7b3f 100644 --- a/src/perl.c +++ b/src/perl.c @@ -437,7 +437,7 @@ static int av2data_set (pTHX_ AV *array, char *name, data_set_t *ds) return -1; } - ds->ds = (data_source_t *)smalloc ((len + 1) * sizeof (data_source_t)); + ds->ds = smalloc ((len + 1) * sizeof (*ds->ds)); ds->ds_num = len + 1; for (i = 0; i <= len; ++i) { @@ -501,7 +501,7 @@ static int av2notification_meta (pTHX_ AV *array, notification_meta_t **meta) hash = (HV *)SvRV (*tmp); - *m = (notification_meta_t *)smalloc (sizeof (**m)); + *m = smalloc (sizeof (**m)); if (NULL == (tmp = hv_fetch (hash, "name", 4, 0))) { log_warn ("av2notification_meta: Skipping invalid " @@ -1218,7 +1218,7 @@ static c_ithread_t *c_ithread_create (PerlInterpreter *base) assert (NULL != perl_threads); - t = (c_ithread_t *)smalloc (sizeof (c_ithread_t)); + t = smalloc (sizeof (*t)); memset (t, 0, sizeof (c_ithread_t)); t->interp = (NULL == base) @@ -1428,7 +1428,7 @@ static int fc_create (int type, const oconfig_item_t *ci, void **user_data) return -1; } - data = (pfc_user_data_t *)smalloc (sizeof (*data)); + data = smalloc (sizeof (*data)); data->name = sstrdup (ci->values[0].value.string); data->user_data = newSV (0); @@ -2252,7 +2252,7 @@ static int init_pi (int argc, char **argv) #endif PERL_SYS_INIT3 (&argc, &argv, &environ); - perl_threads = (c_ithread_list_t *)smalloc (sizeof (c_ithread_list_t)); + perl_threads = smalloc (sizeof (*perl_threads)); memset (perl_threads, 0, sizeof (c_ithread_list_t)); pthread_mutex_init (&perl_threads->mutex, NULL); @@ -2394,7 +2394,7 @@ static int perl_config_enabledebugger (pTHX_ oconfig_item_t *ci) perl_argv[perl_argc - 1] = "-d"; } else { - perl_argv[perl_argc - 1] = (char *)smalloc (strlen (value) + 4); + perl_argv[perl_argc - 1] = smalloc (strlen (value) + 4); sstrncpy (perl_argv[perl_argc - 1], "-d:", 4); sstrncpy (perl_argv[perl_argc - 1] + 3, value, strlen (value) + 1); } @@ -2427,7 +2427,7 @@ static int perl_config_includedir (pTHX_ oconfig_item_t *ci) exit (3); } - perl_argv[perl_argc - 1] = (char *)smalloc (strlen (value) + 3); + perl_argv[perl_argc - 1] = smalloc (strlen (value) + 3); sstrncpy(perl_argv[perl_argc - 1], "-I", 3); sstrncpy(perl_argv[perl_argc - 1] + 2, value, strlen (value) + 1); @@ -2545,7 +2545,7 @@ static int perl_config (oconfig_item_t *ci) void module_register (void) { perl_argc = 4; - perl_argv = (char **)smalloc ((perl_argc + 1) * sizeof (char *)); + perl_argv = smalloc ((perl_argc + 1) * sizeof (*perl_argv)); /* default options for the Perl interpreter */ perl_argv[0] = ""; diff --git a/src/ping.c b/src/ping.c index da63d3a5..b6b2b688 100644 --- a/src/ping.c +++ b/src/ping.c @@ -483,7 +483,7 @@ static int ping_config (const char *key, const char *value) /* {{{ */ hostlist_t *hl; char *host; - hl = (hostlist_t *) malloc (sizeof (hostlist_t)); + hl = malloc (sizeof (*hl)); if (hl == NULL) { char errbuf[1024]; diff --git a/src/postgresql.c b/src/postgresql.c index 79226830..d532906c 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -218,7 +218,7 @@ static c_psql_database_t *c_psql_database_new (const char *name) c_psql_database_t **tmp; c_psql_database_t *db; - db = (c_psql_database_t *)malloc (sizeof(*db)); + db = malloc (sizeof(*db)); if (NULL == db) { log_err ("Out of memory."); return NULL; diff --git a/src/powerdns.c b/src/powerdns.c index ab62dcfd..e80ca8a5 100644 --- a/src/powerdns.c +++ b/src/powerdns.c @@ -465,7 +465,7 @@ static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */ return (-1); assert (buffer_size > 0); - buffer = (char *) malloc (buffer_size); + buffer = malloc (buffer_size); if (buffer == NULL) { FUNC_ERROR ("malloc"); @@ -840,7 +840,7 @@ static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */ return (-1); } - item = (list_item_t *) malloc (sizeof (list_item_t)); + item = malloc (sizeof (*item)); if (item == NULL) { ERROR ("powerdns plugin: malloc failed."); diff --git a/src/processes.c b/src/processes.c index d0d73615..d2c0f44c 100644 --- a/src/processes.c +++ b/src/processes.c @@ -262,7 +262,7 @@ static void ps_list_register (const char *name, const char *regexp) procstat_t *ptr; int status; - new = (procstat_t *) malloc (sizeof (procstat_t)); + new = malloc (sizeof (*new)); if (new == NULL) { ERROR ("processes plugin: ps_list_register: malloc failed."); @@ -275,7 +275,7 @@ static void ps_list_register (const char *name, const char *regexp) if (regexp != NULL) { DEBUG ("ProcessMatch: adding \"%s\" as criteria to process %s.", regexp, name); - new->re = (regex_t *) malloc (sizeof (regex_t)); + new->re = malloc (sizeof (*new->re)); if (new->re == NULL) { ERROR ("processes plugin: ps_list_register: malloc failed."); @@ -410,7 +410,7 @@ static void ps_list_add (const char *name, const char *cmdline, procstat_entry_t { procstat_entry_t *new; - new = (procstat_entry_t *) malloc (sizeof (procstat_entry_t)); + new = malloc (sizeof (*new)); if (new == NULL) return; memset (new, 0, sizeof (procstat_entry_t)); diff --git a/src/rrdtool.c b/src/rrdtool.c index fd5fb563..6b44f67e 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -166,7 +166,7 @@ static int srrd_update (char *filename, char *template, assert (template == NULL); new_argc = 2 + argc; - new_argv = (char **) malloc ((new_argc + 1) * sizeof (char *)); + new_argv = malloc ((new_argc + 1) * sizeof (*new_argv)); if (new_argv == NULL) { ERROR ("rrdtool plugin: malloc failed."); @@ -480,7 +480,7 @@ static int rrd_queue_enqueue (const char *filename, { rrd_queue_t *queue_entry; - queue_entry = (rrd_queue_t *) malloc (sizeof (rrd_queue_t)); + queue_entry = malloc (sizeof (*queue_entry)); if (queue_entry == NULL) return (-1); diff --git a/src/sensors.c b/src/sensors.c index c678dec9..3b453b15 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -378,7 +378,7 @@ static int sensors_load_conf (void) continue; } - fl = (featurelist_t *) malloc (sizeof (featurelist_t)); + fl = malloc (sizeof (*fl)); if (fl == NULL) { ERROR ("sensors plugin: malloc failed."); @@ -435,7 +435,7 @@ static int sensors_load_conf (void) && (subfeature->type != SENSORS_SUBFEATURE_POWER_INPUT)) continue; - fl = (featurelist_t *) malloc (sizeof (featurelist_t)); + fl = malloc (sizeof (*fl)); if (fl == NULL) { ERROR ("sensors plugin: malloc failed."); diff --git a/src/sigrok.c b/src/sigrok.c index ad5c70c0..4e61f946 100644 --- a/src/sigrok.c +++ b/src/sigrok.c @@ -72,7 +72,7 @@ static int sigrok_config_device(oconfig_item_t *ci) struct config_device *cfdev; int i; - if (!(cfdev = malloc(sizeof(struct config_device)))) { + if (!(cfdev = malloc(sizeof(*cfdev)))) { ERROR("sigrok plugin: malloc() failed."); return -1; } @@ -236,14 +236,14 @@ static int sigrok_init_driver(struct config_device *cfdev, drvopts = NULL; if (cfdev->conn) { - if (!(src = malloc(sizeof(struct sr_config)))) + if (!(src = malloc(sizeof(*src)))) return -1; src->key = SR_CONF_CONN; src->data = g_variant_new_string(cfdev->conn); drvopts = g_slist_append(drvopts, src); } if (cfdev->serialcomm) { - if (!(src = malloc(sizeof(struct sr_config)))) + if (!(src = malloc(sizeof(*src)))) return -1; src->key = SR_CONF_SERIALCOMM; src->data = g_variant_new_string(cfdev->serialcomm); diff --git a/src/snmp.c b/src/snmp.c index 3ccf60c3..e1f1f754 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -310,7 +310,7 @@ static int csnmp_config_add_data_values (data_definition_t *dd, oconfig_item_t * sfree (dd->values); dd->values_len = 0; - dd->values = (oid_t *) malloc (sizeof (oid_t) * ci->values_num); + dd->values = malloc (sizeof (*dd->values) * ci->values_num); if (dd->values == NULL) return (-1); dd->values_len = (size_t) ci->values_num; @@ -384,7 +384,7 @@ static int csnmp_config_add_data (oconfig_item_t *ci) int status = 0; int i; - dd = (data_definition_t *) malloc (sizeof (data_definition_t)); + dd = malloc (sizeof (*dd)); if (dd == NULL) return (-1); memset (dd, '\0', sizeof (data_definition_t)); @@ -646,7 +646,7 @@ static int csnmp_config_add_host (oconfig_item_t *ci) char cb_name[DATA_MAX_NAME_LEN]; user_data_t cb_data; - hd = (host_definition_t *) malloc (sizeof (host_definition_t)); + hd = malloc (sizeof (*hd)); if (hd == NULL) return (-1); memset (hd, '\0', sizeof (host_definition_t)); @@ -1710,7 +1710,7 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data) } vl.values_len = ds->ds_num; - vl.values = (value_t *) malloc (sizeof (value_t) * vl.values_len); + vl.values = malloc (sizeof (*vl.values) * vl.values_len); if (vl.values == NULL) return (-1); for (i = 0; i < vl.values_len; i++) diff --git a/src/tail_csv.c b/src/tail_csv.c index bb9b58ac..15c083ea 100644 --- a/src/tail_csv.c +++ b/src/tail_csv.c @@ -290,7 +290,7 @@ static int tcsv_config_add_metric(oconfig_item_t *ci){ int status; int i; - md = (metric_definition_t *)malloc(sizeof(*md)); + md = malloc(sizeof(*md)); if (md == NULL) return (-1); memset(md, 0, sizeof(*md)); diff --git a/src/target_notification.c b/src/target_notification.c index 14fb5418..d850a684 100644 --- a/src/target_notification.c +++ b/src/target_notification.c @@ -126,7 +126,7 @@ static int tn_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ int status; int i; - data = (tn_data_t *) malloc (sizeof (*data)); + data = malloc (sizeof (*data)); if (data == NULL) { ERROR ("tn_create: malloc failed."); diff --git a/src/target_replace.c b/src/target_replace.c index bd8f9e5c..2166746c 100644 --- a/src/target_replace.c +++ b/src/target_replace.c @@ -61,7 +61,7 @@ static char *tr_strdup (const char *orig) /* {{{ */ return (NULL); sz = strlen (orig) + 1; - dest = (char *) malloc (sz); + dest = malloc (sz); if (dest == NULL) return (NULL); @@ -102,7 +102,7 @@ static int tr_config_add_action (tr_action_t **dest, /* {{{ */ return (-1); } - act = (tr_action_t *) malloc (sizeof (*act)); + act = malloc (sizeof (*act)); if (act == NULL) { ERROR ("tr_config_add_action: malloc failed."); @@ -244,7 +244,7 @@ static int tr_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ int status; int i; - data = (tr_data_t *) malloc (sizeof (*data)); + data = malloc (sizeof (*data)); if (data == NULL) { ERROR ("tr_create: malloc failed."); diff --git a/src/target_scale.c b/src/target_scale.c index 6169fa05..b667ed13 100644 --- a/src/target_scale.c +++ b/src/target_scale.c @@ -387,7 +387,7 @@ static int ts_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ int status; int i; - data = (ts_data_t *) malloc (sizeof (*data)); + data = malloc (sizeof (*data)); if (data == NULL) { ERROR ("ts_create: malloc failed."); diff --git a/src/target_set.c b/src/target_set.c index daeaf8be..a676a3d1 100644 --- a/src/target_set.c +++ b/src/target_set.c @@ -87,7 +87,7 @@ static int ts_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ int status; int i; - data = (ts_data_t *) malloc (sizeof (*data)); + data = malloc (sizeof (*data)); if (data == NULL) { ERROR ("ts_create: malloc failed."); diff --git a/src/tcpconns.c b/src/tcpconns.c index 5b47ff53..96221b19 100644 --- a/src/tcpconns.c +++ b/src/tcpconns.c @@ -385,7 +385,7 @@ static port_entry_t *conn_get_port_entry (uint16_t port, int create) if ((ret == NULL) && (create != 0)) { - ret = (port_entry_t *) malloc (sizeof (port_entry_t)); + ret = malloc (sizeof (*ret)); if (ret == NULL) return (NULL); memset (ret, '\0', sizeof (port_entry_t)); @@ -832,7 +832,7 @@ static int conn_read (void) return (-1); } - buffer = (char *) malloc (buffer_len); + buffer = malloc (buffer_len); if (buffer == NULL) { ERROR ("tcpconns plugin: malloc failed."); diff --git a/src/teamspeak2.c b/src/teamspeak2.c index 058eb7c3..345f57e0 100644 --- a/src/teamspeak2.c +++ b/src/teamspeak2.c @@ -83,7 +83,7 @@ static int tss2_add_vserver (int vserver_port) } /* Allocate memory */ - entry = (vserver_list_t *) malloc (sizeof (vserver_list_t)); + entry = malloc (sizeof (*entry)); if (entry == NULL) { ERROR ("teamspeak2 plugin: malloc failed."); diff --git a/src/threshold.c b/src/threshold.c index ed831299..624ab7a9 100644 --- a/src/threshold.c +++ b/src/threshold.c @@ -70,7 +70,7 @@ static int ut_threshold_add (const threshold_t *th) return (-1); } - th_copy = (threshold_t *) malloc (sizeof (threshold_t)); + th_copy = malloc (sizeof (*th_copy)); if (th_copy == NULL) { sfree (name_copy); diff --git a/src/unixsock.c b/src/unixsock.c index 795f7abe..1840e34c 100644 --- a/src/unixsock.c +++ b/src/unixsock.c @@ -368,7 +368,7 @@ static void *us_server_thread (void __attribute__((unused)) *arg) pthread_exit ((void *) 1); } - remote_fd = (int *) malloc (sizeof (int)); + remote_fd = malloc (sizeof (*remote_fd)); if (remote_fd == NULL) { char errbuf[1024]; diff --git a/src/utils_cmd_putval.c b/src/utils_cmd_putval.c index 43244f61..69af2e4a 100644 --- a/src/utils_cmd_putval.c +++ b/src/utils_cmd_putval.c @@ -163,7 +163,7 @@ int handle_putval (FILE *fh, char *buffer) sfree (identifier_copy); vl.values_len = ds->ds_num; - vl.values = (value_t *) malloc (vl.values_len * sizeof (value_t)); + vl.values = malloc (vl.values_len * sizeof (*vl.values)); if (vl.values == NULL) { print_to_socket (fh, "-1 malloc failed.\n"); diff --git a/src/utils_db_query.c b/src/utils_db_query.c index c7be9f0d..d003e7fa 100644 --- a/src/utils_db_query.c +++ b/src/utils_db_query.c @@ -550,7 +550,7 @@ static int udb_result_create (const char *query_name, /* {{{ */ ci->values_num, (ci->values_num == 1) ? "" : "s"); } - r = (udb_result_t *) malloc (sizeof (*r)); + r = malloc (sizeof (*r)); if (r == NULL) { ERROR ("db query utils: malloc failed."); @@ -678,7 +678,7 @@ int udb_query_create (udb_query_t ***ret_query_list, /* {{{ */ return (-1); } - q = (udb_query_t *) malloc (sizeof (*q)); + q = malloc (sizeof (*q)); if (q == NULL) { ERROR ("db query utils: malloc failed."); diff --git a/src/utils_dns.c b/src/utils_dns.c index 2c7a59d3..991d346a 100644 --- a/src/utils_dns.c +++ b/src/utils_dns.c @@ -209,7 +209,7 @@ static void ignore_list_add (const struct in6_addr *addr) if (ignore_list_match (addr) != 0) return; - new = malloc (sizeof (ip_list_t)); + new = malloc (sizeof (*new)); if (new == NULL) { perror ("malloc"); diff --git a/src/utils_mount.c b/src/utils_mount.c index 752d2e15..ecf011d8 100644 --- a/src/utils_mount.c +++ b/src/utils_mount.c @@ -467,8 +467,7 @@ static cu_mount_t *cu_mount_getfsstat (void) return (NULL); } - if ((buf = (STRUCT_STATFS *) malloc (bufsize * sizeof (STRUCT_STATFS))) - == NULL) + if ((buf = malloc (bufsize * sizeof (*buf))) == NULL) return (NULL); memset (buf, '\0', bufsize * sizeof (STRUCT_STATFS)); @@ -487,7 +486,7 @@ static cu_mount_t *cu_mount_getfsstat (void) for (i = 0; i < num; i++) { - if ((new = malloc (sizeof (cu_mount_t))) == NULL) + if ((new = malloc (sizeof (*new))) == NULL) break; memset (new, '\0', sizeof (cu_mount_t)); @@ -541,7 +540,7 @@ static cu_mount_t *cu_mount_gen_getmntent (void) while (getmntent (fp, &mt) == 0) { - if ((new = malloc (sizeof (cu_mount_t))) == NULL) + if ((new = malloc (sizeof (*new))) == NULL) break; memset (new, '\0', sizeof (cu_mount_t)); @@ -599,7 +598,7 @@ static cu_mount_t *cu_mount_getmntent (void) while (getmntent_r (fp, &me, mntbuf, sizeof (mntbuf) )) { - if ((new = malloc (sizeof (cu_mount_t))) == NULL) + if ((new = malloc (sizeof (*new))) == NULL) break; memset (new, '\0', sizeof (cu_mount_t)); @@ -656,7 +655,7 @@ static cu_mount_t *cu_mount_getmntent (void) while ((me = getmntent (fp)) != NULL) { - if ((new = malloc (sizeof (cu_mount_t))) == NULL) + if ((new = malloc (sizeof (*new))) == NULL) break; memset (new, '\0', sizeof (cu_mount_t)); @@ -820,7 +819,7 @@ cu_mount_getoptionvalue(char *line, const char *keyword) if((p-r) == 1) { return NULL; } - m = (char *)smalloc(p-r+1); + m = smalloc(p-r+1); sstrncpy(m, r, p-r+1); return m; } diff --git a/src/utils_rrdcreate.c b/src/utils_rrdcreate.c index 06e4f21b..44c2386f 100644 --- a/src/utils_rrdcreate.c +++ b/src/utils_rrdcreate.c @@ -421,7 +421,7 @@ static int srrd_create (const char *filename, /* {{{ */ char last_up_str[16]; new_argc = 6 + argc; - new_argv = (char **) malloc ((new_argc + 1) * sizeof (char *)); + new_argv = malloc ((new_argc + 1) * sizeof (*new_argv)); if (new_argv == NULL) { ERROR ("rrdtool plugin: malloc failed."); @@ -689,7 +689,7 @@ int cu_rrd_create_file (const char *filename, /* {{{ */ argc = ds_num + rra_num; - if ((argv = (char **) malloc (sizeof (char *) * (argc + 1))) == NULL) + if ((argv = malloc (sizeof (*argv) * (argc + 1))) == NULL) { char errbuf[1024]; ERROR ("cu_rrd_create_file failed: %s", diff --git a/src/virt.c b/src/virt.c index 79d46826..bbf5afc7 100644 --- a/src/virt.c +++ b/src/virt.c @@ -686,7 +686,7 @@ refresh_lists (void) int *domids; /* Get list of domains. */ - domids = malloc (sizeof (int) * n); + domids = malloc (sizeof (*domids) * n); if (domids == 0) { ERROR (PLUGIN_NAME " plugin: malloc failed."); return -1; diff --git a/src/zone.c b/src/zone.c index 15eae6a2..52dc5539 100644 --- a/src/zone.c +++ b/src/zone.c @@ -115,11 +115,11 @@ zone_find_stats(c_avl_tree_t *tree, zoneid_t zoneid) zoneid_t *key = NULL; if (c_avl_get(tree, (void **)&zoneid, (void **)&ret)) { - if (!(ret = malloc(sizeof(zone_stats_t)))) { + if (!(ret = malloc(sizeof(*ret)))) { WARNING("zone plugin: no memory"); return(NULL); } - if (!(key = malloc(sizeof(zoneid_t)))) { + if (!(key = malloc(sizeof(*key)))) { WARNING("zone plugin: no memory"); return(NULL); } -- 2.11.0