From patchwork Sat Apr 16 11:45:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 712371 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3GBkKE3019741 for ; Sat, 16 Apr 2011 11:46:22 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759338Ab1DPLqF (ORCPT ); Sat, 16 Apr 2011 07:46:05 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:64545 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759327Ab1DPLqE (ORCPT ); Sat, 16 Apr 2011 07:46:04 -0400 Received: by wya21 with SMTP id 21so2841995wya.19 for ; Sat, 16 Apr 2011 04:46:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer; bh=Lg/U2rjfuQbzBoDkOYLf6YSsFErYC6SvoCE9uklhn9s=; b=ca+NGen+Ga+BGG301Ygdx7gkhYxax1JJu7FouvojOwaU1BN0mDM+g5T1kFdI6tm5Lk 5uISsovHVUhsfT9gBGO1bcw/w0xdAvGX6iHvhjVBADxIMBa1OlbcLL0f6Ajm4B4ZRLY8 o4b/WSoWxUoMKm/Xa5dtHhsLQAnw/KwboTlp0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=wZMaBXldaYDqqgUlrin3Mua9xXFP6ouzPehcEuCJiG1g7gnds9RBsN7LTIYjSncHHQ ux2KBqiXeGCBA0F6OAxe4n9frPTm1o0bA60DqbJBEtNwI+WVOHfNm1tDVSETyCAxw55f yxLtRfgMH9oTwWA+WswpFtmiVe00SaX/kFA7Q= Received: by 10.217.7.66 with SMTP id z44mr2877483wes.100.1302954362523; Sat, 16 Apr 2011 04:46:02 -0700 (PDT) Received: from localhost.localdomain (93-172-38-69.bb.netvision.net.il [93.172.38.69]) by mx.google.com with ESMTPS id n52sm1705158wer.24.2011.04.16.04.46.00 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 16 Apr 2011 04:46:01 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 1/2 V2] kvm tools: Fix leak in QCOW Date: Sat, 16 Apr 2011 14:45:43 +0300 Message-Id: <1302954344-11700-1-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.5.rc1 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sat, 16 Apr 2011 11:46:39 +0000 (UTC) Fixed leak when reading a zero sector, also simplified flow a bit. Signed-off-by: Sasha Levin --- tools/kvm/qcow.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/kvm/qcow.c b/tools/kvm/qcow.c index 9b9af86..ceac721 100644 --- a/tools/kvm/qcow.c +++ b/tools/kvm/qcow.c @@ -44,7 +44,7 @@ static int qcow1_read_sector(struct disk_image *self, uint64_t sector, void *dst uint64_t l2_table_size; uint64_t clust_offset; uint64_t clust_start; - uint64_t *l2_table; + uint64_t *l2_table = NULL; uint64_t l1_idx; uint64_t l2_idx; uint64_t offset; @@ -69,24 +69,24 @@ static int qcow1_read_sector(struct disk_image *self, uint64_t sector, void *dst goto out_error; if (pread_in_full(q->fd, l2_table, sizeof(uint64_t) * l2_table_size, l2_table_offset) < 0) - goto out_error_free_l2; + goto out_error; l2_idx = get_l2_index(q, offset); if (l2_idx >= l2_table_size) - goto out_error_free_l2; + goto out_error; clust_start = be64_to_cpu(l2_table[l2_idx]); + free(l2_table); + if (!clust_start) goto zero_sector; clust_offset = get_cluster_offset(q, offset); if (pread_in_full(q->fd, dst, dst_len, clust_start + clust_offset) < 0) - goto out_error_free_l2; - - free(l2_table); + goto out_error; return 0; @@ -95,9 +95,9 @@ zero_sector: return 0; -out_error_free_l2: - free(l2_table); out_error: + free(l2_table); + return -1; }