From nobody Tue May 14 05:27:31 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=1621414059; cv=none; d=zohomail.com; s=zohoarc; b=kKfviVGWHfvLfkiKrQN3uOGpbTf+wJteWl82Ra+ZHqvEt0fHznA6IH6QYWneUxTwxdf35WwBHqXR1/B8OaDWNquDbVN8SdZa/EQAnBqjEtUG0y+I8iFsJtnjrxoDUTDADZeavggigQTllIk2fo01lm5fR48UIeLTKJ6bcI7peu4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621414059; 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=MMXJFMlnSrRjCVU4Jmv9bk0pFUFqz1Whg0Ov+qMZSmw=; b=K8JU8vSgraPWnqGFMSjXZBpdfaNWYnJv003hZ9rEYc0nSQGJTEcubm/syEzHUcMOGAE72d9VKleL95Lrd+PZeEddWp6d4LO2jCntkNA0PW8JxKe2yrRD3vFHQXEorw0x5uukBP179rxzQ44Ic8Db5r3YmH5D6wFBDQ17Ewka2zc= 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 1621414059187220.41071812517703; Wed, 19 May 2021 01:47:39 -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-508-QV4aefgTPCyS4eJcMqshDw-1; Wed, 19 May 2021 04:47:36 -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 3872A885B64; Wed, 19 May 2021 08:47:07 +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 13BD45C257; Wed, 19 May 2021 08:47:07 +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 CCB4455347; Wed, 19 May 2021 08:47:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14J8iQgL031000 for ; Wed, 19 May 2021 04:44:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 910602039DA1; Wed, 19 May 2021 08:44:26 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8CAEB2039DA0 for ; Wed, 19 May 2021 08:44:24 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (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 2F836185A79C for ; Wed, 19 May 2021 08:44:24 +0000 (UTC) Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.217]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-94-AZZLPFgrMeqJ5g_W2s13pg-1; Wed, 19 May 2021 04:44:21 -0400 Received: from sender by smtp.strato.de (RZmta 47.26.1 AUTH) with ESMTPSA id c0ae88x4J8iJ3Bl (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 19 May 2021 10:44:19 +0200 (CEST) X-MC-Unique: QV4aefgTPCyS4eJcMqshDw-1 X-MC-Unique: AZZLPFgrMeqJ5g_W2s13pg-1 X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzpIG0mv9coXAgs09ValFcstyKtnZMLOo4jr88Zf5nXI1mYJUK+h" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: libvir-list@redhat.com Subject: [PATCH v1] libxl: adjust handling of libxl_device_nic objects Date: Wed, 19 May 2021 10:44:17 +0200 Message-Id: <20210519084417.30713-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.78 on 10.11.54.4 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 | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 2d2aab7e66..a2e73c8b4d 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,38 @@ 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; =20 - if (libxlMakeNic(def, l_nics[i], &x_nics[nvnics], false)) + for (i =3D 0; i < nvnics; i++) + libxl_device_nic_init(&d_config->nics[i]); + + 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