From: Ruben Kerkhof Date: Fri, 1 Apr 2016 15:55:19 +0000 (+0200) Subject: network plugin: malloc + memset -> calloc X-Git-Tag: collectd-5.6.0~371^2~27 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8bffdff5ed03031a9d7261476118b7d99a0fcd97;p=collectd.git network plugin: malloc + memset -> calloc --- diff --git a/src/network.c b/src/network.c index ed382a06..6be4ed59 100644 --- a/src/network.c +++ b/src/network.c @@ -2012,10 +2012,9 @@ static sockent_t *sockent_create (int type) /* {{{ */ if ((type != SOCKENT_TYPE_CLIENT) && (type != SOCKENT_TYPE_SERVER)) return (NULL); - se = malloc (sizeof (*se)); + se = calloc (1, sizeof (*se)); if (se == NULL) return (NULL); - memset (se, 0, sizeof (*se)); se->type = type; se->node = NULL; @@ -2196,16 +2195,15 @@ static int sockent_client_connect (sockent_t *se) /* {{{ */ continue; } - client->addr = malloc (sizeof (*client->addr)); + client->addr = calloc (1, sizeof (*client->addr)); if (client->addr == NULL) { - ERROR ("network plugin: malloc failed."); + ERROR ("network plugin: calloc failed."); close (client->fd); client->fd = -1; continue; } - memset (client->addr, 0, sizeof (*client->addr)); assert (sizeof (*client->addr) >= ai_ptr->ai_addrlen); memcpy (client->addr, ai_ptr->ai_addr, ai_ptr->ai_addrlen); client->addrlen = ai_ptr->ai_addrlen; @@ -2495,14 +2493,14 @@ 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 (*ent)); + ent = calloc (1, sizeof (*ent)); if (ent == NULL) { - ERROR ("network plugin: malloc failed."); + ERROR ("network plugin: calloc failed."); status = ENOMEM; break; } - memset (ent, 0, sizeof (receive_list_entry_t)); + ent->data = malloc (*ent->data); if (ent->data == NULL) {