898951
From 550637214e4df0cd44d64e83a0e57fc37f470bdb Mon Sep 17 00:00:00 2001
898951
Message-Id: <550637214e4df0cd44d64e83a0e57fc37f470bdb@dist-git>
898951
From: Peter Krempa <pkrempa@redhat.com>
898951
Date: Thu, 22 Jan 2015 15:53:51 +0100
898951
Subject: [PATCH] conf: Don't corrupt metadata on OOM
898951
898951
https://bugzilla.redhat.com/show_bug.cgi?id=1184929
898951
898951
Eric Blake suggested that we could do a little better in case copying of
898951
the metadata to be set fails. With this patch, the old metadata is
898951
discarded after the new string is copied successfuly.
898951
898951
(cherry picked from commit 7655ed0802eecc3d8486a0360d2326ecd052e477)
898951
898951
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
898951
---
898951
 src/conf/domain_conf.c | 13 +++++++++----
898951
 1 file changed, 9 insertions(+), 4 deletions(-)
898951
898951
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
898951
index 4dbe3fc..c4829ff 100644
898951
--- a/src/conf/domain_conf.c
898951
+++ b/src/conf/domain_conf.c
898951
@@ -19044,19 +19044,24 @@ virDomainDefSetMetadata(virDomainDefPtr def,
898951
     xmlDocPtr doc = NULL;
898951
     xmlNodePtr old;
898951
     xmlNodePtr new;
898951
+    char *tmp;
898951
     int ret = -1;
898951
 
898951
     switch ((virDomainMetadataType) type) {
898951
     case VIR_DOMAIN_METADATA_DESCRIPTION:
898951
+        if (VIR_STRDUP(tmp, metadata) < 0)
898951
+            goto cleanup;
898951
+
898951
         VIR_FREE(def->description);
898951
-        if (VIR_STRDUP(def->description, metadata) < 0)
898951
-            goto cleanup;
898951
+        def->description = tmp;
898951
         break;
898951
 
898951
     case VIR_DOMAIN_METADATA_TITLE:
898951
+        if (VIR_STRDUP(tmp, metadata) < 0)
898951
+            goto cleanup;
898951
+
898951
         VIR_FREE(def->title);
898951
-        if (VIR_STRDUP(def->title, metadata) < 0)
898951
-            goto cleanup;
898951
+        def->title = tmp;
898951
         break;
898951
 
898951
     case VIR_DOMAIN_METADATA_ELEMENT:
898951
-- 
898951
2.2.1
898951