From nobody Sun Feb 8 21:48:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1628177686; cv=none; d=zohomail.com; s=zohoarc; b=HfJTqJlb27xIyv4N1boiIF5aAtM0hfmfXU0DkG/Stz8ygh2eV43Q6VoWyV73Q1dWwESezrX9CwGzGOAK8iB0YnfESKgK1nV9jQYJlyBNWjiFDpHB02AL0T2DfANuhqpVrBMx5GV6f6QVb3YQ2rKvjScZcqFrghmMa0spZZk8W7Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628177686; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ArUCoCm0aJTcAqds/XlFliw7I1hHM4//5sV4EycVjWI=; b=MRrGnY5Jp5q1Vr5lRwe1DzQPHR7LtbjjDtBwACNHHZP+gDCszB19HIljg15spXttxQ2srM4EyXJFwqUpa/gYOqW1NxoCDWEqK2URbFDIzYvBHWVaX+bSRRX2ElPBhUijG06wE5ujWY8yo0HfHsDXkEoDPHOo9SmH0T45XYKpLM4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1628177686916310.6742445614219; Thu, 5 Aug 2021 08:34:46 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-421-PtG8DPXFP4eVOZNk17PRWw-1; Thu, 05 Aug 2021 11:34:44 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7675E871827; Thu, 5 Aug 2021 15:34:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 55D8760CC9; Thu, 5 Aug 2021 15:34:38 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1DC33181A2A5; Thu, 5 Aug 2021 15:34:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 175FYZ1s027603 for ; Thu, 5 Aug 2021 11:34:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id B1BFD18401; Thu, 5 Aug 2021 15:34:35 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C7735D6B1 for ; Thu, 5 Aug 2021 15:34:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628177685; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ArUCoCm0aJTcAqds/XlFliw7I1hHM4//5sV4EycVjWI=; b=Fwqehl5sfLBf9ULiqtWHx/1H8YuIBGFn6lmLckXZzarNRW4yUlQzqjakZqGAKAiFiYE/3T FDvrDdpbefM0hnjLv/OCn6kHdF8+1/hTzZVSlqnEEBqQ2U44InWllaj7PT52mvEf8G8ufv dH8hWQNcZsry+PZKDTLOEaaTFyzrzNQ= X-MC-Unique: PtG8DPXFP4eVOZNk17PRWw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 01/13] testQemuAgentSSHKeys: Refactor cleanup Date: Thu, 5 Aug 2021 17:34:17 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628177688251100001 Content-Type: text/plain; charset="utf-8" Use automatic memory freeing for the 'qemuMonitorTest' object and the list of keys so that the cleanup section can be removed. Signed-off-by: Peter Krempa --- tests/qemuagenttest.c | 54 ++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c index e0d2575c45..a447c93494 100644 --- a/tests/qemuagenttest.c +++ b/tests/qemuagenttest.c @@ -39,16 +39,15 @@ static int testQemuAgentSSHKeys(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; - qemuMonitorTest *test =3D qemuMonitorTestNewAgent(xmlopt); - char **keys =3D NULL; + g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); + g_auto(GStrv) keys =3D NULL; int nkeys =3D 0; - int ret =3D -1; if (!test) return -1; if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; if (qemuMonitorTestAddItem(test, "guest-ssh-get-authorized-keys", "{\"return\": {" @@ -57,59 +56,52 @@ testQemuAgentSSHKeys(const void *data) " \"algo2 key2 comments2\"" " ]" "}}") < 0) - goto cleanup; + return -1; if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; if (qemuMonitorTestAddItem(test, "guest-ssh-add-authorized-keys", "{ \"return\" : {} }") < 0) - goto cleanup; + return -1; if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; if (qemuMonitorTestAddItem(test, "guest-ssh-remove-authorized-keys", "{ \"return\" : {} }") < 0) - goto cleanup; + return -1; if ((nkeys =3D qemuAgentSSHGetAuthorizedKeys(qemuMonitorTestGetAgent(t= est), "user", &keys)) < 0) - goto cleanup; + return -1; if (nkeys !=3D 2) { virReportError(VIR_ERR_INTERNAL_ERROR, "expected 2 keys, got %d", nkeys); - ret =3D -1; - goto cleanup; + return -1; } if (STRNEQ(keys[1], "algo2 key2 comments2")) { virReportError(VIR_ERR_INTERNAL_ERROR, "Unexpected key returned: %= s", keys[1]); - ret =3D -1; - goto cleanup; + return -1; } - if ((ret =3D qemuAgentSSHAddAuthorizedKeys(qemuMonitorTestGetAgent(tes= t), - "user", - (const char **) keys, - nkeys, - true)) < 0) - goto cleanup; - - if ((ret =3D qemuAgentSSHRemoveAuthorizedKeys(qemuMonitorTestGetAgent(= test), - "user", - (const char **) keys, - nkeys)) < 0) - goto cleanup; + if (qemuAgentSSHAddAuthorizedKeys(qemuMonitorTestGetAgent(test), + "user", + (const char **) keys, + nkeys, + true) < 0) + return -1; - ret =3D 0; + if (qemuAgentSSHRemoveAuthorizedKeys(qemuMonitorTestGetAgent(test), + "user", + (const char **) keys, + nkeys) < 0) + return -1; - cleanup: - virStringListFreeCount(keys, nkeys); - qemuMonitorTestFree(test); - return ret; + return 0; } --=20 2.31.1