X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fceph.c;h=d928a7ba4b5db1d71e87449f635783e44000f621;hb=0b68a27050ffbe8ce115d644fc572860b51b3707;hp=1b1f40b458c44f9eb573f54c74730bb0056d13e3;hpb=0febfbd11d87acd8a0f10bbcf5d4a58bb68b8dc0;p=collectd.git diff --git a/src/ceph.c b/src/ceph.c index 1b1f40b4..d928a7ba 100644 --- a/src/ceph.c +++ b/src/ceph.c @@ -21,6 +21,7 @@ * Dan Ryder **/ +#define _DEFAULT_SOURCE #define _BSD_SOURCE #include "collectd.h" @@ -656,7 +657,8 @@ static int cc_handle_bool(struct oconfig_item_s *item, int *dest) static int cc_add_daemon_config(oconfig_item_t *ci) { int ret, i; - struct ceph_daemon *array, *nd, cd; + struct ceph_daemon *nd, cd; + struct ceph_daemon **tmp; memset(&cd, 0, sizeof(struct ceph_daemon)); if((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) @@ -708,21 +710,21 @@ static int cc_add_daemon_config(oconfig_item_t *ci) return -EINVAL; } - array = realloc(g_daemons, - sizeof(struct ceph_daemon *) * (g_num_daemons + 1)); - if(array == NULL) + tmp = realloc(g_daemons, (g_num_daemons+1) * sizeof(*g_daemons)); + if(tmp == NULL) { /* The positive return value here indicates that this is a * runtime error, not a configuration error. */ return ENOMEM; } - g_daemons = (struct ceph_daemon**) array; - nd = malloc(sizeof(struct ceph_daemon)); + g_daemons = tmp; + + nd = malloc(sizeof(*nd)); if(!nd) { return ENOMEM; } - memcpy(nd, &cd, sizeof(struct ceph_daemon)); + memcpy(nd, &cd, sizeof(*nd)); g_daemons[g_num_daemons++] = nd; return 0; }