From patchwork Tue Apr 19 07:32:16 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 717101 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 p3J7WnrU027855 for ; Tue, 19 Apr 2011 07:32:49 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752114Ab1DSHcp (ORCPT ); Tue, 19 Apr 2011 03:32:45 -0400 Received: from mail-ww0-f42.google.com ([74.125.82.42]:63773 "EHLO mail-ww0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751937Ab1DSHcp (ORCPT ); Tue, 19 Apr 2011 03:32:45 -0400 Received: by wwk4 with SMTP id 4so2650733wwk.1 for ; Tue, 19 Apr 2011 00:32:43 -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=vMvGQW543IIIm4Ji0Puec794Z5mhlDCw2c1BXi6Xbzk=; b=v2G/Emw4fmYYzTBo/lXEyOyNz2aXH1LH8BPOW+ZlOnkbih9977Uro3qFiPKCc9bHgt H7mOkI2AgWj2VV3epP4NZzEQjfAFEBfV6VivWaPKRrJlGuL2YHMSPLf+jeEh2NSATl2c Qxj396rTK+pINu37nQI7ey/oVc1QH5o7QVLIo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=f+aaaJneeYqO6vjMECbE7Kbuiji1JuoO9mD6hwKDv+VN8fXbJjFSmljohQ1sGT7fZm sIFp0atV4ti6pCiiIRL1GQr2rUZ5KDCnCaHUh+JUX/1TH4deb1dJ1ZixIJfoqRJoMjn/ hTLS8rJw8TmEnpfvf1ISkyJYK2aj1dL84nuMQ= Received: by 10.216.239.130 with SMTP id c2mr1824207wer.60.1303198363873; Tue, 19 Apr 2011 00:32:43 -0700 (PDT) Received: from localhost.localdomain (46-117-236-160.bb.netvision.net.il [46.117.236.160]) by mx.google.com with ESMTPS id r57sm2930581wes.1.2011.04.19.00.32.42 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 19 Apr 2011 00:32:43 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH] kvm tools: Fix possible leak in disk_image Date: Tue, 19 Apr 2011 10:32:16 +0300 Message-Id: <1303198336-4540-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]); Tue, 19 Apr 2011 07:32:49 +0000 (UTC) Close leaking fd if ioctl fails. Signed-off-by: Sasha Levin --- tools/kvm/disk-image.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/tools/kvm/disk-image.c b/tools/kvm/disk-image.c index 252ff1c..0fb2083 100644 --- a/tools/kvm/disk-image.c +++ b/tools/kvm/disk-image.c @@ -120,8 +120,10 @@ static struct disk_image *blkdev__probe(const char *filename, struct stat *st) if (fd < 0) return NULL; - if (ioctl(fd, BLKGETSIZE64, &size) < 0) + if (ioctl(fd, BLKGETSIZE64, &size) < 0) { + close(fd); return NULL; + } return disk_image__new_readonly(fd, size, &raw_image_ro_mmap_ops); }