From patchwork Fri May 18 11:14:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dunrong huang X-Patchwork-Id: 160095 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4F70AB6FC2 for ; Fri, 18 May 2012 21:14:17 +1000 (EST) Received: from localhost ([::1]:34155 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SVL8R-0003N9-49 for incoming@patchwork.ozlabs.org; Fri, 18 May 2012 07:14:15 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:user-agent:mime-version :content-type; bh=joGHzuqW2JeJbpjXiHOfjaJdy6/UIadTuM56ugdW3A0=; b=aO5EesoWcE/1WzkOurQPzjWEWtqh0kmkZtF1e8yYcWjsCV0x4D/JS4hAu/sZNq6W2o 8j12W5KcQQFCy2km2ZA6Y/8lHsjVp+vkiRD7z5OMVLB4WHS8WogpxREscGLIsdxRV9U2 T6vqFOm//HbLqaAGSHom8bC+MxJDtmJzJo5C7chhCn/TdOvyXrYVk828O1GK6gEJ9eWP nxfh6w0xNHZZRbLnmnEcYrKxNRwGCNo83VYfc4a91uYfI/NP2A6L1HBrC+TGUgtDUKhp AXhkC7Hyl30XoXS36oeDVM/iR9iKR3B/PcnsrflQJNISVCItDfcusatc7Rm+oxbntlgJ qpxw== Received: by 10.68.228.97 with SMTP id sh1mr37477639pbc.113.1337339641830; Fri, 18 May 2012 04:14:01 -0700 (PDT) Received: from riegamaths@gmail.com ([119.255.44.227]) by mx.google.com with ESMTPS id nd6sm12470558pbc.63.2012.05.18.04.13.52 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 18 May 2012 04:14:00 -0700 (PDT) Received: by riegamaths@gmail.com (sSMTP sendmail emulation); Fri, 18 May 2012 19:14:13 +0800 From: dunrong huang To: qemu-devel@nongnu.org Date: Fri, 18 May 2012 19:14:13 +0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.45 Cc: Stefan Hajnoczi , Anthony Liguori , Michael Roth Subject: [Qemu-devel] [PATCH 1.1 v2] qdev: Fix memory leak X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Reviewed-by: Stefan Weil --- 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)