From nobody Tue Apr 30 02:27:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1652865743; cv=none; d=zohomail.com; s=zohoarc; b=mWit9L8XsEevfCwfVrg503/5jCqnbVc2SgY2yuy7kXHrVfzwoe29K67BUYpDOharUC6PR0WJWirlnbIeG+BXIkBuXD0rfTJh60KIjlQLmtV/YaQ+p6TC/8vXBVL54eBZLokAsn5lld2QGj4miw1rGaZZb7kUeRPn+qCjzkupGA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652865743; 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=KpsIeU9kHYUt6/l3BCOhr0jGIhVXum1YEAeSMEzc2o4=; b=FKaBo9owocX/xHRTElpwGix/iAfks4d59+ZrMLlUtH3nJH4+T8cBSjQ5kjJl4owFKRUUvkhfaKC7H/neO4ugpByk+KKm7NU8O+Q7jIv/ByytbNwpuiYeYOkvBDNy6m5iNQruJb3cJt78wb1EzkreHZ9TJpzheTadA4xiHpWXBWE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1652865743798722.7308081777393; Wed, 18 May 2022 02:22:23 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-574-R-5hbL-HO9akCJeFe2o3Ew-1; Wed, 18 May 2022 05:22:21 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 242B1100DDF4; Wed, 18 May 2022 09:22:19 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DD021410DD5; Wed, 18 May 2022 09:22:18 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4738E194975B; Wed, 18 May 2022 09:22:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 183741947B92 for ; Wed, 18 May 2022 09:22:16 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E0C5E400DE5E; Wed, 18 May 2022 09:22:15 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6758F40CF8EE for ; Wed, 18 May 2022 09:22:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652865742; 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=KpsIeU9kHYUt6/l3BCOhr0jGIhVXum1YEAeSMEzc2o4=; b=Hft1O2h1099SJq6Q+x0csxBJMa34MFa6YkaP08DROYWgoTRcCWSzNg1WdT9Ne4o1ktTBz1 +yxLRzeP3t9sNj1Rk+djcuqetC2F10+N59o8rWI2mI6JgdEdvQpFNqwWeEZssjv5ZRJYy5 LWd5Sg9m4iU51q7dEvfRbfig03dvBTU= X-MC-Unique: R-5hbL-HO9akCJeFe2o3Ew-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/4] util: typedparam: Introduce virTypedParamListFromParams Date: Wed, 18 May 2022 11:22:10 +0200 Message-Id: <5035ba46d49422cd739191923135f0dcf4e9d736.1652865683.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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: 1652865744882100001 Content-Type: text/plain; charset="utf-8" The helper constructs a virTypedParamList from loose params. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/libvirt_private.syms | 1 + src/util/virtypedparam.c | 13 +++++++++++++ src/util/virtypedparam.h | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d95c181793..3711e33cf5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3493,6 +3493,7 @@ virTypedParamListAddString; virTypedParamListAddUInt; virTypedParamListAddULLong; virTypedParamListFree; +virTypedParamListFromParams; virTypedParamListStealParams; virTypedParamsCheck; virTypedParamsCopy; diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index aa6a871049..2d7e4ab354 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -738,6 +738,19 @@ virTypedParamListStealParams(virTypedParamList *list, return ret; } +virTypedParamList * +virTypedParamListFromParams(virTypedParameterPtr *params, + size_t nparams) +{ + virTypedParamList *l =3D g_new0(virTypedParamList, 1); + + l->par =3D g_steal_pointer(params); + l->npar =3D nparams; + l->par_alloc =3D nparams; + + return l; +} + static int G_GNUC_PRINTF(2, 0) virTypedParamSetNameVPrintf(virTypedParameterPtr par, diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h index f4b3921c38..c4bc58ee8f 100644 --- a/src/util/virtypedparam.h +++ b/src/util/virtypedparam.h @@ -138,6 +138,10 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virTypedParamList, virTy= pedParamListFree); size_t virTypedParamListStealParams(virTypedParamList *list, virTypedParameterPtr *params); +virTypedParamList * +virTypedParamListFromParams(virTypedParameterPtr *params, + size_t nparams); + int virTypedParamListAddInt(virTypedParamList *list, int value, const char *namefmt, --=20 2.35.3 From nobody Tue Apr 30 02:27:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1652865783; cv=none; d=zohomail.com; s=zohoarc; b=Ni3MfJGcoh2o2WaEH0njSYFQjlSZ/36RBdUYOBNDw6Y1HRnzCTb+M6fOPNOrz5TK9XGvWDW2V8PRx0vEQuYH/13VsQ0I4F5qJlhLbVdkhK01domsLitv/rD+AsDFg+2NTYhbtJ+i/OH9Od6cbfg/FP04kqbuk5GQYsb5iKgsV4A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652865783; 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=qfX3kmJ6IhpP7Z08bbAQKU/5OMAqzdWOpPamfhMD+sA=; b=UOJpI60WYtZFUcU6SueAxW0FP5puAOvLXhhD1qJOT/EA2735XMARpfbc1aaGxZkC6tkkbfSvybIxVbclrKjg1Ueh+wDsILf5BSd2xrZ1z38PxQqVIfxOBa5OdMVrgRJb3HQwbXU4XSfiY30NrmQae05xxhS8rGK48zMLnlDFx1o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 16528657838471010.345420860127; Wed, 18 May 2022 02:23:03 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-58-DxXh8lGwNvu03KpQ0gS-IQ-1; Wed, 18 May 2022 05:22:21 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 849E91C08968; Wed, 18 May 2022 09:22:19 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id A362A1400E75; Wed, 18 May 2022 09:22:18 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5697E1947B92; Wed, 18 May 2022 09:22:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CA8A21947B84 for ; Wed, 18 May 2022 09:22:16 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id BB4B740CF8F0; Wed, 18 May 2022 09:22:16 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FCE640CF8EE for ; Wed, 18 May 2022 09:22:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652865782; 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=qfX3kmJ6IhpP7Z08bbAQKU/5OMAqzdWOpPamfhMD+sA=; b=bD86yRoqGENqAtZ7QnJ0LzNiXCkj1xJi9v2bjTZj/iwHhwjW9OPMC+Tkwe14rulPVjmYwe pF8HHVQ1mnkfCEkDE5gJMlJvDtrVYvP3EbfuNFjCeWySoDMfpJFc6HqXebGO3N9g70rxl5 azZcwxpO/4BAEQhs1EBfdCeroyvX5y8= X-MC-Unique: DxXh8lGwNvu03KpQ0gS-IQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/4] virGetConnectGeneric: Fix memleak of 'identparams' when connecting between split daemons Date: Wed, 18 May 2022 11:22:11 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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: 1652865784955100002 Content-Type: text/plain; charset="utf-8" The 'identparams' typed parameter list obtained from virIdentityGetParameters is leaked when called from 'virGetConnectGeneric'. Use 'virTypedParamListFromParams' to absorb it into a virTypedParamList which can be autofreed. Note that the memleak is observable only when running in split-daemon mode. Closes: https://gitlab.com/libvirt/libvirt/-/issues/314 Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/driver.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/driver.c b/src/driver.c index 41b4f0055b..d4136c438f 100644 --- a/src/driver.c +++ b/src/driver.c @@ -36,6 +36,7 @@ #include "viridentity.h" #include "datatypes.h" #include "configmake.h" +#include "virtypedparam.h" VIR_LOG_INIT("driver"); @@ -159,6 +160,7 @@ virGetConnectGeneric(virThreadLocal *threadPtr, const c= har *name) if (conn->driver->connectSetIdentity !=3D NULL) { g_autoptr(virIdentity) ident =3D NULL; + g_autoptr(virTypedParamList) paramlist =3D NULL; virTypedParameterPtr identparams =3D NULL; int nidentparams =3D 0; @@ -169,7 +171,9 @@ virGetConnectGeneric(virThreadLocal *threadPtr, const c= har *name) if (virIdentityGetParameters(ident, &identparams, &nidentparam= s) < 0) goto error; - if (virConnectSetIdentity(conn, identparams, nidentparams, 0) = < 0) + paramlist =3D virTypedParamListFromParams(&identparams, nident= params); + + if (virConnectSetIdentity(conn, paramlist->par, paramlist->npa= r, 0) < 0) goto error; } } --=20 2.35.3 From nobody Tue Apr 30 02:27:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1652865784; cv=none; d=zohomail.com; s=zohoarc; b=GVBuzCF70T/BP2NBBqkEj+F927wGYKsJ9XaV8FLM1ceBcSPpjTjdguz4VwG8UMTLPZqsUT3au8F3hf7WS+jYRN8PbB6HBgfOGF8mnVhQ1dRNePpbsMl2jQDxIHVQx85KzHeCj1sxcPReZxdNpRR89mbW/uCCqVJh2bdZoO04boA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652865784; 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=/4gKiEHap4vqc5nBUBMokbOJ39mLcdcxCZrk7gt03bI=; b=llANMVW3REF5rLTNO0BumRLTISQd0pXwQj//Yn7e+ZnZwKrN8mPnfKZWWlkak+YLlUaoeodU6m1l7WrVt+Q3DmYXNX6PXmRWw1kS8iWdptZOPsztLTL1BxhI9HHgu8TADaCsSzEuaVKY3bW4lco/Ardk1deQyUgTQw9uobTpsvc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1652865784559270.16711806048954; Wed, 18 May 2022 02:23:04 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-290-9uwATyUQMEaJNGrm0vYbZQ-1; Wed, 18 May 2022 05:22:22 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C31703C0CD5A; Wed, 18 May 2022 09:22:19 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B10D41410F36; Wed, 18 May 2022 09:22:19 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B0A561947B8F; Wed, 18 May 2022 09:22:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C2A42194F4BF for ; Wed, 18 May 2022 09:22:17 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 93F3A40CF8F0; Wed, 18 May 2022 09:22:17 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E86540CF8EE for ; Wed, 18 May 2022 09:22:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652865783; 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=/4gKiEHap4vqc5nBUBMokbOJ39mLcdcxCZrk7gt03bI=; b=I3nZS3C4v9IdZbv/nP2jyrLW8XO/BRnhcXYc7+mZYEMOp+4imx07lNUDApzogRfJXsGkbs jmch8Fu0bJQbHhrwi6C7uIMB9QrxJMGvFoZUZT+jdtfqSpTP5f4xMpk9XQygwbekB3ZBwg 9Uaok+k681enlX2DPLsMsinkzh9Sisc= X-MC-Unique: 9uwATyUQMEaJNGrm0vYbZQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/4] virIdentityGetParameters: Return 'virTypedParamList' Date: Wed, 18 May 2022 11:22:12 +0200 Message-Id: <041145bd6e0efb93f040729df197ca257cb34eaa.1652865683.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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: 1652865784965100003 Content-Type: text/plain; charset="utf-8" Refactor the code to use virTypedParamList which simplifies cleanup. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/driver.c | 10 +++------- src/remote/remote_daemon_dispatch.c | 8 +++----- src/util/viridentity.c | 15 +++++---------- src/util/viridentity.h | 5 ++--- 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/driver.c b/src/driver.c index d4136c438f..cea74bdf95 100644 --- a/src/driver.c +++ b/src/driver.c @@ -160,20 +160,16 @@ virGetConnectGeneric(virThreadLocal *threadPtr, const= char *name) if (conn->driver->connectSetIdentity !=3D NULL) { g_autoptr(virIdentity) ident =3D NULL; - g_autoptr(virTypedParamList) paramlist =3D NULL; - virTypedParameterPtr identparams =3D NULL; - int nidentparams =3D 0; + g_autoptr(virTypedParamList) identparams =3D NULL; VIR_DEBUG("Attempting to delegate current identity"); if (!(ident =3D virIdentityGetCurrent())) goto error; - if (virIdentityGetParameters(ident, &identparams, &nidentparam= s) < 0) + if (!(identparams =3D virIdentityGetParameters(ident))) goto error; - paramlist =3D virTypedParamListFromParams(&identparams, nident= params); - - if (virConnectSetIdentity(conn, paramlist->par, paramlist->npa= r, 0) < 0) + if (virConnectSetIdentity(conn, identparams->par, identparams-= >npar, 0) < 0) goto error; } } diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 2463386e39..39953f46cf 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -1793,8 +1793,7 @@ remoteOpenConn(const char *uri, bool preserveIdentity, virConnectPtr *conn) { - virTypedParameterPtr params =3D NULL; - int nparams =3D 0; + g_autoptr(virTypedParamList) identparams =3D NULL; int ret =3D -1; VIR_DEBUG("Getting secondary uri=3D%s readonly=3D%d preserveIdent=3D%d= conn=3D%p", @@ -1814,7 +1813,7 @@ remoteOpenConn(const char *uri, if (!(ident =3D virIdentityGetCurrent())) return -1; - if (virIdentityGetParameters(ident, ¶ms, &nparams) < 0) + if (!(identparams =3D virIdentityGetParameters(ident))) goto error; } @@ -1828,7 +1827,7 @@ remoteOpenConn(const char *uri, VIR_DEBUG("Opened driver %p", *conn); if (preserveIdentity) { - if (virConnectSetIdentity(*conn, params, nparams, 0) < 0) + if (virConnectSetIdentity(*conn, identparams->par, identparams->np= ar, 0) < 0) goto error; VIR_DEBUG("Forwarded current identity to secondary driver"); @@ -1836,7 +1835,6 @@ remoteOpenConn(const char *uri, ret =3D 0; cleanup: - virTypedParamsFree(params, nparams); return ret; error: diff --git a/src/util/viridentity.c b/src/util/viridentity.c index 70843ecf9f..e3a9cbb661 100644 --- a/src/util/viridentity.c +++ b/src/util/viridentity.c @@ -838,17 +838,12 @@ int virIdentitySetParameters(virIdentity *ident, } -int virIdentityGetParameters(virIdentity *ident, - virTypedParameterPtr *params, - int *nparams) +virTypedParamList *virIdentityGetParameters(virIdentity *ident) { - *params =3D NULL; - *nparams =3D 0; + virTypedParameter *tmp =3D NULL; - if (virTypedParamsCopy(params, ident->params, ident->nparams) < 0) - return -1; - - *nparams =3D ident->nparams; + if (virTypedParamsCopy(&tmp, ident->params, ident->nparams) < 0) + return NULL; - return 0; + return virTypedParamListFromParams(&tmp, ident->nparams); } diff --git a/src/util/viridentity.h b/src/util/viridentity.h index 6da6d0c557..5f87d7268b 100644 --- a/src/util/viridentity.h +++ b/src/util/viridentity.h @@ -23,6 +23,7 @@ #include "internal.h" #include +#include "virtypedparam.h" #define VIR_TYPE_IDENTITY vir_identity_get_type() G_DECLARE_FINAL_TYPE(virIdentity, vir_identity, VIR, IDENTITY, GObject); @@ -88,6 +89,4 @@ int virIdentitySetParameters(virIdentity *ident, virTypedParameterPtr params, int nparams); -int virIdentityGetParameters(virIdentity *ident, - virTypedParameterPtr *params, - int *nparams); +virTypedParamList *virIdentityGetParameters(virIdentity *ident); --=20 2.35.3 From nobody Tue Apr 30 02:27:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1652865749; cv=none; d=zohomail.com; s=zohoarc; b=Bb1BPbOYP75+d195m8odMRJmrmKnrMVwky0e7K39BZKoU5XBzwdW8CcvyIvGCrir2ZSc/KwIQK4noIlKxE5aTKsmXncaGmCdImxj41/6xtfgBj7Op/VrdaLFytCougJI18w0iMSSF2i+8yIWsgJW0aJQtoInCdIkTa02QIrYjn4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652865749; 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=B+aOTzu9mFkZiDhZl41DN3MmHvWnzBGmOzxUE6Aa/yk=; b=eY3dWmm7kObiBsMdNbLmQFXoMvRty1Flt0ueQf1n8R/amnfu6qoJDtL/Jyz3dPZimh3GTFqrM3QFW27ancEUSXby4FQtOq/ApvGRgDTph9hSm3dGFaUI2AAfKrh+P6OU9oN5XQuX7KQsx97fTIMV8s6JFbM9ze/5E0ccUB5NfEs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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 [170.10.129.124]) by mx.zohomail.com with SMTPS id 1652865749087530.084390887447; Wed, 18 May 2022 02:22:29 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-609-7WLj_RQmMtSUJ5yqOCWHvA-1; Wed, 18 May 2022 05:22:24 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 493A985A5BC; Wed, 18 May 2022 09:22:22 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34A2A1410DD5; Wed, 18 May 2022 09:22:22 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 02C4F1947B8F; Wed, 18 May 2022 09:22:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 89EFE19259FB for ; Wed, 18 May 2022 09:22:18 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6BD5B40CF8F0; Wed, 18 May 2022 09:22:18 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id E299640CF8EE for ; Wed, 18 May 2022 09:22:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652865748; 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=B+aOTzu9mFkZiDhZl41DN3MmHvWnzBGmOzxUE6Aa/yk=; b=f/OIksZABcTX5uKHNHoqSr5xkFU3G4rSUm65L6sqoT73Okv75l/KS51vozGmg1KUmrukP4 UnxzB8xsx0RrQXd8cRs1D4bEQ0EfNbQEeYhExNCwUZFkbee6jjBEeEjDv2LTQnv14+IeuU IIVlfsLe0HG0B3qCU1AAMaEr021l/G0= X-MC-Unique: 7WLj_RQmMtSUJ5yqOCWHvA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/4] doRemoteOpen: Refactor control flow Date: Wed, 18 May 2022 11:22:13 +0200 Message-Id: <47a96a30025981733267d48d5affc77b6c111994.1652865683.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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: 1652865750849100001 Content-Type: text/plain; charset="utf-8" Use a temporary variable 'newconn' to hold the newly opened connection until we are ready to pass it back instead of the original connection. This way we can avoid complicated 'error'/'cleanup' sections. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/remote/remote_daemon_dispatch.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 39953f46cf..c1f85925a3 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -1794,7 +1794,7 @@ remoteOpenConn(const char *uri, virConnectPtr *conn) { g_autoptr(virTypedParamList) identparams =3D NULL; - int ret =3D -1; + g_autoptr(virConnect) newconn =3D NULL; VIR_DEBUG("Getting secondary uri=3D%s readonly=3D%d preserveIdent=3D%d= conn=3D%p", NULLSTR(uri), readonly, preserveIdentity, conn); @@ -1814,34 +1814,30 @@ remoteOpenConn(const char *uri, return -1; if (!(identparams =3D virIdentityGetParameters(ident))) - goto error; + return -1; } VIR_DEBUG("Opening driver %s", uri); if (readonly) - *conn =3D virConnectOpenReadOnly(uri); + newconn =3D virConnectOpenReadOnly(uri); else - *conn =3D virConnectOpen(uri); - if (!*conn) - goto error; - VIR_DEBUG("Opened driver %p", *conn); + newconn =3D virConnectOpen(uri); + + if (!newconn) + return -1; + + VIR_DEBUG("Opened driver %p", newconn); if (preserveIdentity) { if (virConnectSetIdentity(*conn, identparams->par, identparams->np= ar, 0) < 0) - goto error; + return -1; VIR_DEBUG("Forwarded current identity to secondary driver"); } - ret =3D 0; - cleanup: - return ret; + *conn =3D g_steal_pointer(&newconn); - error: - if (*conn) { - g_clear_pointer(conn, virConnectClose); - } - goto cleanup; + return 0; } --=20 2.35.3