From 281e74478113b009756867ecce6ce2d28be96b38 Mon Sep 17 00:00:00 2001
From: Eduardo Habkost <ehabkost@redhat.com>
Date: Fri, 30 Apr 2010 19:49:52 -0300
Subject: [PATCH] block: Free iovec arrays allocated by multiwrite_merge()

RH-Author: Eduardo Habkost <ehabkost@redhat.com>
Message-id: <20100430194952.GW3494@blackpad.lan.raisama.net>
Patchwork-id: 8934
O-Subject: [RHEL-6 qemu-kvm PATCH] block: Free iovec arrays allocated by
	multiwrite_merge()
Bugzilla: 586572
RH-Acked-by: Christoph Hellwig <chellwig@redhat.com>
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>

Bugzilla: 586572
  (virtio-blk multiwrite merge memory leak)

Cherry-pick from upstream commit 1e1ea48d42e011b9bdd0d689d184e7cac4617b66:

    From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
    Date: Wed, 21 Apr 2010 20:35:45 +0100
    Subject: [PATCH] block: Free iovec arrays allocated by multiwrite_merge()

    A new iovec array is allocated when creating a merged write request.
    This patch ensures that the iovec array is deleted in addition to its
    qiov owner.

    Reported-by: Leszek Urbanski <tygrys@moo.pl>
    Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
    Signed-off-by: Kevin Wolf <kwolf@redhat.com>

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 block.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 block.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index e4d2744..7e3f898 100644
--- a/block.c
+++ b/block.c
@@ -1719,6 +1719,9 @@ static void multiwrite_user_cb(MultiwriteCB *mcb)
 
     for (i = 0; i < mcb->num_callbacks; i++) {
         mcb->callbacks[i].cb(mcb->callbacks[i].opaque, mcb->error);
+        if (mcb->callbacks[i].free_qiov) {
+            qemu_iovec_destroy(mcb->callbacks[i].free_qiov);
+        }
         qemu_free(mcb->callbacks[i].free_qiov);
         qemu_free(mcb->callbacks[i].free_buf);
     }
-- 
1.7.0.3

