Some code paths pass in already pointers to strings which should be
added directly as the value of the typed parameter. To allow more
universal use of virTypedParameterAssignValue add a flag which allows to
copy the value in place.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/util/virtypedparam.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index 9f86166707..720b88dd10 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -209,7 +209,8 @@ virTypedParameterToString(virTypedParameterPtr param)
static int
virTypedParameterAssignValueAP(virTypedParameterPtr param,
int type,
- va_list ap)
+ va_list ap,
+ bool copystr)
{
param->type = type;
switch (type) {
@@ -232,7 +233,13 @@ virTypedParameterAssignValueAP(virTypedParameterPtr param,
param->value.b = !!va_arg(ap, int);
break;
case VIR_TYPED_PARAM_STRING:
- param->value.s = va_arg(ap, char *);
+ if (copystr) {
+ if (VIR_STRDUP(param->value.s, va_arg(ap, char *)) < 0)
+ return -1;
+ } else {
+ param->value.s = va_arg(ap, char *);
+ }
+
if (!param->value.s && VIR_STRDUP(param->value.s, "")
< 0)
return -1;
break;
@@ -265,7 +272,7 @@ virTypedParameterAssign(virTypedParameterPtr param, const char *name,
}
va_start(ap, type);
- ret = virTypedParameterAssignValueAP(param, type, ap);
+ ret = virTypedParameterAssignValueAP(param, type, ap, false);
va_end(ap);
return ret;
--
2.21.0