From patchwork Thu Jul 26 19:40:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2/2] ahci: Fix sglist memleak in ahci_dma_rw_buf() Date: Thu, 26 Jul 2012 09:40:09 -0000 From: Jason Baron X-Patchwork-Id: 173479 Message-Id: To: agraf@suse.de 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 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;