From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NAh59-0002yl-Te for qemu-devel@nongnu.org; Wed, 18 Nov 2009 04:44:11 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NAh55-0002wm-8p for qemu-devel@nongnu.org; Wed, 18 Nov 2009 04:44:11 -0500 Received: from [199.232.76.173] (port=45072 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAh55-0002wg-1L for qemu-devel@nongnu.org; Wed, 18 Nov 2009 04:44:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37137) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NAh54-00041A-0Q for qemu-devel@nongnu.org; Wed, 18 Nov 2009 04:44:06 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAI9i4Nj024239 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 18 Nov 2009 04:44:04 -0500 From: Kevin Wolf Date: Wed, 18 Nov 2009 10:42:59 +0100 Message-Id: <1258537379-25369-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH] qemu-io: Fix memory leak List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-io.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index cac72e9..c84b361 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -129,7 +129,8 @@ create_iovec(QEMUIOVector *qiov, char **argv, int nr_iov, int pattern) { size_t *sizes = calloc(nr_iov, sizeof(size_t)); size_t count = 0; - void *buf, *p; + void *buf = NULL; + void *p; int i; for (i = 0; i < nr_iov; i++) { @@ -139,19 +140,19 @@ create_iovec(QEMUIOVector *qiov, char **argv, int nr_iov, int pattern) len = cvtnum(arg); if (len < 0) { printf("non-numeric length argument -- %s\n", arg); - return NULL; + goto fail; } /* should be SIZE_T_MAX, but that doesn't exist */ if (len > UINT_MAX) { printf("too large length argument -- %s\n", arg); - return NULL; + goto fail; } if (len & 0x1ff) { printf("length argument %lld is not sector aligned\n", len); - return NULL; + goto fail; } sizes[i] = len; @@ -167,6 +168,7 @@ create_iovec(QEMUIOVector *qiov, char **argv, int nr_iov, int pattern) p += sizes[i]; } +fail: free(sizes); return buf; } -- 1.6.2.5