From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:43692) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTceK-00041k-01 for qemu-devel@nongnu.org; Mon, 06 Jun 2011 12:27:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QTceI-0003wm-Ea for qemu-devel@nongnu.org; Mon, 06 Jun 2011 12:27:31 -0400 Received: from mail-pw0-f45.google.com ([209.85.160.45]:43273) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTceH-0003ug-VL for qemu-devel@nongnu.org; Mon, 06 Jun 2011 12:27:30 -0400 Received: by mail-pw0-f45.google.com with SMTP id 6so2348707pwi.4 for ; Mon, 06 Jun 2011 09:27:29 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 6 Jun 2011 18:26:57 +0200 Message-Id: <1307377620-7538-7-git-send-email-pbonzini@redhat.com> In-Reply-To: <1307377620-7538-1-git-send-email-pbonzini@redhat.com> References: <1307377620-7538-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [RFC PATCH 6/9] allow switching a qiov between internal and external storage List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- 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