aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Baron <jbaron@redhat.com>2012-08-03 15:57:10 -0400
committerKevin Wolf <kwolf@redhat.com>2012-08-10 10:25:12 +0200
commitea8d82a1ed72634f089ed1bccccd9c84cc1ab855 (patch)
tree4d1ed2da96ceb799f1a5796c3f64171aba8b258f
parent61f52e06f0a21bab782f98ef3ea789aa6d0aa046 (diff)
ahci: Fix sglist memleak in ahci_dma_rw_buf()
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 <jbaron@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
-rw-r--r--dma-helpers.c1
-rw-r--r--hw/ide/ahci.c3
2 files changed, 4 insertions, 0 deletions
diff --git a/dma-helpers.c b/dma-helpers.c
index 35cb500581..13593d1b42 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 de580a6eff..5ea3cadb01 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;