From nobody Mon Feb 9 03:12:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500586924419294.1967305381065; Thu, 20 Jul 2017 14:42:04 -0700 (PDT) Received: from localhost ([::1]:40090 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYJCt-0007Af-5x for importer@patchew.org; Thu, 20 Jul 2017 17:42:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYJB9-00062X-1e for qemu-devel@nongnu.org; Thu, 20 Jul 2017 17:40:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYJB8-0000aa-02 for qemu-devel@nongnu.org; Thu, 20 Jul 2017 17:40:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45594) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYJB7-0000aK-Mo for qemu-devel@nongnu.org; Thu, 20 Jul 2017 17:40:13 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 92FB361BB4; Thu, 20 Jul 2017 21:40:12 +0000 (UTC) Received: from red.redhat.com (ovpn-120-37.rdu2.redhat.com [10.10.120.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE2007C1EE; Thu, 20 Jul 2017 21:40:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 92FB361BB4 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 92FB361BB4 From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 20 Jul 2017 16:40:05 -0500 Message-Id: <20170720214008.28494-2-eblake@redhat.com> In-Reply-To: <20170720214008.28494-1-eblake@redhat.com> References: <20170720214008.28494-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 20 Jul 2017 21:40:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/4] tests: Enhance qobject output to cover partial visit 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: armbru@redhat.com, Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a test that proves (at least when run under valgrind) that we are correctly handling allocated memory even when a visit is aborted in the middle for whatever other reason. See commit f24582d "qapi: fix double free in qmp_output_visitor_cleanup()" for a fix that was lacking testsuite exposure prior to this patch. Signed-off-by: Eric Blake --- v2: tweak partial alternate visit --- tests/test-qobject-output-visitor.c | 42 +++++++++++++++++++++++++++++++++= +++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 749c54065f..ce2fb8f368 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -1,7 +1,7 @@ /* * QObject Output Visitor unit-tests. * - * Copyright (C) 2011-2016 Red Hat Inc. + * Copyright (C) 2011-2017 Red Hat Inc. * * Authors: * Luiz Capitulino @@ -251,6 +251,44 @@ static void test_visitor_out_struct_errors(TestOutputV= isitorData *data, } +static void test_visitor_out_partial_visit(TestOutputVisitorData *data, + const void *unused) +{ + /* Various checks that a mid-visit abort doesn't leak or double-free. = */ + const char *str =3D "hi"; + Error *err =3D NULL; + UserDefAlternate uda =3D { + .type =3D QTYPE_QDICT, + .u.udfu =3D { .integer =3D 1, + .string =3D (char *) "bye", + .enum1 =3D -1 } /* intentionally bad */ + }; + UserDefAlternate *obj =3D &uda; + + /* Abort within a nested object with no data members */ + visit_start_struct(data->ov, NULL, NULL, 0, &error_abort); + visit_start_struct(data->ov, "nested", NULL, 0, &error_abort); + visitor_reset(data); + + /* Abort in the middle of a list of strings */ + visit_start_list(data->ov, "list", NULL, 0, &error_abort); + visit_type_str(data->ov, NULL, (char **)&str, &error_abort); + visit_type_str(data->ov, NULL, (char **)&str, &error_abort); + visitor_reset(data); + + /* + * Abort in the middle of an alternate, due to bad "enum1" + * discriminator value. Since alternates don't support virtual + * visits, we perform a real one, relying on our knowledge that + * visit_type_UserDefAlternate() calls visit_start_alternate() + * under the hood. + */ + visit_type_UserDefAlternate(data->ov, NULL, &obj, &err); + error_free_or_abort(&err); + visitor_reset(data); +} + + static void test_visitor_out_list(TestOutputVisitorData *data, const void *unused) { @@ -815,6 +853,8 @@ int main(int argc, char **argv) &out_visitor_data, test_visitor_out_struct_nes= ted); output_visitor_test_add("/visitor/output/struct-errors", &out_visitor_data, test_visitor_out_struct_err= ors); + output_visitor_test_add("/visitor/output/partial-visit", + &out_visitor_data, test_visitor_out_partial_vi= sit); output_visitor_test_add("/visitor/output/list", &out_visitor_data, test_visitor_out_list); output_visitor_test_add("/visitor/output/any", --=20 2.13.3