On Wed, Jun 08, 2016 at 10:22:17 +0200, Jiri Denemark wrote: > A CPU data XML file already contains the architecture, let the parser > use it to detect which CPU driver should be used to parse the rest of > the file. > > Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx> > --- > src/cpu/cpu.c | 54 ++++++++++++++++++++++++++++++++++++++++++++---------- > src/cpu/cpu.h | 7 +++---- > src/cpu/cpu_x86.c | 15 ++------------- > 3 files changed, 49 insertions(+), 27 deletions(-) > > diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c > index dbd0987..8c3d39d 100644 > --- a/src/cpu/cpu.c > +++ b/src/cpu/cpu.c [...] > @@ -675,24 +689,44 @@ cpuDataFormat(const virCPUData *data) > * Returns internal CPU data structure parsed from the XML or NULL on error. > */ > virCPUDataPtr > -cpuDataParse(virArch arch, > - const char *xmlStr) > +cpuDataParse(const char *xmlStr) > { > struct cpuArchDriver *driver; > + xmlDocPtr xml = NULL; > + xmlXPathContextPtr ctxt = NULL; > + virCPUDataPtr data = NULL; > + char *arch; 'arch' can be freed uninitialized. > > - VIR_DEBUG("arch=%s, xmlStr=%s", virArchToString(arch), xmlStr); > + VIR_DEBUG("xmlStr=%s", xmlStr); > > - if (!(driver = cpuGetSubDriver(arch))) > - return NULL; > + if (!(xml = virXMLParseStringCtxt(xmlStr, _("CPU data"), &ctxt))) { > + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", > + _("cannot parse CPU data")); > + goto cleanup; > + } > + > + if (!(arch = virXPathString("string(/cpudata/@arch)", ctxt))) { > + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", > + _("missing CPU data architecture")); > + goto cleanup; > + } > + > + if (!(driver = cpuGetSubDriverByName(arch))) > + goto cleanup; This doesn't report errors. > > if (!driver->dataParse) { > virReportError(VIR_ERR_NO_SUPPORT, > - _("cannot parse %s CPU data"), > - virArchToString(arch)); > - return NULL; > + _("cannot parse %s CPU data"), arch); > + goto cleanup; > } > > - return driver->dataParse(xmlStr); > + data = driver->dataParse(ctxt); > + > + cleanup: > + xmlXPathFreeContext(ctxt); > + xmlFreeDoc(xml); > + VIR_FREE(arch); ^^^^ > + return data; > } > > bool ACK with the two problems fixed. -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list