From patchwork Thu Dec 29 08:11:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 9491081 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BFB8362AB7 for ; Thu, 29 Dec 2016 08:11:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D1DC1FF8F for ; Thu, 29 Dec 2016 08:11:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E3062094D; Thu, 29 Dec 2016 08:11:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E27FD1FF8F for ; Thu, 29 Dec 2016 08:11:56 +0000 (UTC) Received: from localhost ([::1]:34308 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMVoX-0000Yi-Vn for patchwork-qemu-devel@patchwork.kernel.org; Thu, 29 Dec 2016 03:11:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34606) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cMVoJ-0000Yb-Sv for qemu-devel@nongnu.org; Thu, 29 Dec 2016 03:11:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cMVoG-0001k8-Qo for qemu-devel@nongnu.org; Thu, 29 Dec 2016 03:11:39 -0500 Received: from mail-it0-x241.google.com ([2607:f8b0:4001:c0b::241]:35765) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cMVoG-0001j3-NI for qemu-devel@nongnu.org; Thu, 29 Dec 2016 03:11:36 -0500 Received: by mail-it0-x241.google.com with SMTP id b123so38394022itb.2 for ; Thu, 29 Dec 2016 00:11:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=3p9lds3GJOVUyXqPtHoU6AsT8UFRvD/UUUPEcULbcLM=; b=fQhVyV7nmZxzCA0m/UzrixdRgeIyCNnjC5ubZCM8VoE12xeb9sd0qW7Vqa8sR1jIY+ sryHMvp/wZK4q2VvQde2VkOOJy/uThcNCOPEaHakGrcZqulTaSWLGuYrcIudIv56nLgh Qb6ppMwtVAQx57/tFRccEvAGtGljU2U/6grOH2fw3M4tphVX1dVRgEQax59kAr0lvvV/ 7+1lxNCLJ7rY5v3zSqZhRapxUTTHvFuJp2RKMDTr6Xn/M7iqNiUhHQXJeDAls5Ur1cnB hja2cowNpEgJtm/yPgRboPMO4wwKfdzU6TRPbNli2FOIZ+hl5HddPIY2bAZKFMCWNDal fm0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=3p9lds3GJOVUyXqPtHoU6AsT8UFRvD/UUUPEcULbcLM=; b=ZWxDz06sO56Qx1WEfADkM/bjOE6iZpLFvlu/uBgt07pyd/NOYFae5uTJKGmh5LpJis +ybOmpgGZVeSj5l1GZAcKP+Twl/8QmA3tGozqLMEi+z7Kkx4My4JaxE8yR/AtEawr74y FWmzpt6kmzg64uF4zHw/8xFn/nlXlUNOFYMWqVomI6VCqx2P6OO7mcX6BWu5aJe5ue+x UV9/zsYBt9JYElnLjceZ/sOappbkeilm9dmx2uGtR69E35zO2JbaJCU4mr1Gw/b/aeSH 8yN/9yCA5Wqsy7RMTj+B7CRwQkHfI5DQ2TglsXe/MFJFUSXsh84A3dXAYGs5C+dIMQDt hSYQ== X-Gm-Message-State: AIkVDXIVheByKjpXHjm0azLKdlp3Rn/GylmkjY3/RJOmibN1BHAtakneY5UiF7Y/9DoBqA== X-Received: by 10.36.37.199 with SMTP id g190mr32565210itg.12.1482999094487; Thu, 29 Dec 2016 00:11:34 -0800 (PST) Received: from localhost.localdomain ([104.192.110.250]) by smtp.gmail.com with ESMTPSA id g186sm19540083itb.4.2016.12.29.00.11.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Dec 2016 00:11:33 -0800 (PST) From: Li Qiang To: kraxel@redhat.com, marcandre.lureau@redhat.com, qemu-devel@nongnu.org Date: Thu, 29 Dec 2016 03:11:26 -0500 Message-Id: <1482999086-59795-1-git-send-email-liq3ea@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4001:c0b::241 Subject: [Qemu-devel] [PATCH] virtio-gpu-3d: fix memory leak in resource attach backing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liqiang6-s@360.cn Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP If the virgl_renderer_resource_attach_iov function fails the 'res_iovs' will be leaked. Add check of the return value to free the 'res_iovs' when failing. Signed-off-by: Li Qiang Reviewed-by: Marc-André Lureau --- hw/display/virtio-gpu-3d.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hw/display/virtio-gpu-3d.c b/hw/display/virtio-gpu-3d.c index 23f39de..07b3691 100644 --- a/hw/display/virtio-gpu-3d.c +++ b/hw/display/virtio-gpu-3d.c @@ -291,8 +291,11 @@ static void virgl_resource_attach_backing(VirtIOGPU *g, return; } - virgl_renderer_resource_attach_iov(att_rb.resource_id, - res_iovs, att_rb.nr_entries); + ret = virgl_renderer_resource_attach_iov(att_rb.resource_id, + res_iovs, att_rb.nr_entries); + + if (ret != 0) + virtio_gpu_cleanup_mapping_iov(res_iovs, att_rb.nr_entries); } static void virgl_resource_detach_backing(VirtIOGPU *g,