From nobody Thu Dec 18 14:53:03 2025 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=1678293594; cv=none; d=zohomail.com; s=zohoarc; b=G9zPJG+/3ucp08NfgbLzJreYft+ioOKHUclAFXSpKdsbW0/ckV/cEAWRbhEXZFnGi/34mX0w/nChtjv9qIWDNIsgfnT1ivnuuY5jUrsEd6MipklN2JM2a6DsuVLSwqwdo9KP5iaq8mQYW8WnaX23WnzFq8RqfBHT6Ng9GB4RcDA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678293594; 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=crIEVgPkiMpmAFHEz5xiSbf2QIOYwP5tiojQ/SXCThw=; b=KnhNlCnV5Zcx0/Akdlpp/XcSSJGMNyzBSmSXrAcVJP38N0hdtPrS4s45Lcr7jFsolUL1zF5JVeSfoMnGUB6pv2K1y9Hhngoll4/4QwxNw/aMlDHig1OHjEz6xwJHdDVhYYxsm4a9L+XlUlDqoCZ6QjCIAfLndgmQDZgtx1H7wsU= 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 1678293594542623.0244197929059; Wed, 8 Mar 2023 08:39:54 -0800 (PST) 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-625-RZ4JGsXIMoyAbtnbcrb5eQ-1; Wed, 08 Mar 2023 11:39:44 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 40F69886463; Wed, 8 Mar 2023 16:39:29 +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 26DC81121330; Wed, 8 Mar 2023 16:39:29 +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 41FB01946A6A; Wed, 8 Mar 2023 16:39:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D51EF1946A7B for ; Wed, 8 Mar 2023 16:39:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id C7F80112132D; Wed, 8 Mar 2023 16:39:19 +0000 (UTC) Received: from virtlab420.virt.lab.eng.bos.redhat.com (virtlab420.virt.lab.eng.bos.redhat.com [10.19.152.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADAB21121314; Wed, 8 Mar 2023 16:39:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678293593; 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=crIEVgPkiMpmAFHEz5xiSbf2QIOYwP5tiojQ/SXCThw=; b=ViF71OjtAc7WrzKXiToC9Z1G9thiP4OI/KAYWLlXlob3RDpVeMGEsf8DLTS0HlJ1qUz+f+ vpaxcTuTEpeqpv9Q5UyP9l8364ch+o3sgjRu5aKTIrvHydKi6MhNejkZ0oBZUQJ3NAAXDA jU5PHfyMKgXkE+4fb0uMSarDrynGW5A= X-MC-Unique: RZ4JGsXIMoyAbtnbcrb5eQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [PATCH 13/16] rpc: use g_auto for client RPC return parameters Date: Wed, 8 Mar 2023 11:39:10 -0500 Message-Id: <20230308163913.338952-14-berrange@redhat.com> In-Reply-To: <20230308163913.338952-1-berrange@redhat.com> References: <20230308163913.338952-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678293594771100001 Currently some, but not all, methods have a call to the xdr_free function, for the 'ret' variable. This is done on methods where there are complex structs containing allocated memory. In other cases the structs contain allocated memory, but the pointer is stolen, so xdr_free is not called. In other cases no allocated memory is present, so xdr_free. This is hard to reason about, because the definition of the struct is not visible in the client stubs. Switch to use g_auto() for the 'ret' variable, which means 'xdr_free' is always going to be called. Some places now need to use g_steal_pointer as a result. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/rpc/gendispatch.pl | 60 +++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index b186849606..e151d33aaa 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -1440,7 +1440,7 @@ elsif ($mode eq "client") { " = &args.$1.$1_len,\n" . " = VIR_TYPED_PARAM_STRING_OKAY) < 0) {\n" . " xdr_free((xdrproc_t)xdr_= $call->{args}, (char *)&args);\n" . - " goto done;\n" . + " goto cleanup;\n" . " }"); push(@free_list, " virTypedParamsRemoteFree((struct= _virTypedParameterRemote *) args.params.params_val,\n" . " args.pa= rams.params_len);\n"); @@ -1527,7 +1527,7 @@ elsif ($mode eq "client") { if ($rettype eq "void") { $call_ret =3D "NULL"; } else { - push(@vars_list, "$rettype ret =3D {0}"); + push(@vars_list, "g_auto($rettype) ret =3D {0}"); =20 foreach my $ret_member (@{$call->{ret_members}}) { if ($multi_ret) { @@ -1582,12 +1582,11 @@ elsif ($mode eq "client") { # error out on unannotated arrays die "$1_nonnull_string array without insert@ a= nnotation: $ret_member"; } elsif ($ret_member =3D~ m/^(?:admin|remote)_nonnull_stri= ng (\S+);/) { - push(@ret_list, "rv =3D ret.$1;"); + push(@ret_list, "rv =3D g_steal_pointer(&ret.$1);"); $single_ret_var =3D "char *rv =3D NULL"; $single_ret_type =3D "char *"; } elsif ($ret_member =3D~ m/^(?:admin|remote)_string (\S+)= ;/) { - push(@ret_list, "rv =3D ret.$1 ? *ret.$1 : NULL;"); - push(@ret_list, "VIR_FREE(ret.$1);"); + push(@ret_list, "rv =3D ret.$1 ? g_steal_pointer(ret.$= 1) : NULL;"); $single_ret_var =3D "char *rv =3D NULL"; $single_ret_type =3D "char *"; } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|network_port|storage_pool|storage_vol|node_device|interface|secret|nwfilt= er|nwfilter_binding|domain_checkpoint|domain_snapshot) (\S+);/) { @@ -1599,7 +1598,6 @@ elsif ($mode eq "client") { # SPECIAL: virDomainCreateWithFlags updates the gi= ven # domain object instead of returning a ne= w one push(@ret_list, "dom->id =3D ret.dom.id;"); - push(@ret_list, "xdr_free((xdrproc_t)xdr_$call->{r= et}, (char *)&ret);"); push(@ret_list, "rv =3D 0;"); $single_ret_var =3D "int rv =3D -1"; $single_ret_type =3D "int"; @@ -1612,7 +1610,6 @@ elsif ($mode eq "client") { push(@ret_list, "rv =3D get_nonnull_$name($pri= v_src, ret.$arg_name);"); } =20 - push(@ret_list, "xdr_free((xdrproc_t)xdr_$rettype,= (char *)&ret);"); $single_ret_var =3D "vir${type_name}Ptr rv =3D NUL= L"; $single_ret_type =3D "vir${type_name}Ptr"; } @@ -1712,8 +1709,6 @@ elsif ($mode eq "client") { push(@ret_list, "rv =3D get_nonnull_$name($priv_sr= c, ret.$arg_name);"); } =20 - push(@ret_list, "xdr_free((xdrproc_t)xdr_$rettype, (ch= ar *)&ret);"); - $single_ret_var =3D "virAdm${type_name}Ptr rv =3D NULL= "; $single_ret_type =3D "virAdm${type_name}Ptr"; } elsif ($ret_member =3D~ m/^(\/)?\*/) { @@ -1820,11 +1815,11 @@ elsif ($mode eq "client") { if ($call->{streamflag} ne "none") { print "\n"; print " if (!(netst =3D virNetClientStreamNew(priv->remoteP= rogram, $call->{constname}, priv->counter, sparse)))\n"; - print " goto done;\n"; + print " goto cleanup;\n"; print "\n"; print " if (virNetClientAddStream(priv->client, netst) < 0)= {\n"; print " virObjectUnref(netst);\n"; - print " goto done;\n"; + print " goto cleanup;\n"; print " }"; print "\n"; print " st->driver =3D &remoteStreamDrv;\n"; @@ -1837,7 +1832,7 @@ elsif ($mode eq "client") { print "\n"; print " if (feature =3D=3D VIR_DRV_FEATURE_REMOTE) {\n"; print " rv =3D 1;\n"; - print " goto done;\n"; + print " goto cleanup;\n"; print " }\n"; } =20 @@ -1847,7 +1842,7 @@ elsif ($mode eq "client") { print " virReportError(VIR_ERR_RPC,\n"; print " _(\"%s length greater than maxim= um: %d > %d\"),\n"; print " $args_check->{name}, (int)$args_= check->{arg}, $args_check->{limit});\n"; - print " goto done;\n"; + print " goto cleanup;\n"; print " }\n"; } =20 @@ -1858,7 +1853,7 @@ elsif ($mode eq "client") { print " _(\"too many remote ${single_ret= _list_error_msg_type}s: %d > %d,\"\n"; print " \"in parameter '$single_ret_li= st_name' for 'vir$call->{ProcName}'\"),\n"; print " $single_ret_list_max_var, $singl= e_ret_list_max_define);\n"; - print " goto done;\n"; + print " goto cleanup;\n"; print " }\n"; } =20 @@ -1909,7 +1904,7 @@ elsif ($mode eq "client") { print " st->privateData =3D NULL;\n"; } =20 - print " goto done;\n"; + print " goto cleanup;\n"; print " }\n"; print "\n"; =20 @@ -1982,29 +1977,22 @@ elsif ($mode eq "client") { } } =20 - if ($single_ret_as_list or $single_ret_cleanup or $modern_ret_as_l= ist) { + print "\n"; + print "cleanup:\n"; + if (@custom_error_cleanup) { + print " if (rv !=3D 0) {\n"; + print " "; + print join("\n ", @custom_error_cleanup); + print " }\n"; + } + if ($modern_ret_as_list) { + print " if (tmp_results) {\n"; + print " for (i =3D 0; i < ret.$single_ret_list_name.${s= ingle_ret_list_name}_len; i++)\n"; + print " virObjectUnref(tmp_results[i]);\n"; + print " VIR_FREE(tmp_results);\n"; + print " }\n"; print "\n"; - print "cleanup:\n"; - if (@custom_error_cleanup) { - print " if (rv !=3D 0) {\n"; - print " "; - print join("\n ", @custom_error_cleanup); - print " }\n"; - } - if ($modern_ret_as_list) { - print " if (tmp_results) {\n"; - print " for (i =3D 0; i < ret.$single_ret_list_name= .${single_ret_list_name}_len; i++)\n"; - print " virObjectUnref(tmp_results[i]);\n"; - print " VIR_FREE(tmp_results);\n"; - print " }\n"; - print "\n"; - } - print " xdr_free((xdrproc_t)xdr_$call->{ret}, (char *)&ret)= ;\n"; } - - print "\n"; - print "done:\n"; - print join("\n", @free_list); =20 print " return rv;\n"; --=20 2.39.1