From: Ruben Kerkhof Date: Fri, 1 Apr 2016 14:00:53 +0000 (+0200) Subject: exec plugin: malloc + memset -> calloc X-Git-Tag: collectd-5.6.0~371^2~40 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ac7b627107467098795f0d078cdb9e72546baea8;p=collectd.git exec plugin: malloc + memset -> calloc --- diff --git a/src/exec.c b/src/exec.c index 4c45dc15..85f6cb80 100644 --- a/src/exec.c +++ b/src/exec.c @@ -126,13 +126,12 @@ static int exec_config_exec (oconfig_item_t *ci) /* {{{ */ return (-1); } - pl = malloc (sizeof (*pl)); + pl = calloc (1, sizeof (*pl)); if (pl == NULL) { - ERROR ("exec plugin: malloc failed."); + ERROR ("exec plugin: calloc failed."); return (-1); } - memset (pl, '\0', sizeof (program_list_t)); if (strcasecmp ("NotificationExec", ci->key) == 0) pl->flags |= PL_NOTIF_ACTION; @@ -163,16 +162,15 @@ static int exec_config_exec (oconfig_item_t *ci) /* {{{ */ return (-1); } - pl->argv = malloc (ci->values_num * sizeof (*pl->argv)); + pl->argv = calloc (ci->values_num, sizeof (*pl->argv)); if (pl->argv == NULL) { - ERROR ("exec plugin: malloc failed."); + ERROR ("exec plugin: calloc failed."); sfree (pl->exec); sfree (pl->user); sfree (pl); return (-1); } - memset (pl->argv, '\0', ci->values_num * sizeof (char *)); { char *tmp = strrchr (ci->values[1].value.string, '/'); @@ -184,7 +182,7 @@ static int exec_config_exec (oconfig_item_t *ci) /* {{{ */ pl->argv[0] = strdup (buffer); if (pl->argv[0] == NULL) { - ERROR ("exec plugin: malloc failed."); + ERROR ("exec plugin: strdup failed."); sfree (pl->argv); sfree (pl->exec); sfree (pl->user);