From patchwork Tue Apr 5 15:41:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 8753181 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 07E57C0553 for ; Tue, 5 Apr 2016 15:42:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 682C420394 for ; Tue, 5 Apr 2016 15:42:01 +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 7D9152038E for ; Tue, 5 Apr 2016 15:42:00 +0000 (UTC) Received: from localhost ([::1]:37906 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anT79-0004Ce-S2 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Apr 2016 11:41:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58145) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anT6s-00044V-DS for qemu-devel@nongnu.org; Tue, 05 Apr 2016 11:41:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1anT6r-0001mS-CV for qemu-devel@nongnu.org; Tue, 05 Apr 2016 11:41:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50355) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anT6r-0001mL-6a for qemu-devel@nongnu.org; Tue, 05 Apr 2016 11:41:41 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CCE8FC00F1E0; Tue, 5 Apr 2016 15:41:40 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-78.ams2.redhat.com [10.36.116.78]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u35FfXBv020325; Tue, 5 Apr 2016 11:41:39 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Tue, 5 Apr 2016 17:41:28 +0200 Message-Id: <1459870888-9246-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1459870888-9246-1-git-send-email-kwolf@redhat.com> References: <1459870888-9246-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, peter.maydell@linaro.org Subject: [Qemu-devel] [PULL 4/4] 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable 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 From: Eric Blake 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 Message-id: 1459526222-30052-1-git-send-email-eblake@redhat.com Signed-off-by: Max Reitz --- 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) {