virt: Replace malloc with calloc for array allocations
authorRadoslaw Jablonski <radoslawx.jablonski@intel.com>
Mon, 26 Mar 2018 10:18:19 +0000 (11:18 +0100)
committerRadoslaw Jablonski <radoslawx.jablonski@intel.com>
Thu, 19 Apr 2018 12:03:40 +0000 (13:03 +0100)
Change-Id: I5720ea4c4a237eca7aac19e2cdf7a37194c4c69c
Signed-off-by: Radoslaw Jablonski <radoslawx.jablonski@intel.com>
src/virt.c

index e01efd3..4dc8645 100644 (file)
@@ -1919,9 +1919,9 @@ static int persistent_domains_state_notification(void) {
   if (n > 0) {
     int *domids;
     /* Get list of domains. */
   if (n > 0) {
     int *domids;
     /* Get list of domains. */
-    domids = malloc(sizeof(*domids) * n);
+    domids = calloc(n, sizeof(*domids));
     if (domids == NULL) {
     if (domids == NULL) {
-      ERROR(PLUGIN_NAME " plugin: malloc failed.");
+      ERROR(PLUGIN_NAME " plugin: calloc failed.");
       return -1;
     }
     n = virConnectListDomains(conn, domids, n);
       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. */
   int *domids;
 
   /* Get list of domains. */
-  domids = malloc(sizeof(*domids) * n);
+  domids = calloc(n, sizeof(*domids));
   if (domids == NULL) {
   if (domids == NULL) {
-    ERROR(PLUGIN_NAME " plugin: malloc failed.");
+    ERROR(PLUGIN_NAME " plugin: calloc failed.");
     return -1;
   }
 
     return -1;
   }