Use a temporary variable to allow copying from the
currently set source.
Always return 0 since none of the callers distinguishes
between 0 and 1 propagated from VIR_STRDUP.
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
src/conf/domain_conf.c | 26 ++++++++------------------
1 file changed, 8 insertions(+), 18 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 88e93f6fb8..cd9b6ca993 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2139,15 +2139,10 @@ virDomainDiskGetSource(virDomainDiskDef const *def)
int
virDomainDiskSetSource(virDomainDiskDefPtr def, const char *src)
{
- int ret;
- char *tmp = def->src->path;
-
- ret = VIR_STRDUP(def->src->path, src);
- if (ret < 0)
- def->src->path = tmp;
- else
- VIR_FREE(tmp);
- return ret;
+ char *tmp = g_strdup(src);
+ g_free(def->src->path);
+ def->src->path = tmp;
+ return 0;
}
@@ -2174,15 +2169,10 @@ virDomainDiskGetDriver(const virDomainDiskDef *def)
int
virDomainDiskSetDriver(virDomainDiskDefPtr def, const char *name)
{
- int ret;
- char *tmp = def->driverName;
-
- ret = VIR_STRDUP(def->driverName, name);
- if (ret < 0)
- def->driverName = tmp;
- else
- VIR_FREE(tmp);
- return ret;
+ char *tmp = g_strdup(name);
+ g_free(def->driverName);
+ def->driverName = tmp;
+ return 0;
}
--
2.21.0