diff mbox

[for-1.7] qom: fix object_property_set_link() memory leak

Message ID 1384787411-7187-1-git-send-email-stefanha@redhat.com
State New
Headers show

Commit Message

Stefan Hajnoczi Nov. 18, 2013, 3:10 p.m. UTC
object_get_canonical_path() returns a string that the caller is
responsible for freeing.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 qom/object.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Andreas Färber Nov. 18, 2013, 3:11 p.m. UTC | #1
Am 18.11.2013 16:10, schrieb Stefan Hajnoczi:
> object_get_canonical_path() returns a string that the caller is
> responsible for freeing.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>

What's the difference to Vlad's v2?

Andreas

> ---
>  qom/object.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/qom/object.c b/qom/object.c
> index b617f26..fc19cf6 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -838,8 +838,9 @@ char *object_property_get_str(Object *obj, const char *name,
>  void object_property_set_link(Object *obj, Object *value,
>                                const char *name, Error **errp)
>  {
> -    object_property_set_str(obj, object_get_canonical_path(value),
> -                            name, errp);
> +    gchar *path = object_get_canonical_path(value);
> +    object_property_set_str(obj, path, name, errp);
> +    g_free(path);
>  }
>  
>  Object *object_property_get_link(Object *obj, const char *name,
>
Stefan Hajnoczi Nov. 19, 2013, 8:49 a.m. UTC | #2
On Mon, Nov 18, 2013 at 04:11:43PM +0100, Andreas Färber wrote:
> Am 18.11.2013 16:10, schrieb Stefan Hajnoczi:
> > object_get_canonical_path() returns a string that the caller is
> > responsible for freeing.
> > 
> > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> 
> What's the difference to Vlad's v2?

Please ignore this patch, Vlad has already submitted an equivalent patch
which I hadn't seen.

NACK
diff mbox

Patch

diff --git a/qom/object.c b/qom/object.c
index b617f26..fc19cf6 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -838,8 +838,9 @@  char *object_property_get_str(Object *obj, const char *name,
 void object_property_set_link(Object *obj, Object *value,
                               const char *name, Error **errp)
 {
-    object_property_set_str(obj, object_get_canonical_path(value),
-                            name, errp);
+    gchar *path = object_get_canonical_path(value);
+    object_property_set_str(obj, path, name, errp);
+    g_free(path);
 }
 
 Object *object_property_get_link(Object *obj, const char *name,