From patchwork Thu Jun 29 06:03:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manos Pitsidianakis X-Patchwork-Id: 9816013 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E057660365 for ; Thu, 29 Jun 2017 06:04:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D515220007 for ; Thu, 29 Jun 2017 06:04:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C87FE205FC; Thu, 29 Jun 2017 06:04:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7189920007 for ; Thu, 29 Jun 2017 06:04:04 +0000 (UTC) Received: from localhost ([::1]:36965 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQSYd-0003QF-VB for patchwork-qemu-devel@patchwork.kernel.org; Thu, 29 Jun 2017 02:04:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58155) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQSY0-0003K0-Vq for qemu-devel@nongnu.org; Thu, 29 Jun 2017 02:03:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQSY0-0006Qi-6e for qemu-devel@nongnu.org; Thu, 29 Jun 2017 02:03:25 -0400 Received: from smtp1.ntua.gr ([2001:648:2000:de::183]:50865) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQSXv-0006OU-PK; Thu, 29 Jun 2017 02:03:20 -0400 Received: from mail.ntua.gr (ppp005055127131.access.hol.gr [5.55.127.131]) (authenticated bits=0) by smtp1.ntua.gr (8.15.2/8.15.2) with ESMTPSA id v5T6373Y026803 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Jun 2017 09:03:09 +0300 (EEST) (envelope-from el13635@mail.ntua.gr) X-Authentication-Warning: smtp1.ntua.gr: Host ppp005055127131.access.hol.gr [5.55.127.131] claimed to be mail.ntua.gr From: Manos Pitsidianakis To: qemu-devel Date: Thu, 29 Jun 2017 09:03:00 +0300 Message-Id: <20170629060300.29869-1-el13635@mail.ntua.gr> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:648:2000:de::183 Subject: [Qemu-devel] [PATCH] block: fix bs->file leak in bdrv_new_open_driver() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP bdrv_open_driver() is called in two places, bdrv_new_open_driver() and bdrv_open_common(). In the latter, failure cleanup in is in its caller, bdrv_open_inherit(), which unrefs the bs->file of the failed driver open if it exists. Let's check for this in bdrv_new_open_driver() as well. Signed-off-by: Manos Pitsidianakis --- block.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block.c b/block.c index 694396281b..aeacd520e0 100644 --- a/block.c +++ b/block.c @@ -1165,6 +1165,9 @@ BlockDriverState *bdrv_new_open_driver(BlockDriver *drv, const char *node_name, ret = bdrv_open_driver(bs, drv, node_name, bs->options, flags, errp); if (ret < 0) { + if (bs->file != NULL) { + bdrv_unref_child(bs, bs->file); + } QDECREF(bs->explicit_options); QDECREF(bs->options); bdrv_unref(bs);