From patchwork Thu Jul 26 19:40:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Baron X-Patchwork-Id: 173479 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 1B1572C00AF for ; Fri, 27 Jul 2012 05:40:27 +1000 (EST) Received: from localhost ([::1]:53995 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SuTv7-0006n3-2C for incoming@patchwork.ozlabs.org; Thu, 26 Jul 2012 15:40:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SuTut-0006YN-Va for qemu-devel@nongnu.org; Thu, 26 Jul 2012 15:40:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SuTus-00087K-QD for qemu-devel@nongnu.org; Thu, 26 Jul 2012 15:40:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42604) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SuTus-00087G-IM for qemu-devel@nongnu.org; Thu, 26 Jul 2012 15:40:10 -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 q6QJe95Z020957 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 26 Jul 2012 15:40:10 -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 q6QJe9l7000987; Thu, 26 Jul 2012 15:40:09 -0400 Date: Thu, 26 Jul 2012 15:40:09 -0400 To: agraf@suse.de Message-Id: In-Reply-To: References: From: Jason Baron 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, armbru@redhat.com, qemu-devel@nongnu.org, alex.williamson@redhat.com, avi@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 2/2] 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() does not appear to free the sglist. Thus, I've added a call to qemu_sglist_destroy() to fix this memory leak. I'm wondering though if 'ahci_populate_sglist()' can return 0, and not populate the sglist, thus causing us to call free on NULL pointer. However, I see that ahci_start_transfer() always calls the free if the return is 0. Signed-off-by: Jason Baron --- hw/ide/ahci.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 9c95714..b48401d 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;