]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Use size_t for ndevice in pool source definition
authorJán Tomko <jtomko@redhat.com>
Tue, 11 Mar 2014 08:13:15 +0000 (09:13 +0100)
committerJán Tomko <jtomko@redhat.com>
Wed, 12 Mar 2014 14:51:40 +0000 (15:51 +0100)
This allows it to be used by the VIR_*_ELEMENT macros.

Also use them for parsing the definiton and remove the redundant
freeing of 'nodeset' before jumping to the cleanup label.

src/conf/storage_conf.c
src/conf/storage_conf.h

index 9c2962fbfe976cf27b2c674cdbaf5135746e0302..39fb416b5a6dfa14dd24f54e50d8180c4dd32a90 100644 (file)
@@ -642,23 +642,20 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
     if (nsource < 0)
         goto cleanup;
 
-    if (nsource > 0) {
-        if (VIR_ALLOC_N(source->devices, nsource) < 0) {
-            VIR_FREE(nodeset);
+    for (i = 0; i < nsource; i++) {
+        virStoragePoolSourceDevice dev = { .path = NULL };
+        dev.path = virXMLPropString(nodeset[i], "path");
+
+        if (dev.path == NULL) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("missing storage pool source device path"));
             goto cleanup;
         }
 
-        for (i = 0; i < nsource; i++) {
-            char *path = virXMLPropString(nodeset[i], "path");
-            if (path == NULL) {
-                VIR_FREE(nodeset);
-                virReportError(VIR_ERR_XML_ERROR, "%s",
-                               _("missing storage pool source device path"));
-                goto cleanup;
-            }
-            source->devices[i].path = path;
+        if (VIR_APPEND_ELEMENT(source->devices, source->ndevice, dev) < 0) {
+            virStoragePoolSourceDeviceClear(&dev);
+            goto cleanup;
         }
-        source->ndevice = nsource;
     }
 
     source->dir = virXPathString("string(./dir/@path)", ctxt);
index 636c9aa8331eed410478df9a6509147df1d5d7ec..e410f414488627e7b32cc227dbd4e5e30bc1d0d5 100644 (file)
@@ -266,7 +266,7 @@ struct _virStoragePoolSource {
     virStoragePoolSourceHostPtr hosts;
 
     /* And either one or more devices ... */
-    int ndevice;
+    size_t ndevice;
     virStoragePoolSourceDevicePtr devices;
 
     /* Or a directory */