From 94b57a9de0206ace8c995c6b6fd0a11243063d76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Tue, 11 Mar 2014 09:13:15 +0100 Subject: [PATCH] Use size_t for ndevice in pool source definition 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 | 23 ++++++++++------------- src/conf/storage_conf.h | 2 +- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 9c2962fbfe..39fb416b5a 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -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); diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index 636c9aa833..e410f41448 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -266,7 +266,7 @@ struct _virStoragePoolSource { virStoragePoolSourceHostPtr hosts; /* And either one or more devices ... */ - int ndevice; + size_t ndevice; virStoragePoolSourceDevicePtr devices; /* Or a directory */