qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] xics: fix several error leaks
@ 2017-09-11 22:04 Greg Kurz
  2017-09-12  4:01 ` David Gibson
  0 siblings, 1 reply; 2+ messages in thread
From: Greg Kurz @ 2017-09-11 22:04 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-ppc, David Gibson, Cedric Le Goater

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>
---
 hw/intc/xics.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/intc/xics.c b/hw/intc/xics.c
index a84ba51ad8ff..80c33be02e5e 100644
--- a/hw/intc/xics.c
+++ b/hw/intc/xics.c
@@ -306,8 +306,8 @@ static void icp_realize(DeviceState *dev, Error **errp)
 
     obj = object_property_get_link(OBJECT(dev), ICP_PROP_XICS, &err);
     if (!obj) {
-        error_setg(errp, "%s: required link '" ICP_PROP_XICS "' not found: %s",
-                   __func__, error_get_pretty(err));
+        error_propagate(errp, err);
+        error_prepend(errp, "required link '" ICP_PROP_XICS "' not found: ");
         return;
     }
 
@@ -315,8 +315,8 @@ static void icp_realize(DeviceState *dev, Error **errp)
 
     obj = object_property_get_link(OBJECT(dev), ICP_PROP_CPU, &err);
     if (!obj) {
-        error_setg(errp, "%s: required link '" ICP_PROP_CPU "' not found: %s",
-                   __func__, error_get_pretty(err));
+        error_propagate(errp, err);
+        error_prepend(errp, "required link '" ICP_PROP_CPU "' not found: ");
         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);
     if (!obj) {
-        error_setg(errp, "%s: required link '" ICS_PROP_XICS "' not found: %s",
-                   __func__, error_get_pretty(err));
+        error_propagate(errp, err);
+        error_prepend(errp, "required link '" ICS_PROP_XICS "' not found: ");
         return;
     }
     ics->xics = XICS_FABRIC(obj);

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] xics: fix several error leaks
  2017-09-11 22:04 [Qemu-devel] [PATCH] xics: fix several error leaks Greg Kurz
@ 2017-09-12  4:01 ` David Gibson
  0 siblings, 0 replies; 2+ messages in thread
From: David Gibson @ 2017-09-12  4:01 UTC (permalink / raw)
  To: Greg Kurz; +Cc: qemu-devel, qemu-ppc, Cedric Le Goater

[-- Attachment #1: Type: text/plain, Size: 2492 bytes --]

On Tue, Sep 12, 2017 at 12:04:40AM +0200, Greg Kurz wrote:
> 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>

Applied to ppc-for-2.11.

> ---
>  hw/intc/xics.c |   12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/intc/xics.c b/hw/intc/xics.c
> index a84ba51ad8ff..80c33be02e5e 100644
> --- a/hw/intc/xics.c
> +++ b/hw/intc/xics.c
> @@ -306,8 +306,8 @@ static void icp_realize(DeviceState *dev, Error **errp)
>  
>      obj = object_property_get_link(OBJECT(dev), ICP_PROP_XICS, &err);
>      if (!obj) {
> -        error_setg(errp, "%s: required link '" ICP_PROP_XICS "' not found: %s",
> -                   __func__, error_get_pretty(err));
> +        error_propagate(errp, err);
> +        error_prepend(errp, "required link '" ICP_PROP_XICS "' not found: ");
>          return;
>      }
>  
> @@ -315,8 +315,8 @@ static void icp_realize(DeviceState *dev, Error **errp)
>  
>      obj = object_property_get_link(OBJECT(dev), ICP_PROP_CPU, &err);
>      if (!obj) {
> -        error_setg(errp, "%s: required link '" ICP_PROP_CPU "' not found: %s",
> -                   __func__, error_get_pretty(err));
> +        error_propagate(errp, err);
> +        error_prepend(errp, "required link '" ICP_PROP_CPU "' not found: ");
>          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);
>      if (!obj) {
> -        error_setg(errp, "%s: required link '" ICS_PROP_XICS "' not found: %s",
> -                   __func__, error_get_pretty(err));
> +        error_propagate(errp, err);
> +        error_prepend(errp, "required link '" ICS_PROP_XICS "' not found: ");
>          return;
>      }
>      ics->xics = XICS_FABRIC(obj);
> 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-12  4:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-11 22:04 [Qemu-devel] [PATCH] xics: fix several error leaks Greg Kurz
2017-09-12  4:01 ` David Gibson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).