conf: def: Avoid unnecessary allocation of 'perf' events definition

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
This commit is contained in:
Peter Krempa 2016-06-28 14:37:29 +02:00
parent 60a545fa68
commit d7c40d50d7
4 changed files with 10 additions and 18 deletions

View File

@ -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);

View File

@ -2140,7 +2140,7 @@ struct _virDomainDef {
virDomainPowerManagement pm;
virDomainPerfDefPtr perf;
virDomainPerfDef perf;
virDomainOSDef os;
char *emulator;

View File

@ -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);

View File

@ -3142,12 +3142,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;
}
}
@ -5220,7 +5220,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;
}