From: Radoslaw Jablonski Date: Mon, 26 Mar 2018 10:18:19 +0000 (+0100) Subject: virt: Replace malloc with calloc for array allocations X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=6704c1a7200212956fc9d2df639c20e529f37e8f;p=collectd.git virt: Replace malloc with calloc for array allocations Change-Id: I5720ea4c4a237eca7aac19e2cdf7a37194c4c69c Signed-off-by: Radoslaw Jablonski --- diff --git a/src/virt.c b/src/virt.c index e01efd33..4dc8645d 100644 --- a/src/virt.c +++ b/src/virt.c @@ -1919,9 +1919,9 @@ static int persistent_domains_state_notification(void) { if (n > 0) { int *domids; /* Get list of domains. */ - domids = malloc(sizeof(*domids) * n); + domids = calloc(n, sizeof(*domids)); if (domids == NULL) { - ERROR(PLUGIN_NAME " plugin: malloc failed."); + ERROR(PLUGIN_NAME " plugin: calloc failed."); return -1; } n = virConnectListDomains(conn, domids, n); @@ -2245,9 +2245,9 @@ static int refresh_lists(struct lv_read_instance *inst) { int *domids; /* Get list of domains. */ - domids = malloc(sizeof(*domids) * n); + domids = calloc(n, sizeof(*domids)); if (domids == NULL) { - ERROR(PLUGIN_NAME " plugin: malloc failed."); + ERROR(PLUGIN_NAME " plugin: calloc failed."); return -1; }