From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:50461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzsNA-0006Lg-MS for qemu-devel@nongnu.org; Fri, 10 Aug 2012 12:47:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzsN8-00083k-HU for qemu-devel@nongnu.org; Fri, 10 Aug 2012 12:47:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20243) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzsN8-00083c-9W for qemu-devel@nongnu.org; Fri, 10 Aug 2012 12:47:38 -0400 From: Kevin Wolf Date: Fri, 10 Aug 2012 18:47:21 +0200 Message-Id: <1344617249-6620-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1344617249-6620-1-git-send-email-kwolf@redhat.com> References: <1344617249-6620-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 03/11] ahci: Fix sglist memleak in ahci_dma_rw_buf() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Jason Baron 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 Signed-off-by: Kevin Wolf --- 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; -- 1.7.6.5