]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Don't corrupt metadata on OOM
authorPeter Krempa <pkrempa@redhat.com>
Tue, 17 Sep 2013 09:16:30 +0000 (11:16 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 17 Sep 2013 10:13:49 +0000 (12:13 +0200)
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

index 7e780684525aaffeb1accee0496999bd10d3ced7..60f25abd67a5138ac6943ff821b5c20b3e590695 100644 (file)
@@ -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: