Some code paths already assume that it is allocated since it was always
allocated by virDomainPerfDefParseXML. Make it member of virDomainDef
directly so that we don't have to allocate it all the time.
This fixes crash when attempting to connect to an existing process via
virDomainQemuAttach since we would not allocate it in that code path.
Resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=1350688
---
src/conf/domain_conf.c | 12 ++----------
src/conf/domain_conf.h | 2 +-
src/qemu/qemu_driver.c | 6 +++---
src/qemu/qemu_process.c | 8 ++++----
4 files changed, 10 insertions(+), 18 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ef266af..7d40f26 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2671,8 +2671,6 @@ void virDomainDefFree(virDomainDefPtr def)
VIR_FREE(def->keywrap);
- VIR_FREE(def->perf);
-
if (def->namespaceData && def->ns.free)
(def->ns.free)(def->namespaceData);
@@ -13136,19 +13134,14 @@ virDomainPerfDefParseXML(virDomainDefPtr def,
if ((n = virXPathNodeSet("./perf/event", ctxt, &nodes)) < 0)
return n;
- if (VIR_ALLOC(def->perf) < 0)
- goto cleanup;
-
for (i = 0; i < n; i++) {
- if (virDomainPerfEventDefParseXML(def->perf, nodes[i]) < 0)
+ if (virDomainPerfEventDefParseXML(&def->perf, nodes[i]) < 0)
goto cleanup;
}
ret = 0;
cleanup:
- if (ret < 0)
- VIR_FREE(def->perf);
VIR_FREE(nodes);
return ret;
}
@@ -23388,8 +23381,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
virBufferAddLit(buf, "</pm>\n");
}
- if (def->perf)
- virDomainPerfDefFormat(buf, def->perf);
+ virDomainPerfDefFormat(buf, &def->perf);
virBufferAddLit(buf, "<devices>\n");
virBufferAdjustIndent(buf, 2);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 7c5cbd9..e1990dc 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2140,7 +2140,7 @@ struct _virDomainDef {
virDomainPowerManagement pm;
- virDomainPerfDefPtr perf;
+ virDomainPerfDef perf;
virDomainOSDef os;
char *emulator;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 61d184b..0507be8 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9642,7 +9642,7 @@ qemuDomainSetPerfEvents(virDomainPtr dom,
if (enabled && virPerfEventEnable(priv->perf, type, vm->pid)
< 0)
goto endjob;
- def->perf->events[type] = enabled ?
+ def->perf.events[type] = enabled ?
VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO;
}
@@ -9656,7 +9656,7 @@ qemuDomainSetPerfEvents(virDomainPtr dom,
enabled = param->value.b;
type = virPerfEventTypeFromString(param->field);
- persistentDef->perf->events[type] = enabled ?
+ persistentDef->perf.events[type] = enabled ?
VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO;
}
@@ -9716,7 +9716,7 @@ qemuDomainGetPerfEvents(virDomainPtr dom,
bool perf_enabled;
if (flags & VIR_DOMAIN_AFFECT_CONFIG)
- perf_enabled = def->perf->events[i] == VIR_TRISTATE_BOOL_YES;
+ perf_enabled = def->perf.events[i] == VIR_TRISTATE_BOOL_YES;
else
perf_enabled = virPerfEventIsEnabled(priv->perf, i);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 63da600..a175a4d 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3139,12 +3139,12 @@ qemuDomainPerfRestart(virDomainObjPtr vm)
return -1;
for (i = 0; i < VIR_PERF_EVENT_LAST; i++) {
- if (def->perf->events[i] &&
- def->perf->events[i] == VIR_TRISTATE_BOOL_YES) {
+ if (def->perf.events[i] &&
+ def->perf.events[i] == VIR_TRISTATE_BOOL_YES) {
/* Failure to re-enable the perf event should not be fatal */
if (virPerfEventEnable(priv->perf, i, vm->pid) < 0)
- def->perf->events[i] = VIR_TRISTATE_BOOL_NO;
+ def->perf.events[i] = VIR_TRISTATE_BOOL_NO;
}
}
@@ -5217,7 +5217,7 @@ qemuProcessLaunch(virConnectPtr conn,
goto cleanup;
for (i = 0; i < VIR_PERF_EVENT_LAST; i++) {
- if (vm->def->perf->events[i] == VIR_TRISTATE_BOOL_YES &&
+ if (vm->def->perf.events[i] == VIR_TRISTATE_BOOL_YES &&
virPerfEventEnable(priv->perf, i, vm->pid) < 0)
goto cleanup;
}
--
2.9.0