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: 782047 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wypy16CD3z9s7g for ; Thu, 29 Jun 2017 16:03:52 +1000 (AEST) Received: from localhost ([::1]:36965 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQSYO-0003QF-V2 for incoming@patchwork.ozlabs.org; Thu, 29 Jun 2017 02:03:48 -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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);