From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:49613) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SVL8J-0003Mp-NU for qemu-devel@nongnu.org; Fri, 18 May 2012 07:14:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SVL8G-0005WN-9U for qemu-devel@nongnu.org; Fri, 18 May 2012 07:14:07 -0400 Received: from mail-pz0-f45.google.com ([209.85.210.45]:38979) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SVL8F-0005W4-T9 for qemu-devel@nongnu.org; Fri, 18 May 2012 07:14:04 -0400 Received: by dadv2 with SMTP id v2so4629583dad.4 for ; Fri, 18 May 2012 04:14:02 -0700 (PDT) From: dunrong huang Date: Fri, 18 May 2012 19:14:13 +0800 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: [Qemu-devel] [PATCH 1.1 v2] qdev: Fix memory leak List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Anthony Liguori , Michael Roth The str allocated in visit_type_str was not freed. The visit_type_str function is an input visitor(-to-native) here, it will allocate memory for caller, so the caller is responsible for freeing the memory. Signed-off-by: dunrong huang --- 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) -- 1.7.8.4