From patchwork Wed Nov 18 09:42:59 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 38738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 701291007D1 for ; Wed, 18 Nov 2009 20:46:13 +1100 (EST) Received: from localhost ([127.0.0.1]:39801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAh73-0003ZD-PU for incoming@patchwork.ozlabs.org; Wed, 18 Nov 2009 04:46:09 -0500 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 Received: from localhost.localdomain (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAI9i2sK028617; Wed, 18 Nov 2009 04:44:03 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Wed, 18 Nov 2009 10:42:59 +0100 Message-Id: <1258537379-25369-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Kevin Wolf Subject: [Qemu-devel] [PATCH] qemu-io: Fix memory leak X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Kevin Wolf Reviewed-by: Christoph Hellwig --- 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; }