xics: fix several error leaks

If object_property_get_link() fails then it allocates an error, which
must be freed before returning. The error_get_pretty() function is
merely an accessor to the error message and doesn't free anything.

The error.h header indicates how to do it right:

 * Pass an existing error to the caller with the message modified:
 *     error_propagate(errp, err);
 *     error_prepend(errp, "Could not frobnicate '%s': ", name);

Signed-off-by: Greg Kurz <groug@kaod.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Greg Kurz 2017-09-12 00:04:40 +02:00 committed by David Gibson
parent e100161b69
commit a1a6bbde4f

View File

@ -306,8 +306,8 @@ static void icp_realize(DeviceState *dev, Error **errp)
obj = object_property_get_link(OBJECT(dev), ICP_PROP_XICS, &err); obj = object_property_get_link(OBJECT(dev), ICP_PROP_XICS, &err);
if (!obj) { if (!obj) {
error_setg(errp, "%s: required link '" ICP_PROP_XICS "' not found: %s", error_propagate(errp, err);
__func__, error_get_pretty(err)); error_prepend(errp, "required link '" ICP_PROP_XICS "' not found: ");
return; return;
} }
@ -315,8 +315,8 @@ static void icp_realize(DeviceState *dev, Error **errp)
obj = object_property_get_link(OBJECT(dev), ICP_PROP_CPU, &err); obj = object_property_get_link(OBJECT(dev), ICP_PROP_CPU, &err);
if (!obj) { if (!obj) {
error_setg(errp, "%s: required link '" ICP_PROP_CPU "' not found: %s", error_propagate(errp, err);
__func__, error_get_pretty(err)); error_prepend(errp, "required link '" ICP_PROP_CPU "' not found: ");
return; return;
} }
@ -641,8 +641,8 @@ static void ics_base_realize(DeviceState *dev, Error **errp)
obj = object_property_get_link(OBJECT(dev), ICS_PROP_XICS, &err); obj = object_property_get_link(OBJECT(dev), ICS_PROP_XICS, &err);
if (!obj) { if (!obj) {
error_setg(errp, "%s: required link '" ICS_PROP_XICS "' not found: %s", error_propagate(errp, err);
__func__, error_get_pretty(err)); error_prepend(errp, "required link '" ICS_PROP_XICS "' not found: ");
return; return;
} }
ics->xics = XICS_FABRIC(obj); ics->xics = XICS_FABRIC(obj);