From nobody Mon Feb 9 08:05:37 2026 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=1643899957; cv=none; d=zohomail.com; s=zohoarc; b=HNaPw+xOXTIA840mT0mwMGL6HV2zPgMakreR6RR/HgJL6vqABZxRFvtk/IygQxBq4XlhRXURaR7pYYFfqNuJst1lph21nBP+6xDjTHUHTBB3FsDXMzotMeveNSkOok0gDLsVGfNqOGEzAcFEwSmuCWKv4oh3pu0nnrOHKWG75Q8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643899957; 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=SdZuBI1s/i9n2dvMQcmWO3kk/wFd0OAMqjHZCOKYaJY=; b=hsixsBlOrGFKQMkuZuf5Aek58eFqZlIwM5G/EZB50C6SQGGmhHNNRLyWc01pXj9IEiB94mgCr+pbZ7vevISMX+/jWGe1wsCKXwM7rrrB8xwxy0qpYb0YPSFa2HCyuVCeilOfGG+KtWAoO5a43K5kq46lanuGRfbTIVJu0xOz6rs= 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 1643899957212799.1358821936267; Thu, 3 Feb 2022 06:52:37 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-450-3imyVOmDOhKW43p2mokIeg-1; Thu, 03 Feb 2022 09:52:27 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AD1B181424D; Thu, 3 Feb 2022 14:52:21 +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 8954222E10; Thu, 3 Feb 2022 14:52:21 +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 574C51809CB8; Thu, 3 Feb 2022 14:52:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 213EqAKi029432 for ; Thu, 3 Feb 2022 09:52:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id E0AED70D30; Thu, 3 Feb 2022 14:52:10 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 402B070D3D for ; Thu, 3 Feb 2022 14:52:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643899956; 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=SdZuBI1s/i9n2dvMQcmWO3kk/wFd0OAMqjHZCOKYaJY=; b=XOjMQsxDD2Sn10zgXpSfOE4i+T9kVl8dxm52qSAggPzR2Uckxdyv7chMKM+JwlenmAXZK+ zq8u9z3GXRmyr3NttbE5D129fZqXtjRK3LgXaxt6uZacnSzlp4PL323wtB6KQvafDTyvxa vHMG1IbnK3Ocg0+pf9fkv7GiUKrf6Aw= X-MC-Unique: 3imyVOmDOhKW43p2mokIeg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/5] cmdStartGetFDs: Modernize Date: Thu, 3 Feb 2022 15:51:56 +0100 Message-Id: <8fa4fe86750f3951941492ec9033441f381066c1.1643899820.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.84 on 10.5.11.23 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: 1643899959166100001 Content-Type: text/plain; charset="utf-8" Calculate the length of the FD list beforehand to avoid multiple expansions and mainly simplify the code and use automatic freeing to remove the error code path. Signed-off-by: Peter Krempa --- tools/virsh-domain.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 43d310f2af..b4cb7193a7 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -4021,7 +4021,7 @@ cmdStartGetFDs(vshControl *ctl, { const char *fdopt; g_auto(GStrv) fdlist =3D NULL; - int *fds =3D NULL; + g_autofree int *fds =3D NULL; size_t nfds =3D 0; size_t i; @@ -4036,23 +4036,19 @@ cmdStartGetFDs(vshControl *ctl, return -1; } + nfds =3D g_strv_length(fdlist); + fds =3D g_new0(int, nfds); + for (i =3D 0; fdlist[i] !=3D NULL; i++) { - int fd; - if (virStrToLong_i(fdlist[i], NULL, 10, &fd) < 0) { + if (virStrToLong_i(fdlist[i], NULL, 10, fds + i) < 0) { vshError(ctl, _("Unable to parse FD number '%s'"), fdlist[i]); - goto error; + return -1; } - VIR_EXPAND_N(fds, nfds, 1); - fds[nfds - 1] =3D fd; } - *fdsret =3D fds; + *fdsret =3D g_steal_pointer(&fds); *nfdsret =3D nfds; return 0; - - error: - VIR_FREE(fds); - return -1; } static bool --=20 2.34.1