conf: Don't corrupt metadata on OOM

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.
This commit is contained in:
Peter Krempa 2013-09-17 11:16:30 +02:00
parent 044e3e7524
commit 7655ed0802
1 changed files with 9 additions and 4 deletions

View 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: