From patchwork Fri Apr 1 15:57:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8726361 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2CE729F3D1 for ; Fri, 1 Apr 2016 15:59:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7F86820155 for ; Fri, 1 Apr 2016 15:59:20 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 7D52C201FA for ; Fri, 1 Apr 2016 15:59:19 +0000 (UTC) Received: from localhost ([::1]:45169 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1am1Ti-0005bW-ST for patchwork-qemu-devel@patchwork.kernel.org; Fri, 01 Apr 2016 11:59:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36370) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1am1Ta-0005a0-U9 for qemu-devel@nongnu.org; Fri, 01 Apr 2016 11:59:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1am1TX-0006H6-MN for qemu-devel@nongnu.org; Fri, 01 Apr 2016 11:59:10 -0400 Received: from resqmta-po-09v.sys.comcast.net ([96.114.154.168]:42284) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1am1TX-0006H0-G6 for qemu-devel@nongnu.org; Fri, 01 Apr 2016 11:59:07 -0400 Received: from resomta-po-18v.sys.comcast.net ([96.114.154.242]) by comcast with SMTP id m1QwaTTNud826m1RaajbIK; Fri, 01 Apr 2016 15:57:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1459526226; bh=w6PXyWr2Bv3wkgnMh6dhENFigchsWDEvhty6+jY4nvY=; h=Received:Received:From:To:Subject:Date:Message-Id; b=FvCnD4v5t5ZEcLExqtLsuJtvydaPotMx5QdAYhk90foBRVIQRPHTXYz+JFyDMGbqL RN8Qg4pNslGwfdiRDcqwakWd6YgMxlzKYrgzOf+4I2yq+we/fMUGOAOOIQJIxTIjMf Am7RuV5H7LR8Vd2nzpwPnswtrSGW7szrVkuO34LSntQCFlGO/FymiHUvBxXBVBGgXS vnKDagi6Snu7qcG/+Vns8vbKWMqiQfHkODjL9Na0DD6uz/UAx+pDCVcTyMAwlCTO5A 9dGMsEfCAUYzuIFIm2fiylhBfYkQ13eDAb0+O3T+Jyux+Y8vCcggvVbxJxZUdhmX82 DGW585R0ahtWA== Received: from red.redhat.com ([24.10.254.122]) by resomta-po-18v.sys.comcast.net with comcast id d3x31s00A2fD5rL013x5LM; Fri, 01 Apr 2016 15:57:06 +0000 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 1 Apr 2016 09:57:02 -0600 Message-Id: <1459526222-30052-1-git-send-email-eblake@redhat.com> X-Mailer: git-send-email 2.5.5 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 96.114.154.168 Cc: Kevin Wolf , "open list:Block layer core" Subject: [Qemu-devel] [PATCH for-2.6] crypto: Avoid memory leak on failure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit 7836857 introduced a memory leak due to invalid use of Error vs. visit_type_end(). If visiting the intermediate members fails, we clear the error and unconditionally use visit_end_struct() on the same error object; but if that cleanup succeeds, we then skip the qapi_free call. Until a later patch adds visit_check_struct(), the only safe approach is to use two separate error objects. Signed-off-by: Eric Blake --- block/crypto.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/block/crypto.c b/block/crypto.c index be34985..1903e84 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -196,6 +196,7 @@ block_crypto_open_opts_init(QCryptoBlockFormat format, OptsVisitor *ov; QCryptoBlockOpenOptions *ret = NULL; Error *local_err = NULL; + Error *end_err = NULL; ret = g_new0(QCryptoBlockOpenOptions, 1); ret->format = format; @@ -218,10 +219,9 @@ block_crypto_open_opts_init(QCryptoBlockFormat format, error_setg(&local_err, "Unsupported block format %d", format); break; } - error_propagate(errp, local_err); - local_err = NULL; - visit_end_struct(opts_get_visitor(ov), &local_err); + visit_end_struct(opts_get_visitor(ov), &end_err); + error_propagate(&local_err, end_err); out: if (local_err) { @@ -242,6 +242,7 @@ block_crypto_create_opts_init(QCryptoBlockFormat format, OptsVisitor *ov; QCryptoBlockCreateOptions *ret = NULL; Error *local_err = NULL; + Error *end_err = NULL; ret = g_new0(QCryptoBlockCreateOptions, 1); ret->format = format; @@ -264,10 +265,9 @@ block_crypto_create_opts_init(QCryptoBlockFormat format, error_setg(&local_err, "Unsupported block format %d", format); break; } - error_propagate(errp, local_err); - local_err = NULL; - visit_end_struct(opts_get_visitor(ov), &local_err); + visit_end_struct(opts_get_visitor(ov), &end_err); + error_propagate(&local_err, end_err); out: if (local_err) {