]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
locking: sanlock: Avoid use of VIR_ALLOC_VAR for 'struct sanlk_resource'
authorPeter Krempa <pkrempa@redhat.com>
Wed, 3 Feb 2021 12:31:15 +0000 (13:31 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 3 Feb 2021 15:09:25 +0000 (16:09 +0100)
In both cases we need memory for a 'struct sanlk_resource' followed by
one 'struct sanlk_disk', thus there's no risk of overflow.

Use g_malloc0 and sizeof() to allocate the memory instead of
VIR_ALLOC_VAR.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/locking/lock_driver_sanlock.c

index f35a0c065c29e67edb6562c3c72027820a511f5a..7319f56819215e4fe809420f3d2c77a7aee52555 100644 (file)
@@ -531,8 +531,7 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
     g_autofree struct sanlk_resource *res = NULL;
     size_t i;
 
-    if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0)
-        return -1;
+    res = g_malloc0(sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk));
 
     res->flags = shared ? SANLK_RES_SHARED : 0;
     res->num_disks = 1;
@@ -591,8 +590,7 @@ virLockManagerSanlockAddDisk(virLockManagerSanlockDriverPtr driver,
         return -1;
     }
 
-    if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0)
-        return -1;
+    res = g_malloc0(sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk));
 
     res->flags = shared ? SANLK_RES_SHARED : 0;
     res->num_disks = 1;