mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
storage_conf: Improve the memory deallocation of pool def parsing
Changes: * Free all the strings at "cleanup", instead of freeing them in the middle * Remove xmlFree * s/tmppath/target_path/, to make it more sensible * Add new goto label "error"
This commit is contained in:
parent
d10cfaec3b
commit
6afdfc8e13
@ -820,7 +820,7 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
|
|||||||
xmlNodePtr source_node;
|
xmlNodePtr source_node;
|
||||||
char *type = NULL;
|
char *type = NULL;
|
||||||
char *uuid = NULL;
|
char *uuid = NULL;
|
||||||
char *tmppath;
|
char *target_path = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(ret) < 0) {
|
if (VIR_ALLOC(ret) < 0) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
@ -831,21 +831,18 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
|
|||||||
if ((ret->type = virStoragePoolTypeFromString(type)) < 0) {
|
if ((ret->type = virStoragePoolTypeFromString(type)) < 0) {
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
_("unknown storage pool type %s"), type);
|
_("unknown storage pool type %s"), type);
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlFree(type);
|
|
||||||
type = NULL;
|
|
||||||
|
|
||||||
if ((options = virStoragePoolOptionsForPoolType(ret->type)) == NULL) {
|
if ((options = virStoragePoolOptionsForPoolType(ret->type)) == NULL) {
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
source_node = virXPathNode("./source", ctxt);
|
source_node = virXPathNode("./source", ctxt);
|
||||||
if (source_node) {
|
if (source_node) {
|
||||||
if (virStoragePoolDefParseSource(ctxt, &ret->source, ret->type,
|
if (virStoragePoolDefParseSource(ctxt, &ret->source, ret->type,
|
||||||
source_node) < 0)
|
source_node) < 0)
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret->name = virXPathString("string(./name)", ctxt);
|
ret->name = virXPathString("string(./name)", ctxt);
|
||||||
@ -855,7 +852,7 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
|
|||||||
if (ret->name == NULL) {
|
if (ret->name == NULL) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("missing pool source name element"));
|
_("missing pool source name element"));
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
uuid = virXPathString("string(./uuid)", ctxt);
|
uuid = virXPathString("string(./uuid)", ctxt);
|
||||||
@ -863,22 +860,21 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
|
|||||||
if (virUUIDGenerate(ret->uuid) < 0) {
|
if (virUUIDGenerate(ret->uuid) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("unable to generate uuid"));
|
_("unable to generate uuid"));
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (virUUIDParse(uuid, ret->uuid) < 0) {
|
if (virUUIDParse(uuid, ret->uuid) < 0) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("malformed uuid element"));
|
_("malformed uuid element"));
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
VIR_FREE(uuid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options->flags & VIR_STORAGE_POOL_SOURCE_HOST) {
|
if (options->flags & VIR_STORAGE_POOL_SOURCE_HOST) {
|
||||||
if (!ret->source.nhost) {
|
if (!ret->source.nhost) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("missing storage pool source host name"));
|
_("missing storage pool source host name"));
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -886,14 +882,14 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
|
|||||||
if (!ret->source.dir) {
|
if (!ret->source.dir) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("missing storage pool source path"));
|
_("missing storage pool source path"));
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (options->flags & VIR_STORAGE_POOL_SOURCE_NAME) {
|
if (options->flags & VIR_STORAGE_POOL_SOURCE_NAME) {
|
||||||
if (ret->source.name == NULL) {
|
if (ret->source.name == NULL) {
|
||||||
/* source name defaults to pool name */
|
/* source name defaults to pool name */
|
||||||
if (VIR_STRDUP(ret->source.name, ret->name) < 0)
|
if (VIR_STRDUP(ret->source.name, ret->name) < 0)
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -901,7 +897,7 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
|
|||||||
if (!ret->source.adapter.type) {
|
if (!ret->source.adapter.type) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("missing storage pool source adapter"));
|
_("missing storage pool source adapter"));
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret->source.adapter.type ==
|
if (ret->source.adapter.type ==
|
||||||
@ -911,18 +907,18 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
|
|||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("'wwnn' and 'wwpn' must be specified for adapter "
|
_("'wwnn' and 'wwpn' must be specified for adapter "
|
||||||
"type 'fchost'"));
|
"type 'fchost'"));
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virValidateWWN(ret->source.adapter.data.fchost.wwnn) ||
|
if (!virValidateWWN(ret->source.adapter.data.fchost.wwnn) ||
|
||||||
!virValidateWWN(ret->source.adapter.data.fchost.wwpn))
|
!virValidateWWN(ret->source.adapter.data.fchost.wwpn))
|
||||||
goto cleanup;
|
goto error;
|
||||||
} else if (ret->source.adapter.type ==
|
} else if (ret->source.adapter.type ==
|
||||||
VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) {
|
VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) {
|
||||||
if (!ret->source.adapter.data.name) {
|
if (!ret->source.adapter.data.name) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("missing storage pool source adapter name"));
|
_("missing storage pool source adapter name"));
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -932,36 +928,40 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
|
|||||||
if (!ret->source.ndevice) {
|
if (!ret->source.ndevice) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("missing storage pool source device name"));
|
_("missing storage pool source device name"));
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* When we are working with a virtual disk we can skip the target
|
/* When we are working with a virtual disk we can skip the target
|
||||||
* path and permissions */
|
* path and permissions */
|
||||||
if (!(options->flags & VIR_STORAGE_POOL_SOURCE_NETWORK)) {
|
if (!(options->flags & VIR_STORAGE_POOL_SOURCE_NETWORK)) {
|
||||||
if ((tmppath = virXPathString("string(./target/path)", ctxt)) == NULL) {
|
if (!(target_path = virXPathString("string(./target/path)", ctxt))) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("missing storage pool target path"));
|
_("missing storage pool target path"));
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
ret->target.path = virFileSanitizePath(tmppath);
|
ret->target.path = virFileSanitizePath(target_path);
|
||||||
VIR_FREE(tmppath);
|
|
||||||
if (!ret->target.path)
|
if (!ret->target.path)
|
||||||
goto cleanup;
|
goto error;
|
||||||
|
|
||||||
if (virStorageDefParsePerms(ctxt, &ret->target.perms,
|
if (virStorageDefParsePerms(ctxt, &ret->target.perms,
|
||||||
"./target/permissions",
|
"./target/permissions",
|
||||||
DEFAULT_POOL_PERM_MODE) < 0)
|
DEFAULT_POOL_PERM_MODE) < 0)
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(uuid);
|
VIR_FREE(uuid);
|
||||||
xmlFree(type);
|
VIR_FREE(type);
|
||||||
|
VIR_FREE(target_path);
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
error:
|
||||||
virStoragePoolDefFree(ret);
|
virStoragePoolDefFree(ret);
|
||||||
return NULL;
|
ret = NULL;
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
virStoragePoolDefPtr
|
virStoragePoolDefPtr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user