From nobody Thu Nov 6 12:14:09 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540843507109325.1253679927514; Mon, 29 Oct 2018 13:05:07 -0700 (PDT) Received: from localhost ([::1]:48708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHDmX-0004py-3j for importer@patchew.org; Mon, 29 Oct 2018 16:05:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHDkc-0003Jb-K4 for qemu-devel@nongnu.org; Mon, 29 Oct 2018 16:03:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHDkb-00061e-Mc for qemu-devel@nongnu.org; Mon, 29 Oct 2018 16:03:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43534) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHDkb-00061N-D2 for qemu-devel@nongnu.org; Mon, 29 Oct 2018 16:03:01 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BB0B3C0669A5; Mon, 29 Oct 2018 20:03:00 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-158.ams2.redhat.com [10.36.116.158]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EF395DF50; Mon, 29 Oct 2018 20:02:51 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 7F5DD16444B; Mon, 29 Oct 2018 21:02:50 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 29 Oct 2018 21:02:50 +0100 Message-Id: <20181029200250.24029-4-kraxel@redhat.com> In-Reply-To: <20181029200250.24029-1-kraxel@redhat.com> References: <20181029200250.24029-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 29 Oct 2018 20:03:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/3] hw: ccid-card-emulated: cleanup resource when realize in error path 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: Li Qiang , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Li Qiang Signed-off-by: Li Qiang Message-id: 1539946236-18028-3-git-send-email-liq3ea@gmail.com Signed-off-by: Gerd Hoffmann --- hw/usb/ccid-card-emulated.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c index b356edb0f3..25976ed84f 100644 --- a/hw/usb/ccid-card-emulated.c +++ b/hw/usb/ccid-card-emulated.c @@ -499,7 +499,7 @@ static void emulated_realize(CCIDCardState *base, Error= **errp) card->reader =3D NULL; card->quit_apdu_thread =3D 0; if (init_event_notifier(card, errp) < 0) { - return; + goto out1; } =20 card->backend =3D 0; @@ -513,7 +513,7 @@ static void emulated_realize(CCIDCardState *base, Error= **errp) for (ptable =3D backend_enum_table; ptable->name !=3D NULL; ++ptab= le) { error_append_hint(errp, "%s\n", ptable->name); } - return; + goto out2; } =20 /* TODO: a passthru backened that works on local machine. third card t= ype?*/ @@ -523,31 +523,39 @@ static void emulated_realize(CCIDCardState *base, Err= or **errp) } else { error_setg(errp, "%s: you must provide all three certs for" " certificates backend", TYPE_EMULATED_CCID); - return; + goto out2; } } else { if (card->backend !=3D BACKEND_NSS_EMULATED) { error_setg(errp, "%s: bad backend specified. The options are:%= s" " (default), %s.", TYPE_EMULATED_CCID, BACKEND_NSS_EMULATED_NAME, BACKEND_CERTIFICATES_NAM= E); - return; + goto out2; } if (card->cert1 !=3D NULL || card->cert2 !=3D NULL || card->cert3 = !=3D NULL) { error_setg(errp, "%s: unexpected cert parameters to nss emulat= ed " "backend", TYPE_EMULATED_CCID); - return; + goto out2; } /* default to mirroring the local hardware readers */ ret =3D wrap_vcard_emul_init(NULL); } if (ret !=3D VCARD_EMUL_OK) { error_setg(errp, "%s: failed to initialize vcard", TYPE_EMULATED_C= CID); - return; + goto out2; } qemu_thread_create(&card->event_thread_id, "ccid/event", event_thread, card, QEMU_THREAD_JOINABLE); qemu_thread_create(&card->apdu_thread_id, "ccid/apdu", handle_apdu_thr= ead, card, QEMU_THREAD_JOINABLE); + +out2: + clean_event_notifier(card); +out1: + qemu_cond_destroy(&card->handle_apdu_cond); + qemu_mutex_destroy(&card->handle_apdu_mutex); + qemu_mutex_destroy(&card->vreader_mutex); + qemu_mutex_destroy(&card->event_list_mutex); } =20 static void emulated_unrealize(CCIDCardState *base, Error **errp) --=20 2.9.3