From patchwork Fri Aug 3 19:57:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Baron X-Patchwork-Id: 175043 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 9A4492C0079 for ; Sat, 4 Aug 2012 05:57:44 +1000 (EST) Received: from localhost ([::1]:40612 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SxO0E-00046p-MY for incoming@patchwork.ozlabs.org; Fri, 03 Aug 2012 15:57:42 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52333) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SxNzo-00036j-8T for qemu-devel@nongnu.org; Fri, 03 Aug 2012 15:57:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SxNzn-0003iA-B7 for qemu-devel@nongnu.org; Fri, 03 Aug 2012 15:57:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:19391) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SxNzk-0003gx-4f; Fri, 03 Aug 2012 15:57:12 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q73JvB5b030777 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 Aug 2012 15:57:11 -0400 Received: from redhat.com (dhcp-185-114.bos.redhat.com [10.16.185.114]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q73JvA4o016512; Fri, 3 Aug 2012 15:57:11 -0400 Date: Fri, 3 Aug 2012 15:57:10 -0400 From: Jason Baron To: agraf@suse.de Message-Id: <1b114377e92202a2aba65ade4f80d63514366cf6.1344023079.git.jbaron@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, aliguori@us.ibm.com, qemu-devel@nongnu.org, armbru@redhat.com, qemu-stable@nongnu.org, alex.williamson@redhat.com, avi@redhat.com, pbonzini@redhat.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH 2/2 v2] ahci: Fix sglist memleak in ahci_dma_rw_buf() 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 I noticed that in hw/ide/ahci:ahci_dma_rw_buf() we do not free the sglist. Thus, I've added a call to qemu_sglist_destroy() to fix this memory leak. In addition, I've adeed a call in qemu_sglist_destroy() to 0 all of the sglist fields, in case there is some other codepath that tries to free the sglist. Signed-off-by: Jason Baron --- dma-helpers.c | 1 + hw/ide/ahci.c | 3 +++ 2 files changed, 4 insertions(+), 0 deletions(-) diff --git a/dma-helpers.c b/dma-helpers.c index 35cb500..13593d1 100644 --- a/dma-helpers.c +++ b/dma-helpers.c @@ -65,6 +65,7 @@ void qemu_sglist_add(QEMUSGList *qsg, dma_addr_t base, dma_addr_t len) void qemu_sglist_destroy(QEMUSGList *qsg) { g_free(qsg->sg); + memset(qsg, 0, sizeof(*qsg)); } typedef struct { diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index de580a6..5ea3cad 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1073,6 +1073,9 @@ static int ahci_dma_rw_buf(IDEDMA *dma, int is_write) dma_buf_write(p, l, &s->sg); } + /* free sglist that was created in ahci_populate_sglist() */ + qemu_sglist_destroy(&s->sg); + /* update number of transferred bytes */ ad->cur_cmd->status = cpu_to_le32(le32_to_cpu(ad->cur_cmd->status) + l); s->io_buffer_index += l;