From nobody Tue May 14 02:04:52 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; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621417465; cv=none; d=zohomail.com; s=zohoarc; b=SbWJz3qR4Fe7SESsSc4c1FZX7QWEjlQyqyzeNS5ecvyxEzSJ66PKASWjFsPiu3eKUy8NIEC3p85vk51CURRaiPAsffnKpL+LDJW/AJxHY8IFdRcjI99UyzTFaQwsf6Nhv5kkRHoi/icPA8GeAXXS2Dr5TqaprWJxTde79oN5iXU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621417465; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=iUEnKFgJPRmy/Sk+hQDPdevQxkPi/3xUcXaI+rwvnIA=; b=f7D55U4v6GVA78rQhMW7era5Ln3dj2qTqsQdA0Ecf3cNeXyUDTXMnoKynUajTXncKDDARu/RBUxjY/TlDkV7PX5c9DT6HXrwQwUOaOLD0eP8d7jsblQSd4emvQJPCyX0AVWJ5c3RiBsAd9zh5AItA1CEVJSgOOa2uJm9jxEqUNA= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com 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 1621417465936330.8209705958195; Wed, 19 May 2021 02:44:25 -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-570-ejAsL-ClM5OMn-gUlP7sCg-1; Wed, 19 May 2021 05:44:22 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E5D8D188E3CC; Wed, 19 May 2021 09:44:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 748D05C230; Wed, 19 May 2021 09:44:17 +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 0EEFB55352; Wed, 19 May 2021 09:44:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14J9bZDh006375 for ; Wed, 19 May 2021 05:37:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 27853BE5CF; Wed, 19 May 2021 09:37:35 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 22A8B9C051 for ; Wed, 19 May 2021 09:37:32 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A0E3E833942 for ; Wed, 19 May 2021 09:37:32 +0000 (UTC) Received: from mo4-p01-ob.smtp.rzone.de (mo4-p01-ob.smtp.rzone.de [85.215.255.52]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-12-jzXqJKTNOPGJHiUIbh_khw-1; Wed, 19 May 2021 05:37:30 -0400 Received: from sender by smtp.strato.de (RZmta 47.26.1 AUTH) with ESMTPSA id c0ae88x4J9bR3cL (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 19 May 2021 11:37:27 +0200 (CEST) X-MC-Unique: ejAsL-ClM5OMn-gUlP7sCg-1 X-MC-Unique: jzXqJKTNOPGJHiUIbh_khw-1 X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: libvir-list@redhat.com Subject: [PATCH v2] libxl: adjust handling of libxl_device_nic objects Date: Wed, 19 May 2021 11:37:25 +0200 Message-Id: <20210519093725.8240-1-olaf@aepfle.de> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Olaf Hering 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.16 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 Content-Type: text/plain; charset="utf-8" libxl objects are supposed to be initialized and disposed. Adjust libxlMakeNic to use an already initialized object, it is owned by the caller. Adjust libxlMakeNicList to initialize the list of objects, before they are filled by libxlMakeNic. In case of error the objects are disposed by libxl_domain_config_dispose. The usage of g_new0 is suspicious in the context of libxl because the memory allocated via glib is released with plain free() inside libxl. Signed-off-by: Olaf Hering --- src/libxl/libxl_conf.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 2d2aab7e66..e4afa578b0 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1345,8 +1345,6 @@ libxlMakeNic(virDomainDef *def, return -1; } =20 - libxl_device_nic_init(x_nic); - virMacAddrGetRaw(&l_nic->mac, x_nic->mac); =20 /* @@ -1532,39 +1530,39 @@ libxlMakeNicList(virDomainDef *def, libxl_domain_c= onfig *d_config) { virDomainNetDef **l_nics =3D def->nets; size_t nnics =3D def->nnets; - libxl_device_nic *x_nics; size_t i, nvnics =3D 0; - - x_nics =3D g_new0(libxl_device_nic, nnics); + int ret =3D -1; =20 for (i =3D 0; i < nnics; i++) { if (virDomainNetGetActualType(l_nics[i]) =3D=3D VIR_DOMAIN_NET_TYP= E_HOSTDEV) continue; + nvnics++; + } + if (!nvnics) + return 0; + + d_config->nics =3D g_new0(libxl_device_nic, nvnics); + d_config->num_nics =3D nvnics; + + for (i =3D 0; i < nvnics; i++) + libxl_device_nic_init(&d_config->nics[i]); =20 - if (libxlMakeNic(def, l_nics[i], &x_nics[nvnics], false)) + for (i =3D 0; i < nvnics; i++) { + if (libxlMakeNic(def, l_nics[i], &d_config->nics[i], false)) goto error; /* * The devid (at least right now) will not get initialized by * libxl in the setup case but is required for starting the * device-model. */ - if (x_nics[nvnics].devid < 0) - x_nics[nvnics].devid =3D nvnics; - - nvnics++; + if (d_config->nics[i].devid < 0) + d_config->nics[i].devid =3D i; } =20 - VIR_SHRINK_N(x_nics, nnics, nnics - nvnics); - d_config->nics =3D x_nics; - d_config->num_nics =3D nvnics; - - return 0; + ret =3D 0; =20 error: - for (i =3D 0; i < nnics; i++) - libxl_device_nic_dispose(&x_nics[i]); - VIR_FREE(x_nics); - return -1; + return ret; } =20 int