qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1.1 v2] qdev: Fix memory leak


From: Stefan Weil
Subject: Re: [Qemu-devel] [PATCH 1.1 v2] qdev: Fix memory leak
Date: Fri, 18 May 2012 23:20:42 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120430 Thunderbird/12.0.1

Am 18.05.2012 13:14, schrieb dunrong huang:
The str allocated in visit_type_str was not freed.

The visit_type_str function is an input visitor(<QMP/String/etc>-to-native)
here, it will allocate memory for caller, so the caller is responsible for
freeing the memory.

Signed-off-by: dunrong huang<address@hidden>
---
  hw/qdev-properties.c |    6 +++++-
  1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index c5545dc..b7b5597 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -753,10 +753,12 @@ static void set_mac(Object *obj, Visitor *v, void *opaque,
          }
          mac->a[i] = strtol(str+pos,&p, 16);
      }
+    g_free(str);
      return;

  inval:
      error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+    g_free(str);
  }

  PropertyInfo qdev_prop_macaddr = {
@@ -825,7 +827,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void 
*opaque,
      uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
      unsigned int slot, fn, n;
      Error *local_err = NULL;
-    char *str = (char *)"";
+    char *str;

      if (dev->state != DEV_STATE_CREATED) {
          error_set(errp, QERR_PERMISSION_DENIED);
@@ -848,10 +850,12 @@ static void set_pci_devfn(Object *obj, Visitor *v, void 
*opaque,
          goto invalid;
      }
      *ptr = slot<<  3 | fn;
+    g_free(str);
      return;

  invalid:
      error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+    g_free(str);
  }

  static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest, 
size_t len)


Reviewed-by: Stefan Weil <address@hidden>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]