qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH 6/9] allow switching a qiov between internal and


From: Paolo Bonzini
Subject: [Qemu-devel] [RFC PATCH 6/9] allow switching a qiov between internal and external storage
Date: Mon, 6 Jun 2011 18:26:57 +0200

qemu_iovec_reset and qemu_iovec_destroy will switch from external to
internal storage (it was previously forbidden to call it with external
storage).  So, qemu_iovec_destroy followed by qemu_iovec_init_external
will not leak memory when called on a qiov that already had internal
storage allocated.

Signed-off-by: Paolo Bonzini <address@hidden>
---
 cutils.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/cutils.c b/cutils.c
index f9a7e36..0fef64a 100644
--- a/cutils.c
+++ b/cutils.c
@@ -215,14 +215,22 @@ void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector 
*src, size_t size)
 
 void qemu_iovec_destroy(QEMUIOVector *qiov)
 {
-    assert(qiov->nalloc != -1);
+    if (qiov->nalloc != -1) {
+        qemu_free(qiov->iov);
+        qiov->nalloc = 0;
+        qiov->iov = NULL;
+    }
 
-    qemu_free(qiov->iov);
+    qiov->niov = 0;
+    qiov->size = 0;
 }
 
 void qemu_iovec_reset(QEMUIOVector *qiov)
 {
-    assert(qiov->nalloc != -1);
+    if (qiov->nalloc == -1) {
+        qiov->nalloc = 0;
+        qiov->iov = NULL;
+    }
 
     qiov->niov = 0;
     qiov->size = 0;
-- 
1.7.4.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]