Eric Blake suggested that we could do a little better in case copying of
the metadata to be set fails. With this patch, the old metadata is
discarded after the new string is copied successfuly.
---
src/conf/domain_conf.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7e78068..60f25ab 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18599,19 +18599,24 @@ virDomainDefSetMetadata(virDomainDefPtr def,
xmlDocPtr doc = NULL;
xmlNodePtr old;
xmlNodePtr new;
+ char *tmp;
int ret = -1;
switch ((virDomainMetadataType) type) {
case VIR_DOMAIN_METADATA_DESCRIPTION:
- VIR_FREE(def->description);
- if (VIR_STRDUP(def->description, metadata) < 0)
+ if (VIR_STRDUP(tmp, metadata) < 0)
goto cleanup;
+
+ VIR_FREE(def->description);
+ def->description = tmp;
break;
case VIR_DOMAIN_METADATA_TITLE:
- VIR_FREE(def->title);
- if (VIR_STRDUP(def->title, metadata) < 0)
+ if (VIR_STRDUP(tmp, metadata) < 0)
goto cleanup;
+
+ VIR_FREE(def->title);
+ def->title = tmp;
break;
case VIR_DOMAIN_METADATA_ELEMENT:
--
1.8.3.2