From nobody Mon Nov 25 19:48:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1594156498; cv=none; d=zohomail.com; s=zohoarc; b=eF+fyubogkGT2OQCk2FW7ADzoRsk5ZdiLnbAvNrPRk5RXRD6g4FapVaoDcT4u2+koYU5VDTtUuEo4ZY/SoTGqFALGgoZVetlcHZ0zqEIPGycXyAaeYD8ZmHd4NaWrexx/zRtArmDjsuKBbl0z6V83jGXBOOStykAQ8vkIgOr97E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594156498; 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=fDu/APagev+tfVLHU0sAcn1Manuqe+XLnW7PLKnjbjs=; b=JlsLsbiqsM+WbVyuSwwUhwXe5v+XN/MvyrsMTCEbqtU9s8P7QSz7FN211bQbBNgclNtJDqH1IvRklUElwaxAJ71+h/ymqoCf+ghUSG5F/Z+Na0/e+TQfP5VlITy/BSc1JW6Vj4qae8NZODTMlNVH4trf7pN3rZVMQM15VIIO1dU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1594156498691278.91258303198356; Tue, 7 Jul 2020 14:14:58 -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-191-kSaZW1QDMVyfH8KIXAIVzg-1; Tue, 07 Jul 2020 17:14:54 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4348F1009600; Tue, 7 Jul 2020 21:14:49 +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 2593E5BAC3; Tue, 7 Jul 2020 21:14:49 +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 E54721809547; Tue, 7 Jul 2020 21:14:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067L8NMM007927 for ; Tue, 7 Jul 2020 17:08:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 68A1179220; Tue, 7 Jul 2020 21:08:23 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E063797E9 for ; Tue, 7 Jul 2020 21:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594156497; 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=fDu/APagev+tfVLHU0sAcn1Manuqe+XLnW7PLKnjbjs=; b=Tsp+8D2Rb6pCLae2KRYOhbjaz/F8o2HVstGDq6fNlb0Ic1FXcmA5WXMqCL1Vjbl5WVObHa 3ot1COBouj93/fuxGBFotU75LSDNe9GCtVbOvmzBHjK8mhDorAHSrR2CqSX5FOAp1H+D1V L1cxWUWf/1LvKff321/uNMEgeM1pH0Q= X-MC-Unique: kSaZW1QDMVyfH8KIXAIVzg-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 01/15] replace g_new() with g_new0() for consistency Date: Tue, 7 Jul 2020 17:08:01 -0400 Message-Id: <20200707210815.1797463-2-laine@redhat.com> In-Reply-To: <20200707210815.1797463-1-laine@redhat.com> References: <20200707210815.1797463-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.79 on 10.5.11.15 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) Content-Type: text/plain; charset="utf-8" g_new() is used in only 3 places. Switching them to g_new0() will do no harm, reduces confusion, and helps me sleep better at night knowing that all allocated memory is initialized to 0 :-) (Yes, I *know* that in all three cases the associated memory is immediately assigned some other value. Today.) Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_backup.c | 2 +- src/util/virutil.c | 2 +- tests/qemuhotplugmock.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c index 8dc9d2504d..dae9300567 100644 --- a/src/qemu/qemu_backup.c +++ b/src/qemu/qemu_backup.c @@ -64,7 +64,7 @@ qemuBackupPrepare(virDomainBackupDefPtr def) =20 if (def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PULL) { if (!def->server) { - def->server =3D g_new(virStorageNetHostDef, 1); + def->server =3D g_new0(virStorageNetHostDef, 1); =20 def->server->transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; def->server->name =3D g_strdup("localhost"); diff --git a/src/util/virutil.c b/src/util/virutil.c index 04f882fda7..ff664ea778 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -962,7 +962,7 @@ virGetGroupList(uid_t uid, gid_t gid, gid_t **list) if (uid !=3D (uid_t)-1 && virGetUserEnt(uid, &user, &primary, NULL, NULL, true) >=3D 0) { int nallocgrps =3D 10; - gid_t *grps =3D g_new(gid_t, nallocgrps); + gid_t *grps =3D g_new0(gid_t, nallocgrps); =20 while (1) { int nprevallocgrps =3D nallocgrps; diff --git a/tests/qemuhotplugmock.c b/tests/qemuhotplugmock.c index d2324913cf..29fac8a598 100644 --- a/tests/qemuhotplugmock.c +++ b/tests/qemuhotplugmock.c @@ -57,7 +57,7 @@ virDevMapperGetTargets(const char *path, *devPaths =3D NULL; =20 if (STREQ(path, "/dev/mapper/virt")) { - *devPaths =3D g_new(char *, 4); + *devPaths =3D g_new0(char *, 4); (*devPaths)[0] =3D g_strdup("/dev/block/8:0"); /* /dev/sda */ (*devPaths)[1] =3D g_strdup("/dev/block/8:16"); /* /dev/sdb */ (*devPaths)[2] =3D g_strdup("/dev/block/8:32"); /* /dev/sdc */ --=20 2.25.4 From nobody Mon Nov 25 19:48:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1594156318; cv=none; d=zohomail.com; s=zohoarc; b=Vc1fjWc2wE/szUm5enMX1Cvly+JEQZC+DeHJ+KD5kcKRYNCCgdaSKS0c+S/8YySbqNZi2xv6K4Ceo2jIN0ePRDSOBa0mE6ebjDLhjInfBsx/DHGwcHevXtOe9FnYE6pDCmrxxCGGEXSRxDjOx6DIDhDAENRuxXsvRdso2npZZBw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594156318; 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=Gs27YS8z5HILSqFKQQpocL3g1KLU9e5rBbV50pPDLjI=; b=fMeRirQ2m1xrlIlhf+nRwL9SpyPFlYMACxyfVXZ0fR6nZXhIdNW5Kit9HRQkzKjmRlXisD3a3/DXn/Tl+QFCxSmIhAMCat4nC+SVw1T3AQ3LrbQtcYKj6UWjRASBCq/HhlXDmhHobgPRb9esRFQ5VhKqIAsAU7q7iDuI+zwNsBw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1594156318068636.7350551728098; Tue, 7 Jul 2020 14:11:58 -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-60-xLOvFg2DPUqKGKATDxi1Zg-1; Tue, 07 Jul 2020 17:11:54 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C6B71106B242; Tue, 7 Jul 2020 21:11:46 +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 468F3512FE; Tue, 7 Jul 2020 21:11:46 +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 0AF2872F69; Tue, 7 Jul 2020 21:11:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067L8NiQ007933 for ; Tue, 7 Jul 2020 17:08:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id DEF38797E0; Tue, 7 Jul 2020 21:08:23 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9599379220 for ; Tue, 7 Jul 2020 21:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594156316; 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=Gs27YS8z5HILSqFKQQpocL3g1KLU9e5rBbV50pPDLjI=; b=P21nOwtNms/K282ggJ/JQQJOJKp19L083Z2qpWz1jLyYIXMyt4Viz5RmgUYHu1sZUcO9Fr b10YTvUufDWIcWXte5in5MWU9GVgfulRIEobwNsr0eriI1ECvHyFiV987hfoZt6eKnGbo2 okWyUYRSniOqgTsGUqtZu0ksU9x8/6k= X-MC-Unique: xLOvFg2DPUqKGKATDxi1Zg-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 02/15] util: define g_autoptr cleanups for a couple dnsmasq objects Date: Tue, 7 Jul 2020 17:08:02 -0400 Message-Id: <20200707210815.1797463-3-laine@redhat.com> In-Reply-To: <20200707210815.1797463-1-laine@redhat.com> References: <20200707210815.1797463-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.79 on 10.5.11.11 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/util/virdnsmasq.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/virdnsmasq.h b/src/util/virdnsmasq.h index 4c14bc6ca7..e3814c2eb1 100644 --- a/src/util/virdnsmasq.h +++ b/src/util/virdnsmasq.h @@ -78,10 +78,14 @@ typedef enum { typedef struct _dnsmasqCaps dnsmasqCaps; typedef dnsmasqCaps *dnsmasqCapsPtr; =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(dnsmasqCaps, virObjectUnref); + =20 dnsmasqContext * dnsmasqContextNew(const char *network_name, const char *config_dir); void dnsmasqContextFree(dnsmasqContext *ctx); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(dnsmasqContext, dnsmasqContextFree); + int dnsmasqAddDhcpHost(dnsmasqContext *ctx, const char *mac, virSocketAddr *ip, --=20 2.25.4 From nobody Mon Nov 25 19:48:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1594156324; cv=none; d=zohomail.com; s=zohoarc; b=DXiwppiclS/TDx97eH/fzCIr8MMIajPiE7f9Co2Vm1Si53Jed3YFHLQUCcpLEpQE2qhnhlqHrh2mODvX1wlCujvaNlEiw6tDzfIZo+pnyy+HzMBB4zai5llmjnu0rolY48wPyrgZY3e3GRqkJwf7wymrL0R7CaFbntVD7BeP3SY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594156324; 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=AbEy0OfA1YOPc5VROaLsacoUK0XQEKy0TlumLtVHc10=; b=H6vDwdN1K4MHxCdWfl5Pjder/HYXTc46XGPGGIELZaNads0selZtEq809eM96u3d5AsZub6vxlRVmCQ4pliiSghVdbnZ1cX7NdE9s5U87cdtKKORxMqnruqiswGdDRY3Qf7urlsbjQvXdfRMty5OdaTM+V6OM++hhnQePR5J7Hw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1594156324786775.2176557169149; Tue, 7 Jul 2020 14:12:04 -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-395-kvzQhEfvPkOtIZCTek3u7Q-1; Tue, 07 Jul 2020 17:12:01 -0400 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 CD747EC1A3; Tue, 7 Jul 2020 21:11:55 +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 56D691A7D8; Tue, 7 Jul 2020 21:11:55 +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 0236D1809547; Tue, 7 Jul 2020 21:11:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067L8OY6007938 for ; Tue, 7 Jul 2020 17:08:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 60B61797E0; Tue, 7 Jul 2020 21:08:24 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1824479220 for ; Tue, 7 Jul 2020 21:08:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594156323; 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=AbEy0OfA1YOPc5VROaLsacoUK0XQEKy0TlumLtVHc10=; b=Z7gIwfzLBo+QruivZAMCtgdIvstMVXMtHRNoeXv7LqpwOqiNaewM6dkRXuzpI71Kk/cN3j HD9rz/Ulf4b+Iu6N9ZigJP1lDFZrflk+iBTy4v907sXCySsRokGinzxWxcCWtvkYBfhJ5S lTzSl3vjRRrvYC9L9mNSoIVDj3m8uq0= X-MC-Unique: kvzQhEfvPkOtIZCTek3u7Q-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 03/15] define g_autoptr cleanup function for virNetworkDHCPLease Date: Tue, 7 Jul 2020 17:08:03 -0400 Message-Id: <20200707210815.1797463-4-laine@redhat.com> In-Reply-To: <20200707210815.1797463-1-laine@redhat.com> References: <20200707210815.1797463-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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) Content-Type: text/plain; charset="utf-8" virNetworkDHCPLease and virNetworkDHCPLeaseFree() are declared in the public API file libvirt-network.h, and we can't pollute that with glib macro invocations, so put this in src/datatypes.h next to the other virNetwork items. Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/datatypes.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/datatypes.h b/src/datatypes.h index d58429ad6c..ade3779e43 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -635,6 +635,8 @@ struct _virNetworkPort { =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetworkPort, virObjectUnref); =20 +/* virNetworkDHCPLease is defined in the public API - libvirt-network.h */ +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetworkDHCPLease, virNetworkDHCPLeaseFree= ); =20 /** * _virInterface: --=20 2.25.4 From nobody Mon Nov 25 19:48:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1594156444; cv=none; d=zohomail.com; s=zohoarc; b=DIZSmkLR5SSGiV0xSrU9TSYZgdfZvT+xlsE+/WDbnCFTtEDNHu9aJECrzZ5UcWq7g+lQZ4p+KIEPLubpEuyY2ry05+B9teGEKrqoVzdQjthn3tOQuOf2YuijSWsH4lZhWy4ztMqR+v/7Jv4mlItaZ1HQfxhYarxyI89HToKF5kw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594156444; 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=7YroraUqqy5ywvPA8rJg5OC0Z/GgfHaoYoYjlxKaQX8=; b=bJZOobadGapsytb9bcLWcuIdEsVbG/zocvmSpeX6lXaBypQyPWG3lDenKEX5FFMEkQDgw3B0eJ+CIwzxVryhsa6O9PkdB2urabvjfs1uKTBbrPiLwlQ6EVt2KD+QHhEGpZiYnT+qoV4z3HTYwGwjGTgAj2IkswGAV/o6DeDbZWU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1594156444137380.74283808820667; Tue, 7 Jul 2020 14:14:04 -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-394-UtUEOvCzMbKrE8jJPNLEzQ-1; Tue, 07 Jul 2020 17:12:05 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A4C1FEC1A5; Tue, 7 Jul 2020 21:11:59 +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 878295BAC3; Tue, 7 Jul 2020 21:11:59 +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 5B32472F74; Tue, 7 Jul 2020 21:11:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067L8OOr007948 for ; Tue, 7 Jul 2020 17:08:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id D6C10797E0; Tue, 7 Jul 2020 21:08:24 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FCDF79220 for ; Tue, 7 Jul 2020 21:08:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594156442; 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=7YroraUqqy5ywvPA8rJg5OC0Z/GgfHaoYoYjlxKaQX8=; b=PZC9SywYUwe25dckixWAC6E6AJo5dBKcN3bpe4itUEvlEt/SuscXwZAr78ibJLbAmj5r8b YIFnNg919rYChHXkkwgq2PA6oisyBRQixDArWt2hstTtyuz4vU8spw+4BqTSZ7cQ8Z5GmF 0iKWFcID/csXAXcSQtNE7sS6hATiX6I= X-MC-Unique: UtUEOvCzMbKrE8jJPNLEzQ-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 04/15] network: replace VIR_ALLOC/REALLOC with g_new0/g_renew Date: Tue, 7 Jul 2020 17:08:04 -0400 Message-Id: <20200707210815.1797463-5-laine@redhat.com> In-Reply-To: <20200707210815.1797463-1-laine@redhat.com> References: <20200707210815.1797463-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.79 on 10.5.11.15 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/network/bridge_driver.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 713763130b..ab359acdb5 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -177,8 +177,7 @@ networkDnsmasqDefNamespaceParseOptions(networkDnsmasqXm= lNsDefPtr nsdef, if (nnodes =3D=3D 0) return 0; =20 - if (VIR_ALLOC_N(nsdef->options, nnodes) < 0) - return -1; + nsdef->options =3D g_new0(char *, nnodes); =20 for (i =3D 0; i < nnodes; i++) { if (!(nsdef->options[nsdef->noptions++] =3D virXMLPropString(nodes= [i], "value"))) { @@ -196,12 +195,9 @@ static int networkDnsmasqDefNamespaceParse(xmlXPathContextPtr ctxt, void **data) { - networkDnsmasqXmlNsDefPtr nsdata =3D NULL; + networkDnsmasqXmlNsDefPtr nsdata =3D g_new0(networkDnsmasqXmlNsDef, 1); int ret =3D -1; =20 - if (VIR_ALLOC(nsdata) < 0) - return -1; - if (networkDnsmasqDefNamespaceParseOptions(nsdata, ctxt)) goto cleanup; =20 @@ -733,8 +729,7 @@ networkStateInitialize(bool privileged, return -1; } =20 - if (VIR_ALLOC(network_driver) < 0) - goto error; + network_driver =3D g_new0(virNetworkDriverState, 1); =20 network_driver->lockFD =3D -1; if (virMutexInit(&network_driver->lock) < 0) { @@ -2753,8 +2748,7 @@ networkCreateInterfacePool(virNetworkDefPtr netdef) goto cleanup; } =20 - if (VIR_ALLOC_N(netdef->forward.ifs, numVirtFns) < 0) - goto cleanup; + netdef->forward.ifs =3D g_new0(virNetworkForwardIfDef, numVirtFns); =20 for (i =3D 0; i < numVirtFns; i++) { virPCIDeviceAddressPtr thisVirtFn =3D virtFns[i]; @@ -4323,8 +4317,7 @@ networkGetDHCPLeases(virNetworkPtr net, continue; =20 if (need_results) { - if (VIR_ALLOC(lease) < 0) - goto error; + lease =3D g_new0(virNetworkDHCPLease, 1); =20 lease->expirytime =3D expirytime_tmp; =20 @@ -4378,9 +4371,8 @@ networkGetDHCPLeases(virNetworkPtr net, =20 if (leases_ret) { /* NULL terminated array */ - ignore_value(VIR_REALLOC_N(leases_ret, nleases + 1)); - *leases =3D leases_ret; - leases_ret =3D NULL; + leases_ret =3D g_renew(virNetworkDHCPLeasePtr, leases_ret, nlease= s + 1); + *leases =3D g_steal_pointer(&leases_ret); } =20 rv =3D nleases; @@ -5612,10 +5604,9 @@ networkPortSetParameters(virNetworkPortPtr port, if (!(dir =3D virNetworkObjGetPortStatusDir(obj, driver->stateDir))) goto cleanup; =20 - if ((VIR_ALLOC(bandwidth) < 0) || - (VIR_ALLOC(bandwidth->in) < 0) || - (VIR_ALLOC(bandwidth->out) < 0)) - goto cleanup; + bandwidth =3D g_new0(virNetDevBandwidth, 1); + bandwidth->in =3D g_new0(virNetDevBandwidthRate, 1); + bandwidth->out =3D g_new0(virNetDevBandwidthRate, 1); =20 for (i =3D 0; i < nparams; i++) { virTypedParameterPtr param =3D ¶ms[i]; --=20 2.25.4 From nobody Mon Nov 25 19:48:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1594156502; cv=none; d=zohomail.com; s=zohoarc; b=LOPB3LNIhP1zQkYINeEvoV/vn1+jLZoE6T3eFEZF3h/7zU3tnLBAejPt51n7z9mY5yngIJ/tCArB3Ajh49it09s6ptBPINLCirookl2ixtuBw5NnTDosxIusUkQBfF2CRoe6v8p6Z9Yyg2btw1Ci9Pfpfspc4Hkb7zONK1ymNEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594156502; 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=bA26iqyIikBHvyFWvprvGlDk4SkPHiSLHPULS9ThjCY=; b=ULQLnx0ftUM5g8r5JSuJbjusf8uFoeALI8sTC1HWVPN7igon5mQhvZ4v4O/zMqfYYgUaw0CCThNF8K++QCwc28fIWeQKHuI2cSCnOVKh6tVMzlXCv1CG5gs5dlVykkFwmbFzkVnSkjCkpbteYqUVTJcbcZrX929XHGM08Gbx4/8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1594156501999688.5581940854748; Tue, 7 Jul 2020 14:15:01 -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-85-gJqKNnwBNNmbIZcHoRS0Xw-1; Tue, 07 Jul 2020 17:14:58 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 270C4EC1AE; Tue, 7 Jul 2020 21:14:52 +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 054B15D9C9; Tue, 7 Jul 2020 21:14:52 +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 CB2B91809557; Tue, 7 Jul 2020 21:14:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067L8PMc007959 for ; Tue, 7 Jul 2020 17:08:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 70608797EB; Tue, 7 Jul 2020 21:08:25 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10F3E797E0 for ; Tue, 7 Jul 2020 21:08:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594156500; 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=bA26iqyIikBHvyFWvprvGlDk4SkPHiSLHPULS9ThjCY=; b=NpMgRiN/rlI26Lo8sssa4ny5RA7MwQ5qBUXgL72wokiviXMM5I/pjvsQblRAgoka535C0W kcN6JoNliJvTuWnGhvW/cC/mkv0KGDWTOc+8ztgrKUqGNybhz/xKSUMMBE5zmP1Y1L8ZEC cvBPDOLKN8e/WVu5jD57fdhuPjLzL58= X-MC-Unique: gJqKNnwBNNmbIZcHoRS0Xw-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 05/15] network: use g_auto wherever appropriate Date: Tue, 7 Jul 2020 17:08:05 -0400 Message-Id: <20200707210815.1797463-6-laine@redhat.com> In-Reply-To: <20200707210815.1797463-1-laine@redhat.com> References: <20200707210815.1797463-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.79 on 10.5.11.14 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) Content-Type: text/plain; charset="utf-8" This includes standard g_autofree() as well as other objects that have a cleanup function defined to use via g_autoptr (virCommand, virJSONValue) Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/network/bridge_driver.c | 206 ++++++++++-------------------- src/network/bridge_driver_linux.c | 7 +- src/network/leaseshelper.c | 16 +-- 3 files changed, 76 insertions(+), 153 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index ab359acdb5..31bd0dd92c 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -160,6 +160,7 @@ networkDnsmasqDefNamespaceFree(void *nsdata) =20 VIR_FREE(def); } +G_DEFINE_AUTOPTR_CLEANUP_FUNC(networkDnsmasqXmlNsDef, networkDnsmasqDefNam= espaceFree); =20 =20 static int @@ -195,7 +196,7 @@ static int networkDnsmasqDefNamespaceParse(xmlXPathContextPtr ctxt, void **data) { - networkDnsmasqXmlNsDefPtr nsdata =3D g_new0(networkDnsmasqXmlNsDef, 1); + g_autoptr(networkDnsmasqXmlNsDef) nsdata =3D g_new0(networkDnsmasqXmlN= sDef, 1); int ret =3D -1; =20 if (networkDnsmasqDefNamespaceParseOptions(nsdata, ctxt)) @@ -207,7 +208,6 @@ networkDnsmasqDefNamespaceParse(xmlXPathContextPtr ctxt, ret =3D 0; =20 cleanup: - networkDnsmasqDefNamespaceFree(nsdata); return ret; } =20 @@ -329,7 +329,7 @@ networkRunHook(virNetworkObjPtr obj, { virNetworkDefPtr def; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - char *xml =3D NULL; + g_autofree char *xml =3D NULL; int hookret; int ret =3D -1; =20 @@ -366,7 +366,6 @@ networkRunHook(virNetworkObjPtr obj, =20 ret =3D 0; cleanup: - VIR_FREE(xml); return ret; } =20 @@ -431,14 +430,14 @@ static int networkRemoveInactive(virNetworkDriverStatePtr driver, virNetworkObjPtr obj) { - char *leasefile =3D NULL; - char *customleasefile =3D NULL; - char *radvdconfigfile =3D NULL; - char *configfile =3D NULL; - char *radvdpidbase =3D NULL; - char *statusfile =3D NULL; - char *macMapFile =3D NULL; - dnsmasqContext *dctx =3D NULL; + g_autofree char *leasefile =3D NULL; + g_autofree char *customleasefile =3D NULL; + g_autofree char *radvdconfigfile =3D NULL; + g_autofree char *configfile =3D NULL; + g_autofree char *radvdpidbase =3D NULL; + g_autofree char *statusfile =3D NULL; + g_autofree char *macMapFile =3D NULL; + g_autoptr(dnsmasqContext) dctx =3D NULL; virNetworkDefPtr def =3D virNetworkObjGetPersistentDef(obj); =20 int ret =3D -1; @@ -492,14 +491,6 @@ networkRemoveInactive(virNetworkDriverStatePtr driver, ret =3D 0; =20 cleanup: - VIR_FREE(leasefile); - VIR_FREE(configfile); - VIR_FREE(customleasefile); - VIR_FREE(radvdconfigfile); - VIR_FREE(radvdpidbase); - VIR_FREE(statusfile); - VIR_FREE(macMapFile); - dnsmasqContextFree(dctx); return ret; } =20 @@ -550,9 +541,9 @@ networkUpdateState(virNetworkObjPtr obj, { virNetworkDefPtr def; virNetworkDriverStatePtr driver =3D opaque; - dnsmasqCapsPtr dnsmasq_caps =3D networkGetDnsmasqCaps(driver); + g_autoptr(dnsmasqCaps) dnsmasq_caps =3D networkGetDnsmasqCaps(driver); virMacMapPtr macmap; - char *macMapFile =3D NULL; + g_autofree char *macMapFile =3D NULL; int ret =3D -1; =20 virObjectLock(obj); @@ -614,7 +605,7 @@ networkUpdateState(virNetworkObjPtr obj, if (virNetworkObjIsActive(obj) && def->ips && (def->nips > 0)) { pid_t radvdPid; pid_t dnsmasqPid; - char *radvdpidbase; + g_autofree char *radvdpidbase =3D NULL; =20 ignore_value(virPidFileReadIfAlive(driver->pidDir, def->name, @@ -630,14 +621,11 @@ networkUpdateState(virNetworkObjPtr obj, radvdpidbase, &radvdPid, RADVD)); virNetworkObjSetRadvdPid(obj, radvdPid); - VIR_FREE(radvdpidbase); } =20 ret =3D 0; cleanup: virObjectUnlock(obj); - virObjectUnref(dnsmasq_caps); - VIR_FREE(macMapFile); return ret; } =20 @@ -716,8 +704,8 @@ networkStateInitialize(bool privileged, void *opaque G_GNUC_UNUSED) { int ret =3D VIR_DRV_STATE_INIT_ERROR; - char *configdir =3D NULL; - char *rundir =3D NULL; + g_autofree char *configdir =3D NULL; + g_autofree char *rundir =3D NULL; bool autostart =3D true; #ifdef WITH_FIREWALLD DBusConnection *sysbus =3D NULL; @@ -845,8 +833,6 @@ networkStateInitialize(bool privileged, =20 ret =3D VIR_DRV_STATE_INIT_COMPLETE; cleanup: - VIR_FREE(configdir); - VIR_FREE(rundir); return ret; =20 error: @@ -1047,10 +1033,11 @@ networkDnsmasqConfLocalPTRs(virBufferPtr buf, { virNetworkIPDefPtr ip; size_t i; - char *ptr =3D NULL; int rc; =20 for (i =3D 0; i < def->nips; i++) { + g_autofree char *ptr =3D NULL; + ip =3D def->ips + i; =20 if (ip->localPTR !=3D VIR_TRISTATE_BOOL_YES) @@ -1071,7 +1058,6 @@ networkDnsmasqConfLocalPTRs(virBufferPtr buf, } =20 virBufferAsprintf(buf, "local=3D/%s/\n", ptr); - VIR_FREE(ptr); } =20 return 0; @@ -1095,7 +1081,6 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, bool wantDNS =3D dns->enable !=3D VIR_TRISTATE_BOOL_NO; virNetworkIPDefPtr tmpipdef, ipdef, ipv4def, ipv6def; bool ipv6SLAAC; - char *saddr =3D NULL, *eaddr =3D NULL; =20 *configstr =3D NULL; =20 @@ -1150,12 +1135,11 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, if (fwd->domain) virBufferAsprintf(&configbuf, "/%s/", fwd->domain); if (VIR_SOCKET_ADDR_VALID(&fwd->addr)) { - char *addr =3D virSocketAddrFormat(&fwd->addr); + g_autofree char *addr =3D virSocketAddrFormat(&fwd->addr); =20 if (!addr) goto cleanup; virBufferAsprintf(&configbuf, "%s\n", addr); - VIR_FREE(addr); if (!fwd->domain) addNoResolv =3D true; } else { @@ -1228,7 +1212,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, for (i =3D 0; (tmpipdef =3D virNetworkDefGetIPByIndex(def, AF_UNSPEC, i)); i++) { - char *ipaddr =3D virSocketAddrFormat(&tmpipdef->address); + g_autofree char *ipaddr =3D virSocketAddrFormat(&tmpipdef->add= ress); =20 if (!ipaddr) goto cleanup; @@ -1254,11 +1238,9 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, "(as described in RFC1918/RFC3484/RFC4193= )."), ipaddr, (int)version / 1000000, (int)(version % 1000000) / 1000); - VIR_FREE(ipaddr); goto cleanup; } virBufferAsprintf(&configbuf, "listen-address=3D%s\n", ipaddr); - VIR_FREE(ipaddr); } } =20 @@ -1414,6 +1396,8 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, int thisRange; virNetworkDHCPRangeDef range =3D ipdef->ranges[r]; g_autofree char *leasetime =3D NULL; + g_autofree char *saddr =3D NULL; + g_autofree char *eaddr =3D NULL; =20 if (!(saddr =3D virSocketAddrFormat(&range.addr.start)) || !(eaddr =3D virSocketAddrFormat(&range.addr.end))) @@ -1446,8 +1430,6 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, =20 virBufferAddLit(&configbuf, "\n"); =20 - VIR_FREE(saddr); - VIR_FREE(eaddr); thisRange =3D virSocketAddrGetRange(&range.addr.start, &range.addr.end, &ipdef->address, @@ -1464,7 +1446,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, * support) */ if (!ipdef->nranges && ipdef->nhosts) { - char *bridgeaddr =3D virSocketAddrFormat(&ipdef->address); + g_autofree char *bridgeaddr =3D virSocketAddrFormat(&ipdef->ad= dress); if (!bridgeaddr) goto cleanup; virBufferAsprintf(&configbuf, "dhcp-range=3D%s,static", @@ -1472,7 +1454,6 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET6)) virBufferAsprintf(&configbuf, ",%d", prefix); virBufferAddLit(&configbuf, "\n"); - VIR_FREE(bridgeaddr); } =20 if (networkBuildDnsmasqDhcpHostsList(dctx, ipdef) < 0) @@ -1492,13 +1473,12 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, =20 if (ipdef->bootfile) { if (VIR_SOCKET_ADDR_VALID(&ipdef->bootserver)) { - char *bootserver =3D virSocketAddrFormat(&ipdef->boots= erver); + g_autofree char *bootserver =3D virSocketAddrFormat(&i= pdef->bootserver); =20 if (!bootserver) goto cleanup; virBufferAsprintf(&configbuf, "dhcp-boot=3D%s%s%s\n", ipdef->bootfile, ",,", bootserver); - VIR_FREE(bootserver); } else { virBufferAsprintf(&configbuf, "dhcp-boot=3D%s\n", ipde= f->bootfile); } @@ -1543,12 +1523,11 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, (ipdef =3D virNetworkDefGetIPByIndex(def, AF_INET6, i)); i++) { if (!(ipdef->nranges || ipdef->nhosts)) { - char *bridgeaddr =3D virSocketAddrFormat(&ipdef->addre= ss); + g_autofree char *bridgeaddr =3D virSocketAddrFormat(&i= pdef->address); if (!bridgeaddr) goto cleanup; virBufferAsprintf(&configbuf, "dhcp-range=3D%s,ra-only\n", bridgea= ddr); - VIR_FREE(bridgeaddr); } } } @@ -1569,8 +1548,6 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, ret =3D 0; =20 cleanup: - VIR_FREE(saddr); - VIR_FREE(eaddr); return ret; } =20 @@ -1584,13 +1561,13 @@ networkBuildDhcpDaemonCommandLine(virNetworkDriverS= tatePtr driver, dnsmasqContext *dctx) { virNetworkDefPtr def =3D virNetworkObjGetDef(obj); - dnsmasqCapsPtr dnsmasq_caps =3D networkGetDnsmasqCaps(driver); - virCommandPtr cmd =3D NULL; + g_autoptr(dnsmasqCaps) dnsmasq_caps =3D networkGetDnsmasqCaps(driver); + g_autoptr(virCommand) cmd =3D NULL; int ret =3D -1; - char *configfile =3D NULL; - char *configstr =3D NULL; - char *hostsfilestr =3D NULL; - char *leaseshelper_path =3D NULL; + g_autofree char *configfile =3D NULL; + g_autofree char *configstr =3D NULL; + g_autofree char *hostsfilestr =3D NULL; + g_autofree char *leaseshelper_path =3D NULL; =20 virNetworkObjSetDnsmasqPid(obj, -1); =20 @@ -1625,14 +1602,9 @@ networkBuildDhcpDaemonCommandLine(virNetworkDriverSt= atePtr driver, virCommandAddArgFormat(cmd, "--dhcp-script=3D%s", leaseshelper_path); virCommandAddEnvPair(cmd, "VIR_BRIDGE_NAME", def->bridge); =20 - *cmdout =3D cmd; + *cmdout =3D g_steal_pointer(&cmd); ret =3D 0; cleanup: - virObjectUnref(dnsmasq_caps); - VIR_FREE(configfile); - VIR_FREE(configstr); - VIR_FREE(hostsfilestr); - VIR_FREE(leaseshelper_path); return ret; } =20 @@ -1645,11 +1617,11 @@ networkStartDhcpDaemon(virNetworkDriverStatePtr dri= ver, virNetworkIPDefPtr ipdef; size_t i; bool needDnsmasq =3D false; - virCommandPtr cmd =3D NULL; - char *pidfile =3D NULL; + g_autoptr(virCommand) cmd =3D NULL; + g_autofree char *pidfile =3D NULL; pid_t dnsmasqPid; int ret =3D -1; - dnsmasqContext *dctx =3D NULL; + g_autoptr(dnsmasqContext) dctx =3D NULL; =20 /* see if there are any IP addresses that need a dhcp server */ i =3D 0; @@ -1722,9 +1694,6 @@ networkStartDhcpDaemon(virNetworkDriverStatePtr drive= r, =20 ret =3D 0; cleanup: - VIR_FREE(pidfile); - virCommandFree(cmd); - dnsmasqContextFree(dctx); return ret; } =20 @@ -1745,7 +1714,7 @@ networkRefreshDhcpDaemon(virNetworkDriverStatePtr dri= ver, size_t i; pid_t dnsmasqPid; virNetworkIPDefPtr ipdef, ipv4def, ipv6def; - dnsmasqContext *dctx =3D NULL; + g_autoptr(dnsmasqContext) dctx =3D NULL; =20 /* if no IP addresses specified, nothing to do */ if (!virNetworkDefGetIPByIndex(def, AF_UNSPEC, 0)) @@ -1797,7 +1766,6 @@ networkRefreshDhcpDaemon(virNetworkDriverStatePtr dri= ver, dnsmasqPid =3D virNetworkObjGetDnsmasqPid(obj); ret =3D kill(dnsmasqPid, SIGHUP); cleanup: - dnsmasqContextFree(dctx); return ret; } =20 @@ -1872,7 +1840,7 @@ networkRadvdConfContents(virNetworkObjPtr obj, /* add a section for each IPv6 address in the config */ for (i =3D 0; (ipdef =3D virNetworkDefGetIPByIndex(def, AF_INET6, i));= i++) { int prefix; - char *netaddr; + g_autofree char *netaddr =3D NULL; =20 prefix =3D virNetworkIPDefPrefix(ipdef); if (prefix < 0) { @@ -1889,7 +1857,6 @@ networkRadvdConfContents(virNetworkObjPtr obj, " {\n%s };\n", netaddr, prefix, dhcp6 ? radvd2 : radvd3); - VIR_FREE(netaddr); } =20 virBufferAddLit(&configbuf, "};\n"); @@ -1908,8 +1875,8 @@ networkRadvdConfWrite(virNetworkDriverStatePtr driver, { virNetworkDefPtr def =3D virNetworkObjGetDef(obj); int ret =3D -1; - char *configStr =3D NULL; - char *myConfigFile =3D NULL; + g_autofree char *configStr =3D NULL; + g_autofree char *myConfigFile =3D NULL; =20 if (!configFile) configFile =3D &myConfigFile; @@ -1937,8 +1904,6 @@ networkRadvdConfWrite(virNetworkDriverStatePtr driver, =20 ret =3D 0; cleanup: - VIR_FREE(configStr); - VIR_FREE(myConfigFile); return ret; } =20 @@ -1948,12 +1913,12 @@ networkStartRadvd(virNetworkDriverStatePtr driver, virNetworkObjPtr obj) { virNetworkDefPtr def =3D virNetworkObjGetDef(obj); - dnsmasqCapsPtr dnsmasq_caps =3D networkGetDnsmasqCaps(driver); + g_autoptr(dnsmasqCaps) dnsmasq_caps =3D networkGetDnsmasqCaps(driver); pid_t radvdPid; - char *pidfile =3D NULL; - char *radvdpidbase =3D NULL; - char *configfile =3D NULL; - virCommandPtr cmd =3D NULL; + g_autofree char *pidfile =3D NULL; + g_autofree char *radvdpidbase =3D NULL; + g_autofree char *configfile =3D NULL; + g_autoptr(virCommand) cmd =3D NULL; int ret =3D -1; =20 virNetworkObjSetRadvdPid(obj, -1); @@ -2026,11 +1991,6 @@ networkStartRadvd(virNetworkDriverStatePtr driver, =20 ret =3D 0; cleanup: - virObjectUnref(dnsmasq_caps); - virCommandFree(cmd); - VIR_FREE(configfile); - VIR_FREE(radvdpidbase); - VIR_FREE(pidfile); return ret; } =20 @@ -2040,14 +2000,13 @@ networkRefreshRadvd(virNetworkDriverStatePtr driver, virNetworkObjPtr obj) { virNetworkDefPtr def =3D virNetworkObjGetDef(obj); - dnsmasqCapsPtr dnsmasq_caps =3D networkGetDnsmasqCaps(driver); + g_autoptr(dnsmasqCaps) dnsmasq_caps =3D networkGetDnsmasqCaps(driver); g_autofree char *radvdpidbase =3D NULL; g_autofree char *pidfile =3D NULL; pid_t radvdPid; =20 /* Is dnsmasq handling RA? */ if (DNSMASQ_RA_SUPPORT(dnsmasq_caps)) { - virObjectUnref(dnsmasq_caps); if ((radvdpidbase =3D networkRadvdPidfileBasename(def->name)) && (pidfile =3D virPidFileBuildPath(driver->pidDir, radvdpidbase)= )) { /* radvd should not be running but in case it is */ @@ -2056,7 +2015,6 @@ networkRefreshRadvd(virNetworkDriverStatePtr driver, } return 0; } - virObjectUnref(dnsmasq_caps); =20 /* if there's no running radvd, just start it */ radvdPid =3D virNetworkObjGetRadvdPid(obj); @@ -2248,7 +2206,7 @@ static int networkSetIPv6Sysctls(virNetworkObjPtr obj) { virNetworkDefPtr def =3D virNetworkObjGetDef(obj); - char *field =3D NULL; + g_autofree char *field =3D NULL; int ret =3D -1; bool enableIPv6 =3D !!virNetworkDefGetIPByIndex(def, AF_INET6, 0); =20 @@ -2273,7 +2231,6 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj) "on bridge %s"), field, def->bridge); goto cleanup; } - VIR_FREE(field); =20 /* The rest of the ipv6 sysctl tunables should always be set the * same, whether or not we're using ipv6 on this bridge. @@ -2282,6 +2239,7 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj) /* Prevent guests from hijacking the host network by sending out * their own router advertisements. */ + VIR_FREE(field); field =3D g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf/%s/accept_ra", def->bridge); =20 @@ -2290,11 +2248,11 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj) _("cannot disable %s"), field); goto cleanup; } - VIR_FREE(field); =20 /* All interfaces used as a gateway (which is what this is, by * definition), must always have autoconf=3D0. */ + VIR_FREE(field); field =3D g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf/%s/autoconf", de= f->bridge); =20 if (virFileWriteStr(field, "0", 0) < 0) { @@ -2305,7 +2263,6 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj) =20 ret =3D 0; cleanup: - VIR_FREE(field); return ret; } =20 @@ -2384,7 +2341,8 @@ networkWaitDadFinish(virNetworkObjPtr obj) { virNetworkDefPtr def =3D virNetworkObjGetDef(obj); virNetworkIPDefPtr ipdef; - virSocketAddrPtr *addrs =3D NULL, addr =3D NULL; + g_autofree virSocketAddrPtr *addrs =3D NULL; + virSocketAddrPtr addr =3D NULL; size_t naddrs =3D 0; int ret =3D -1; =20 @@ -2399,7 +2357,6 @@ networkWaitDadFinish(virNetworkObjPtr obj) ret =3D (naddrs =3D=3D 0) ? 0 : virNetDevIPWaitDadFinish(addrs, naddrs= ); =20 cleanup: - VIR_FREE(addrs); VIR_DEBUG("Finished waiting for IPv6 DAD on network %s with status %d", def->name, ret); return ret; @@ -2416,9 +2373,9 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr d= river, virErrorPtr save_err =3D NULL; virNetworkIPDefPtr ipdef; virNetDevIPRoutePtr routedef; - char *macTapIfName =3D NULL; + g_autofree char *macTapIfName =3D NULL; virMacMapPtr macmap; - char *macMapFile =3D NULL; + g_autofree char *macMapFile =3D NULL; int tapfd =3D -1; bool dnsmasqStarted =3D false; bool devOnline =3D false; @@ -2465,7 +2422,6 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr d= river, VIR_NETDEV_TAP_CREATE_USE_MAC_F= OR_BRIDGE | VIR_NETDEV_TAP_CREATE_IFUP | VIR_NETDEV_TAP_CREATE_PERSIST) = < 0) { - VIR_FREE(macTapIfName); goto error; } } @@ -2581,9 +2537,6 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr d= river, if (virNetDevBandwidthSet(def->bridge, def->bandwidth, true, true) < 0) goto error; =20 - VIR_FREE(macTapIfName); - VIR_FREE(macMapFile); - return 0; =20 error: @@ -2607,10 +2560,8 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr = driver, if (macTapIfName) { VIR_FORCE_CLOSE(tapfd); ignore_value(virNetDevTapDelete(macTapIfName, NULL)); - VIR_FREE(macTapIfName); } virNetworkObjUnrefMacMap(obj); - VIR_FREE(macMapFile); =20 ignore_value(virNetDevBridgeDelete(def->bridge)); =20 @@ -2635,14 +2586,12 @@ networkShutdownNetworkVirtual(virNetworkDriverState= Ptr driver, =20 radvdPid =3D virNetworkObjGetRadvdPid(obj); if (radvdPid > 0) { - char *radvdpidbase; + g_autofree char *radvdpidbase =3D NULL; =20 kill(radvdPid, SIGTERM); /* attempt to delete the pidfile we created */ - if ((radvdpidbase =3D networkRadvdPidfileBasename(def->name))) { + if ((radvdpidbase =3D networkRadvdPidfileBasename(def->name))) virPidFileDelete(driver->pidDir, radvdpidbase); - VIR_FREE(radvdpidbase); - } } =20 dnsmasqPid =3D virNetworkObjGetDnsmasqPid(obj); @@ -2650,11 +2599,9 @@ networkShutdownNetworkVirtual(virNetworkDriverStateP= tr driver, kill(dnsmasqPid, SIGTERM); =20 if (def->mac_specified) { - char *macTapIfName =3D networkBridgeDummyNicName(def->bridge); - if (macTapIfName) { + g_autofree char *macTapIfName =3D networkBridgeDummyNicName(def->b= ridge); + if (macTapIfName) ignore_value(virNetDevTapDelete(macTapIfName, NULL)); - VIR_FREE(macTapIfName); - } } =20 ignore_value(virNetDevSetOnline(def->bridge, false)); @@ -2960,7 +2907,7 @@ networkShutdownNetwork(virNetworkDriverStatePtr drive= r, { virNetworkDefPtr def =3D virNetworkObjGetDef(obj); int ret =3D 0; - char *stateFile; + g_autofree char *stateFile =3D NULL; =20 VIR_INFO("Shutting down network '%s'", def->name); =20 @@ -2972,7 +2919,6 @@ networkShutdownNetwork(virNetworkDriverStatePtr drive= r, return -1; =20 unlink(stateFile); - VIR_FREE(stateFile); =20 switch ((virNetworkForwardType) def->forward.type) { =20 @@ -3245,7 +3191,6 @@ networkFindUnusedBridgeName(virNetworkObjListPtr nets, virNetworkDefPtr def) { int ret =3D -1, id =3D 0; - char *newname =3D NULL; const char *templ =3D "virbr%d"; const char *p; =20 @@ -3255,7 +3200,8 @@ networkFindUnusedBridgeName(virNetworkObjListPtr nets, templ =3D def->bridge; =20 do { - newname =3D g_strdup_printf(templ, id); + g_autofree char *newname =3D g_strdup_printf(templ, id); + /* check if this name is used in another libvirt network or * there is an existing device with that name. ignore errors * from virNetDevExists(), just in case it isn't implemented @@ -3264,11 +3210,10 @@ networkFindUnusedBridgeName(virNetworkObjListPtr ne= ts, if (!(virNetworkObjBridgeInUse(nets, newname, def->name) || virNetDevExists(newname) =3D=3D 1)) { VIR_FREE(def->bridge); /*could contain template */ - def->bridge =3D newname; + def->bridge =3D g_steal_pointer(&newname); ret =3D 0; goto cleanup; } - VIR_FREE(newname); } while (++id <=3D MAX_BRIDGE_ID); =20 virReportError(VIR_ERR_INTERNAL_ERROR, @@ -3276,8 +3221,6 @@ networkFindUnusedBridgeName(virNetworkObjListPtr nets, MAX_BRIDGE_ID); ret =3D 0; cleanup: - if (ret < 0) - VIR_FREE(newname); return ret; } =20 @@ -3421,7 +3364,7 @@ networkValidate(virNetworkDriverStatePtr driver, */ for (i =3D 0; i < def->forward.nifs; i++) { virNetworkForwardIfDefPtr iface =3D &def->forward.ifs[i]; - char *sysfs_path =3D NULL; + g_autofree char *sysfs_path =3D NULL; =20 switch ((virNetworkForwardHostdevDeviceType)iface->type) { case VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV: @@ -3462,10 +3405,8 @@ networkValidate(virNetworkDriverStatePtr driver, _("device '%s' in network '%s' is not " "an SR-IOV Virtual Function"), sysfs_path, def->name); - VIR_FREE(sysfs_path); return -1; } - VIR_FREE(sysfs_path); break; } =20 @@ -4141,7 +4082,8 @@ networkSetAutostart(virNetworkPtr net, virNetworkDriverStatePtr driver =3D networkGetDriver(); virNetworkObjPtr obj; virNetworkDefPtr def; - char *configFile =3D NULL, *autostartLink =3D NULL; + g_autofree char *configFile =3D NULL; + g_autofree char *autostartLink =3D NULL; bool new_autostart; bool cur_autostart; int ret =3D -1; @@ -4198,8 +4140,6 @@ networkSetAutostart(virNetworkPtr net, ret =3D 0; =20 cleanup: - VIR_FREE(configFile); - VIR_FREE(autostartLink); virNetworkObjEndAPI(&obj); return ret; } @@ -4221,14 +4161,13 @@ networkGetDHCPLeases(virNetworkPtr net, long long currtime =3D 0; long long expirytime_tmp =3D -1; bool ipv6 =3D false; - char *lease_entries =3D NULL; - char *custom_lease_file =3D NULL; + g_autofree char *lease_entries =3D NULL; + g_autofree char *custom_lease_file =3D NULL; const char *ip_tmp =3D NULL; const char *mac_tmp =3D NULL; virJSONValuePtr lease_tmp =3D NULL; - virJSONValuePtr leases_array =3D NULL; + g_autoptr(virJSONValue) leases_array =3D NULL; virNetworkIPDefPtr ipdef_tmp =3D NULL; - virNetworkDHCPLeasePtr lease =3D NULL; virNetworkDHCPLeasePtr *leases_ret =3D NULL; virNetworkObjPtr obj; virNetworkDefPtr def; @@ -4317,7 +4256,7 @@ networkGetDHCPLeases(virNetworkPtr net, continue; =20 if (need_results) { - lease =3D g_new0(virNetworkDHCPLease, 1); + g_autoptr(virNetworkDHCPLease) lease =3D g_new0(virNetworkDHCP= Lease, 1); =20 lease->expirytime =3D expirytime_tmp; =20 @@ -4365,8 +4304,6 @@ networkGetDHCPLeases(virNetworkPtr net, } else { nleases++; } - - VIR_FREE(lease); } =20 if (leases_ret) { @@ -4378,13 +4315,7 @@ networkGetDHCPLeases(virNetworkPtr net, rv =3D nleases; =20 cleanup: - VIR_FREE(lease); - VIR_FREE(lease_entries); - VIR_FREE(custom_lease_file); - virJSONValueFree(leases_array); - virNetworkObjEndAPI(&obj); - return rv; =20 error: @@ -5577,7 +5508,7 @@ networkPortSetParameters(virNetworkPortPtr port, virNetworkDefPtr def; virNetworkPortDefPtr portdef; virNetDevBandwidthPtr bandwidth =3D NULL; - char *dir =3D NULL; + g_autofree char *dir =3D NULL; int ret =3D -1; size_t i; =20 @@ -5654,7 +5585,6 @@ networkPortSetParameters(virNetworkPortPtr port, cleanup: virNetDevBandwidthFree(bandwidth); virNetworkObjEndAPI(&obj); - VIR_FREE(dir); return ret; } =20 diff --git a/src/network/bridge_driver_linux.c b/src/network/bridge_driver_= linux.c index 5fc77785dc..58df15b5cf 100644 --- a/src/network/bridge_driver_linux.c +++ b/src/network/bridge_driver_linux.c @@ -218,7 +218,8 @@ void networkPostReloadFirewallRules(bool startup G_GNUC= _UNUSED) int networkCheckRouteCollision(virNetworkDefPtr def) { int ret =3D 0, len; - char *cur, *buf =3D NULL; + char *cur; + g_autofree char *buf =3D NULL; /* allow for up to 100000 routes (each line is 128 bytes) */ enum {MAX_ROUTE_SIZE =3D 128*100000}; =20 @@ -315,14 +316,13 @@ int networkCheckRouteCollision(virNetworkDefPtr def) =20 if ((r_addr.data.inet4.sin_addr.s_addr =3D=3D addr_val) && (r_mask.data.inet4.sin_addr.s_addr =3D=3D mask_val)) { - char *addr_str =3D virSocketAddrFormat(&r_addr); + g_autofree char *addr_str =3D virSocketAddrFormat(&r_addr); if (!addr_str) virResetLastError(); virReportError(VIR_ERR_INTERNAL_ERROR, _("Route address '%s' conflicts " "with IP address for '%s'"), NULLSTR(addr_str), iface); - VIR_FREE(addr_str); ret =3D -1; goto out; } @@ -330,7 +330,6 @@ int networkCheckRouteCollision(virNetworkDefPtr def) } =20 out: - VIR_FREE(buf); return ret; } =20 diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c index 2b5fc0f442..732dd09610 100644 --- a/src/network/leaseshelper.c +++ b/src/network/leaseshelper.c @@ -82,8 +82,8 @@ VIR_ENUM_IMPL(virLeaseAction, int main(int argc, char **argv) { - char *pid_file =3D NULL; - char *custom_lease_file =3D NULL; + g_autofree char *pid_file =3D NULL; + g_autofree char *custom_lease_file =3D NULL; const char *ip =3D NULL; const char *mac =3D NULL; const char *leases_str =3D NULL; @@ -91,13 +91,13 @@ main(int argc, char **argv) const char *clientid =3D getenv("DNSMASQ_CLIENT_ID"); const char *interface =3D getenv("DNSMASQ_INTERFACE"); const char *hostname =3D getenv("DNSMASQ_SUPPLIED_HOSTNAME"); - char *server_duid =3D NULL; + g_autofree char *server_duid =3D NULL; int action =3D -1; int pid_file_fd =3D -1; int rv =3D EXIT_FAILURE; bool delete =3D false; - virJSONValuePtr lease_new =3D NULL; - virJSONValuePtr leases_array_new =3D NULL; + g_autoptr(virJSONValue) lease_new =3D NULL; + g_autoptr(virJSONValue) leases_array_new =3D NULL; =20 virSetErrorFunc(NULL, NULL); virSetErrorLogPriorityFunc(NULL); @@ -256,11 +256,5 @@ main(int argc, char **argv) if (pid_file_fd !=3D -1) virPidFileReleasePath(pid_file, pid_file_fd); =20 - VIR_FREE(pid_file); - VIR_FREE(server_duid); - VIR_FREE(custom_lease_file); - virJSONValueFree(lease_new); - virJSONValueFree(leases_array_new); - return rv; } --=20 2.25.4 From nobody Mon Nov 25 19:48:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1594156331; cv=none; d=zohomail.com; s=zohoarc; b=hXxuoz5kz7m8/aED14qwPiPejaknYwTy7zk8Yif8vr+8bAXIWtovbH6myC5X+xuT4iQwBBSdcq4xq9cCjPhiGX0LuSvH0mL97vCPc/aV2JkQLZQc9Qh+MWQ4F+fSbuZ48tYUUoVNFOz0lA5gda49BlbckptCbSjiNUkmZ6WyOwE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594156331; 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=LuOTwn5mKn8BLdKluN3IWM4kR6DDHMEBpgjS/46Cryo=; b=mVxOvcpwKH+iiMSPtf4fa2QwRGNGa63sS9RW1E5rTPr9W27v37vQg7gj5bloKZfUatLZH90j+0toZqqg66WXymwv2ki81hbUYq+bkLozaNUqPf2Gi7lyg/C2mSXGMcrZHuPXNFTDJLs2NvS3VqvaF62fDjI6Cffbec0/UDGuxXw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 15941563312337.978472714636723; Tue, 7 Jul 2020 14:12:11 -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-464-pxO0iAkIOlqUJ-h5GwPV3w-1; Tue, 07 Jul 2020 17:12:07 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F30C78015CB; Tue, 7 Jul 2020 21:12:01 +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 CDFA2797E0; Tue, 7 Jul 2020 21:12:01 +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 9DAAC1809557; Tue, 7 Jul 2020 21:12:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067L8Qs4007965 for ; Tue, 7 Jul 2020 17:08:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0A05079220; Tue, 7 Jul 2020 21:08:26 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F067797E0 for ; Tue, 7 Jul 2020 21:08:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594156329; 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=LuOTwn5mKn8BLdKluN3IWM4kR6DDHMEBpgjS/46Cryo=; b=frFnTYRrxoGcCAheYKmuKRybB3therbxCZ+wsyjabI4lIkHjSNGYRl1aDqY4vZGv6GMOto PfKe9SCDrBT6M29xdNF9tQt/S8qZF5qng1vDom5cP4vUSp7z2GdoBpYt7n906tuXPk76GD gXxiVsE8CpTL0ftjiEk7+RdYXaVn6k8= X-MC-Unique: pxO0iAkIOlqUJ-h5GwPV3w-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 06/15] network: eliminate unnecessary labels Date: Tue, 7 Jul 2020 17:08:06 -0400 Message-Id: <20200707210815.1797463-7-laine@redhat.com> In-Reply-To: <20200707210815.1797463-1-laine@redhat.com> References: <20200707210815.1797463-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.79 on 10.5.11.13 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) Content-Type: text/plain; charset="utf-8" All these cleanup/error labels were reduced to having just "return ret" by a previous patch, so get rid of them and return directly. Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/network/bridge_driver.c | 264 ++++++++++++------------------ src/network/bridge_driver_linux.c | 15 +- 2 files changed, 113 insertions(+), 166 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 31bd0dd92c..79b2ca3330 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -197,18 +197,14 @@ networkDnsmasqDefNamespaceParse(xmlXPathContextPtr ct= xt, void **data) { g_autoptr(networkDnsmasqXmlNsDef) nsdata =3D g_new0(networkDnsmasqXmlN= sDef, 1); - int ret =3D -1; =20 if (networkDnsmasqDefNamespaceParseOptions(nsdata, ctxt)) - goto cleanup; + return -1; =20 if (nsdata->noptions > 0) *data =3D g_steal_pointer(&nsdata); =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -331,22 +327,20 @@ networkRunHook(virNetworkObjPtr obj, g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_autofree char *xml =3D NULL; int hookret; - int ret =3D -1; =20 if (virHookPresent(VIR_HOOK_DRIVER_NETWORK)) { if (!obj) { VIR_DEBUG("Not running hook as @obj is NULL"); - ret =3D 0; - goto cleanup; + return 0; } def =3D virNetworkObjGetDef(obj); =20 virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); if (virNetworkDefFormatBuf(&buf, def, network_driver->xmlopt, 0) <= 0) - goto cleanup; + return -1; if (port && virNetworkPortDefFormatBuf(&buf, port) < 0) - goto cleanup; + return -1; =20 virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, ""); @@ -359,14 +353,12 @@ networkRunHook(virNetworkObjPtr obj, * If the script raised an error, pass it to the callee. */ if (hookret < 0) - goto cleanup; + return -1; =20 networkNetworkObjTaint(obj, VIR_NETWORK_TAINT_HOOK); } =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 @@ -440,34 +432,32 @@ networkRemoveInactive(virNetworkDriverStatePtr driver, g_autoptr(dnsmasqContext) dctx =3D NULL; virNetworkDefPtr def =3D virNetworkObjGetPersistentDef(obj); =20 - int ret =3D -1; - /* remove the (possibly) existing dnsmasq and radvd files */ if (!(dctx =3D dnsmasqContextNew(def->name, driver->dnsmasqStateDir))) { - goto cleanup; + return -1; } =20 if (!(leasefile =3D networkDnsmasqLeaseFileNameDefault(driver, def->na= me))) - goto cleanup; + return -1; =20 if (!(customleasefile =3D networkDnsmasqLeaseFileNameCustom(driver, de= f->bridge))) - goto cleanup; + return -1; =20 if (!(radvdconfigfile =3D networkRadvdConfigFileName(driver, def->name= ))) - goto cleanup; + return -1; =20 if (!(radvdpidbase =3D networkRadvdPidfileBasename(def->name))) - goto cleanup; + return -1; =20 if (!(configfile =3D networkDnsmasqConfigFileName(driver, def->name))) - goto cleanup; + return -1; =20 if (!(statusfile =3D virNetworkConfigFile(driver->stateDir, def->name)= )) - goto cleanup; + return -1; =20 if (!(macMapFile =3D virMacMapFileName(driver->dnsmasqStateDir, def->b= ridge))) - goto cleanup; + return -1; =20 /* dnsmasq */ dnsmasqDelete(dctx); @@ -488,10 +478,7 @@ networkRemoveInactive(virNetworkDriverStatePtr driver, /* remove the network definition */ virNetworkObjRemoveInactive(driver->networks, obj); =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -703,7 +690,6 @@ networkStateInitialize(bool privileged, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { - int ret =3D VIR_DRV_STATE_INIT_ERROR; g_autofree char *configdir =3D NULL; g_autofree char *rundir =3D NULL; bool autostart =3D true; @@ -831,13 +817,12 @@ networkStateInitialize(bool privileged, } #endif =20 - ret =3D VIR_DRV_STATE_INIT_COMPLETE; - cleanup: - return ret; + return VIR_DRV_STATE_INIT_COMPLETE; + =20 error: networkStateCleanup(); - goto cleanup; + return VIR_DRV_STATE_INIT_ERROR; } =20 =20 @@ -1074,7 +1059,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, { virNetworkDefPtr def =3D virNetworkObjGetDef(obj); g_auto(virBuffer) configbuf =3D VIR_BUFFER_INITIALIZER; - int r, ret =3D -1; + int r; int nbleases =3D 0; size_t i; virNetworkDNSDefPtr dns =3D &def->dns; @@ -1138,7 +1123,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, g_autofree char *addr =3D virSocketAddrFormat(&fwd->addr); =20 if (!addr) - goto cleanup; + return -1; virBufferAsprintf(&configbuf, "%s\n", addr); if (!fwd->domain) addNoResolv =3D true; @@ -1165,7 +1150,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, =20 if (wantDNS && networkDnsmasqConfLocalPTRs(&configbuf, def) < 0) - goto cleanup; + return -1; =20 if (wantDNS && def->dns.forwardPlainNames =3D=3D VIR_TRISTATE_BOOL_NO)= { virBufferAddLit(&configbuf, "domain-needed\n"); @@ -1215,7 +1200,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, g_autofree char *ipaddr =3D virSocketAddrFormat(&tmpipdef->add= ress); =20 if (!ipaddr) - goto cleanup; + return -1; =20 /* also part of CVE 2012-3411 - if the host's version of * dnsmasq doesn't have bind-dynamic, only allow listening on @@ -1238,7 +1223,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, "(as described in RFC1918/RFC3484/RFC4193= )."), ipaddr, (int)version / 1000000, (int)(version % 1000000) / 1000); - goto cleanup; + return -1; } virBufferAsprintf(&configbuf, "listen-address=3D%s\n", ipaddr); } @@ -1279,14 +1264,14 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, _("Missing required 'service' " "attribute in SRV record of network '%s'"= ), def->name); - goto cleanup; + return -1; } if (!dns->srvs[i].protocol) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing required 'service' " "attribute in SRV record of network '%s'"= ), def->name); - goto cleanup; + return -1; } /* RFC2782 requires that service and protocol be preceded by * an underscore. @@ -1335,7 +1320,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("For IPv4, multiple DHCP definitions " "cannot be specified.")); - goto cleanup; + return -1; } else { ipv4def =3D ipdef; } @@ -1355,13 +1340,13 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, (int)(version % 1000000) / 1000, DNSMASQ_DHCPv6_MAJOR_REQD, DNSMASQ_DHCPv6_MINOR_REQD); - goto cleanup; + return -1; } if (ipv6def) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("For IPv6, multiple DHCP definitions " "cannot be specified.")); - goto cleanup; + return -1; } else { ipv6def =3D ipdef; } @@ -1390,7 +1375,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, virReportError(VIR_ERR_INTERNAL_ERROR, _("bridge '%s' has an invalid prefix"), def->bridge); - goto cleanup; + return -1; } for (r =3D 0; r < ipdef->nranges; r++) { int thisRange; @@ -1401,7 +1386,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, =20 if (!(saddr =3D virSocketAddrFormat(&range.addr.start)) || !(eaddr =3D virSocketAddrFormat(&range.addr.end))) - goto cleanup; + return -1; =20 if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET6)) { virBufferAsprintf(&configbuf, "dhcp-range=3D%s,%s,%d", @@ -1416,11 +1401,11 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, _("Failed to translate bridge '%s' " "prefix %d to netmask"), def->bridge, prefix); - goto cleanup; + return -1; } =20 if (!(netmaskStr =3D virSocketAddrFormat(&netmask))) - goto cleanup; + return -1; virBufferAsprintf(&configbuf, "dhcp-range=3D%s,%s,%s", saddr, eaddr, netmaskStr); } @@ -1435,7 +1420,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, &ipdef->address, virNetworkIPDefPrefix(ipdef)= ); if (thisRange < 0) - goto cleanup; + return -1; nbleases +=3D thisRange; } =20 @@ -1448,7 +1433,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, if (!ipdef->nranges && ipdef->nhosts) { g_autofree char *bridgeaddr =3D virSocketAddrFormat(&ipdef->ad= dress); if (!bridgeaddr) - goto cleanup; + return -1; virBufferAsprintf(&configbuf, "dhcp-range=3D%s,static", bridgeaddr); if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET6)) @@ -1457,7 +1442,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, } =20 if (networkBuildDnsmasqDhcpHostsList(dctx, ipdef) < 0) - goto cleanup; + return -1; =20 /* Note: the following is IPv4 only */ if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET)) { @@ -1476,7 +1461,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, g_autofree char *bootserver =3D virSocketAddrFormat(&i= pdef->bootserver); =20 if (!bootserver) - goto cleanup; + return -1; virBufferAsprintf(&configbuf, "dhcp-boot=3D%s%s%s\n", ipdef->bootfile, ",,", bootserver); } else { @@ -1492,7 +1477,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, =20 /* this is done once per interface */ if (networkBuildDnsmasqHostsList(dctx, dns) < 0) - goto cleanup; + return -1; =20 /* Even if there are currently no static hosts, if we're * listening for DHCP, we should write a 0-length hosts @@ -1525,7 +1510,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, if (!(ipdef->nranges || ipdef->nhosts)) { g_autofree char *bridgeaddr =3D virSocketAddrFormat(&i= pdef->address); if (!bridgeaddr) - goto cleanup; + return -1; virBufferAsprintf(&configbuf, "dhcp-range=3D%s,ra-only\n", bridgea= ddr); } @@ -1540,15 +1525,12 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, } =20 if (!(*configstr =3D virBufferContentAndReset(&configbuf))) - goto cleanup; + return -1; =20 *hostsfilestr =3D dnsmasqDhcpHostsToString(dctx->hostsfile->hosts, dctx->hostsfile->nhosts); =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -1563,7 +1545,6 @@ networkBuildDhcpDaemonCommandLine(virNetworkDriverSta= tePtr driver, virNetworkDefPtr def =3D virNetworkObjGetDef(obj); g_autoptr(dnsmasqCaps) dnsmasq_caps =3D networkGetDnsmasqCaps(driver); g_autoptr(virCommand) cmd =3D NULL; - int ret =3D -1; g_autofree char *configfile =3D NULL; g_autofree char *configstr =3D NULL; g_autofree char *hostsfilestr =3D NULL; @@ -1573,27 +1554,27 @@ networkBuildDhcpDaemonCommandLine(virNetworkDriverS= tatePtr driver, =20 if (networkDnsmasqConfContents(obj, pidfile, &configstr, &hostsfilestr, dctx, dnsmasq_caps) < 0) - goto cleanup; + return -1; if (!configstr) - goto cleanup; + return -1; =20 /* construct the filename */ if (!(configfile =3D networkDnsmasqConfigFileName(driver, def->name))) - goto cleanup; + return -1; =20 /* Write the file */ if (virFileWriteStr(configfile, configstr, 0600) < 0) { virReportSystemError(errno, _("couldn't write dnsmasq config file '%s'"), configfile); - goto cleanup; + return -1; } =20 /* This helper is used to create custom leases file for libvirt */ if (!(leaseshelper_path =3D virFileFindResource("libvirt_leaseshelper", abs_top_builddir "/src", LIBEXECDIR))) - goto cleanup; + return -1; =20 cmd =3D virCommandNew(dnsmasqCapsGetBinaryPath(dnsmasq_caps)); virCommandAddArgFormat(cmd, "--conf-file=3D%s", configfile); @@ -1603,9 +1584,7 @@ networkBuildDhcpDaemonCommandLine(virNetworkDriverSta= tePtr driver, virCommandAddEnvPair(cmd, "VIR_BRIDGE_NAME", def->bridge); =20 *cmdout =3D g_steal_pointer(&cmd); - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 @@ -1620,7 +1599,6 @@ networkStartDhcpDaemon(virNetworkDriverStatePtr drive= r, g_autoptr(virCommand) cmd =3D NULL; g_autofree char *pidfile =3D NULL; pid_t dnsmasqPid; - int ret =3D -1; g_autoptr(dnsmasqContext) dctx =3D NULL; =20 /* see if there are any IP addresses that need a dhcp server */ @@ -1631,53 +1609,46 @@ networkStartDhcpDaemon(virNetworkDriverStatePtr dri= ver, needDnsmasq =3D true; } =20 - if (i =3D=3D 0) { - /* no IP addresses at all, so we don't need to run */ - ret =3D 0; - goto cleanup; - } + /* no IP addresses at all, so we don't need to run */ + if (i =3D=3D 0) + return 0; =20 - if (!needDnsmasq && def->dns.enable =3D=3D VIR_TRISTATE_BOOL_NO) { - /* no DHCP services needed, and user disabled DNS service */ - ret =3D 0; - goto cleanup; - } + /* no DHCP services needed, and user disabled DNS service */ + if (!needDnsmasq && def->dns.enable =3D=3D VIR_TRISTATE_BOOL_NO) + return 0; =20 if (virFileMakePath(driver->pidDir) < 0) { virReportSystemError(errno, _("cannot create directory %s"), driver->pidDir); - goto cleanup; + return -1; } =20 if (!(pidfile =3D virPidFileBuildPath(driver->pidDir, def->name))) - goto cleanup; + return -1; =20 if (virFileMakePath(driver->dnsmasqStateDir) < 0) { virReportSystemError(errno, _("cannot create directory %s"), driver->dnsmasqStateDir); - goto cleanup; + return -1; } =20 dctx =3D dnsmasqContextNew(def->name, driver->dnsmasqStateDir); if (dctx =3D=3D NULL) - goto cleanup; + return -1; =20 if (networkDnsmasqCapsRefresh(driver) < 0) - goto cleanup; + return -1; =20 - ret =3D networkBuildDhcpDaemonCommandLine(driver, obj, &cmd, pidfile, = dctx); - if (ret < 0) - goto cleanup; + if (networkBuildDhcpDaemonCommandLine(driver, obj, &cmd, pidfile, dctx= ) < 0) + return -1; =20 - ret =3D dnsmasqSave(dctx); - if (ret < 0) - goto cleanup; + if (dnsmasqSave(dctx) < 0) + return -1; =20 - ret =3D virCommandRun(cmd, NULL); - if (ret < 0) - goto cleanup; + if (virCommandRun(cmd, NULL) < 0) + return -1; =20 /* * There really is no race here - when dnsmasq daemonizes, its @@ -1687,14 +1658,12 @@ networkStartDhcpDaemon(virNetworkDriverStatePtr dri= ver, * pid */ =20 - ret =3D virPidFileRead(driver->pidDir, def->name, &dnsmasqPid); - if (ret < 0) - goto cleanup; + if (virPidFileRead(driver->pidDir, def->name, &dnsmasqPid) < 0) + return -1; + virNetworkObjSetDnsmasqPid(obj, dnsmasqPid); =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 @@ -1710,7 +1679,6 @@ networkRefreshDhcpDaemon(virNetworkDriverStatePtr dri= ver, virNetworkObjPtr obj) { virNetworkDefPtr def =3D virNetworkObjGetDef(obj); - int ret =3D -1; size_t i; pid_t dnsmasqPid; virNetworkIPDefPtr ipdef, ipv4def, ipv6def; @@ -1726,10 +1694,8 @@ networkRefreshDhcpDaemon(virNetworkDriverStatePtr dr= iver, return networkStartDhcpDaemon(driver, obj); =20 VIR_INFO("Refreshing dnsmasq for network %s", def->bridge); - if (!(dctx =3D dnsmasqContextNew(def->name, - driver->dnsmasqStateDir))) { - goto cleanup; - } + if (!(dctx =3D dnsmasqContextNew(def->name, driver->dnsmasqStateDir))) + return -1; =20 /* Look for first IPv4 address that has dhcp defined. * We only support dhcp-host config on one IPv4 subnetwork @@ -1752,21 +1718,20 @@ networkRefreshDhcpDaemon(virNetworkDriverStatePtr d= river, } =20 if (ipv4def && (networkBuildDnsmasqDhcpHostsList(dctx, ipv4def) < 0)) - goto cleanup; + return -1; =20 if (ipv6def && (networkBuildDnsmasqDhcpHostsList(dctx, ipv6def) < 0)) - goto cleanup; + return -1; =20 if (networkBuildDnsmasqHostsList(dctx, &def->dns) < 0) - goto cleanup; + return -1; =20 - if ((ret =3D dnsmasqSave(dctx)) < 0) - goto cleanup; + if (dnsmasqSave(dctx) < 0) + return -1; =20 dnsmasqPid =3D virNetworkObjGetDnsmasqPid(obj); - ret =3D kill(dnsmasqPid, SIGHUP); - cleanup: - return ret; + return kill(dnsmasqPid, SIGHUP); + } =20 =20 @@ -1874,7 +1839,6 @@ networkRadvdConfWrite(virNetworkDriverStatePtr driver, char **configFile) { virNetworkDefPtr def =3D virNetworkObjGetDef(obj); - int ret =3D -1; g_autofree char *configStr =3D NULL; g_autofree char *myConfigFile =3D NULL; =20 @@ -1884,27 +1848,24 @@ networkRadvdConfWrite(virNetworkDriverStatePtr driv= er, *configFile =3D NULL; =20 if (networkRadvdConfContents(obj, &configStr) < 0) - goto cleanup; + return -1; =20 - if (!configStr) { - ret =3D 0; - goto cleanup; - } + if (!configStr) + return 0; =20 /* construct the filename */ if (!(*configFile =3D networkRadvdConfigFileName(driver, def->name))) - goto cleanup; + return -1; + /* write the file */ if (virFileWriteStr(*configFile, configStr, 0600) < 0) { virReportSystemError(errno, _("couldn't write radvd config file '%s'"), *configFile); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 @@ -1919,20 +1880,16 @@ networkStartRadvd(virNetworkDriverStatePtr driver, g_autofree char *radvdpidbase =3D NULL; g_autofree char *configfile =3D NULL; g_autoptr(virCommand) cmd =3D NULL; - int ret =3D -1; =20 virNetworkObjSetRadvdPid(obj, -1); =20 /* Is dnsmasq handling RA? */ - if (DNSMASQ_RA_SUPPORT(dnsmasq_caps)) { - ret =3D 0; - goto cleanup; - } + if (DNSMASQ_RA_SUPPORT(dnsmasq_caps)) + return 0; =20 if (!virNetworkDefGetIPByIndex(def, AF_INET6, 0)) { /* no IPv6 addresses, so we don't need to run radvd */ - ret =3D 0; - goto cleanup; + return 0; } =20 if (!virFileIsExecutable(RADVD)) { @@ -1940,30 +1897,32 @@ networkStartRadvd(virNetworkDriverStatePtr driver, _("Cannot find %s - " "Possibly the package isn't installed"), RADVD); - goto cleanup; + return -1; } =20 if (virFileMakePath(driver->pidDir) < 0) { virReportSystemError(errno, _("cannot create directory %s"), driver->pidDir); - goto cleanup; + return -1; } + if (virFileMakePath(driver->radvdStateDir) < 0) { virReportSystemError(errno, _("cannot create directory %s"), driver->radvdStateDir); - goto cleanup; + return -1; } =20 /* construct pidfile name */ if (!(radvdpidbase =3D networkRadvdPidfileBasename(def->name))) - goto cleanup; + return -1; + if (!(pidfile =3D virPidFileBuildPath(driver->pidDir, radvdpidbase))) - goto cleanup; + return -1; =20 if (networkRadvdConfWrite(driver, obj, &configfile) < 0) - goto cleanup; + return -1; =20 /* prevent radvd from daemonizing itself with "--debug 1", and use * a dummy pidfile name - virCommand will create the pidfile we @@ -1983,15 +1942,13 @@ networkStartRadvd(virNetworkDriverStatePtr driver, virCommandDaemonize(cmd); =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 if (virPidFileRead(driver->pidDir, radvdpidbase, &radvdPid) < 0) - goto cleanup; - virNetworkObjSetRadvdPid(obj, radvdPid); + return -1; =20 - ret =3D 0; - cleanup: - return ret; + virNetworkObjSetRadvdPid(obj, radvdPid); + return 0; } =20 =20 @@ -2207,7 +2164,6 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj) { virNetworkDefPtr def =3D virNetworkObjGetDef(obj); g_autofree char *field =3D NULL; - int ret =3D -1; bool enableIPv6 =3D !!virNetworkDefGetIPByIndex(def, AF_INET6, 0); =20 /* set disable_ipv6 if there are no ipv6 addresses defined for the @@ -2221,15 +2177,14 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj) if (!enableIPv6) VIR_DEBUG("ipv6 appears to already be disabled on %s", def->bridge); - ret =3D 0; - goto cleanup; + return 0; } =20 if (virFileWriteStr(field, enableIPv6 ? "0" : "1", 0) < 0) { virReportSystemError(errno, _("cannot write to %s to enable/disable IPv6 " "on bridge %s"), field, def->bridge); - goto cleanup; + return -1; } =20 /* The rest of the ipv6 sysctl tunables should always be set the @@ -2246,7 +2201,7 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj) if (virFileWriteStr(field, "0", 0) < 0) { virReportSystemError(errno, _("cannot disable %s"), field); - goto cleanup; + return -1; } =20 /* All interfaces used as a gateway (which is what this is, by @@ -2258,12 +2213,10 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj) if (virFileWriteStr(field, "0", 0) < 0) { virReportSystemError(errno, _("cannot disable %s"), field); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 @@ -3190,7 +3143,7 @@ static int networkFindUnusedBridgeName(virNetworkObjListPtr nets, virNetworkDefPtr def) { - int ret =3D -1, id =3D 0; + int id =3D 0; const char *templ =3D "virbr%d"; const char *p; =20 @@ -3211,17 +3164,14 @@ networkFindUnusedBridgeName(virNetworkObjListPtr ne= ts, virNetDevExists(newname) =3D=3D 1)) { VIR_FREE(def->bridge); /*could contain template */ def->bridge =3D g_steal_pointer(&newname); - ret =3D 0; - goto cleanup; + return 0; } } while (++id <=3D MAX_BRIDGE_ID); =20 virReportError(VIR_ERR_INTERNAL_ERROR, _("Bridge generation exceeded max id %d"), MAX_BRIDGE_ID); - ret =3D 0; - cleanup: - return ret; + return -1; } =20 =20 diff --git a/src/network/bridge_driver_linux.c b/src/network/bridge_driver_= linux.c index 58df15b5cf..7f765bcf99 100644 --- a/src/network/bridge_driver_linux.c +++ b/src/network/bridge_driver_linux.c @@ -217,7 +217,7 @@ void networkPostReloadFirewallRules(bool startup G_GNUC= _UNUSED) */ int networkCheckRouteCollision(virNetworkDefPtr def) { - int ret =3D 0, len; + int len; char *cur; g_autofree char *buf =3D NULL; /* allow for up to 100000 routes (each line is 128 bytes) */ @@ -225,7 +225,7 @@ int networkCheckRouteCollision(virNetworkDefPtr def) =20 /* Read whole routing table into memory */ if ((len =3D virFileReadAll(PROC_NET_ROUTE, MAX_ROUTE_SIZE, &buf)) < 0) - goto out; + return 0; =20 /* Dropping the last character shouldn't hurt */ if (len > 0) @@ -234,7 +234,7 @@ int networkCheckRouteCollision(virNetworkDefPtr def) VIR_DEBUG("%s output:\n%s", PROC_NET_ROUTE, buf); =20 if (!STRPREFIX(buf, "Iface")) - goto out; + return 0; =20 /* First line is just headings, skip it */ cur =3D strchr(buf, '\n'); @@ -296,8 +296,7 @@ int networkCheckRouteCollision(virNetworkDefPtr def) virReportError(VIR_ERR_INTERNAL_ERROR, _("Network is already in use by interface %= s"), iface); - ret =3D -1; - goto out; + return -1; } } =20 @@ -323,14 +322,12 @@ int networkCheckRouteCollision(virNetworkDefPtr def) _("Route address '%s' conflicts " "with IP address for '%s'"), NULLSTR(addr_str), iface); - ret =3D -1; - goto out; + return -1; } } } =20 - out: - return ret; + return 0; } =20 static const char networkLocalMulticastIPv4[] =3D "224.0.0.0/24"; --=20 2.25.4 From nobody Mon Nov 25 19:48:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1594156570; cv=none; d=zohomail.com; s=zohoarc; b=nZHihtYrb7sWr733WAU4Y35lTlxfap21v7mvgP9Dst98bNSpkaR9dVG0tuV6yEv10+20BCVAK5O5eg0z1VJOKrVj1qm4Z3f8gGm5g/K3Z6pPMpkjREOqO/fMF2XqnfvLN/oe8R6vrNmo483aVH47Bd06s5lPBEfHQ/s49gFCT8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594156570; 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=3uaB9vSrSoYEevjwFWBu2r9liSzb4qpRXtjKQPm5cT0=; b=V+h+B/5brOgCld4bGaKq8svEM/Wg0wjVZNdEErkuHvJXeGWJkKmgPnaztyGHAtE8PJfhaESODDtjlWkYtYKc+dtqKWYz5a+rzgyYyYhlxkX98PGCIn3s/6+XI/s6xbB/1k4GOhzD2syMoKrMtNlKEDCCQxDi3c/wtrmSSsP07Bc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1594156570762895.5959366733067; Tue, 7 Jul 2020 14:16:10 -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-402-VXe-F0vqOv6GvhLVhJp1Nw-1; Tue, 07 Jul 2020 17:15:01 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 35477107ACCA; Tue, 7 Jul 2020 21:14:55 +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 13F9379248; Tue, 7 Jul 2020 21:14:55 +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 D633772F6B; Tue, 7 Jul 2020 21:14:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067L8Q7a007976 for ; Tue, 7 Jul 2020 17:08:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7FBE8797E0; Tue, 7 Jul 2020 21:08:26 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38DD579220 for ; Tue, 7 Jul 2020 21:08:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594156569; 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=3uaB9vSrSoYEevjwFWBu2r9liSzb4qpRXtjKQPm5cT0=; b=cnz7Rd3ZJ2981pWWy24+WJbpLvKw8X+gyjUzUsc3TQ6loYMhufNOb5UA2paIW9jTD3c6++ E1kgBnJZstxhrqREh4YghBlo1ZBoryd1oaQdCGDbT/hTl2T/Hi/cypcAZpAgqBCTZ5XhEe mtdnQuKF/Lu8Hb8PRovsbyG7ZZaFXOQ= X-MC-Unique: VXe-F0vqOv6GvhLVhJp1Nw-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 07/15] network: use g_free() in place of remaining VIR_FREE() Date: Tue, 7 Jul 2020 17:08:07 -0400 Message-Id: <20200707210815.1797463-8-laine@redhat.com> In-Reply-To: <20200707210815.1797463-1-laine@redhat.com> References: <20200707210815.1797463-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.79 on 10.5.11.13 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/network/bridge_driver.c | 45 +++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 79b2ca3330..7d81d4dd78 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -158,7 +158,7 @@ networkDnsmasqDefNamespaceFree(void *nsdata) =20 virStringListFreeCount(def->options, def->noptions); =20 - VIR_FREE(def); + g_free(def); } G_DEFINE_AUTOPTR_CLEANUP_FUNC(networkDnsmasqXmlNsDef, networkDnsmasqDefNam= espaceFree); =20 @@ -707,7 +707,7 @@ networkStateInitialize(bool privileged, =20 network_driver->lockFD =3D -1; if (virMutexInit(&network_driver->lock) < 0) { - VIR_FREE(network_driver); + g_clear_pointer(&network_driver, g_free); goto error; } =20 @@ -875,18 +875,18 @@ networkStateCleanup(void) virPidFileRelease(network_driver->stateDir, "driver", network_driver->lockFD); =20 - VIR_FREE(network_driver->networkConfigDir); - VIR_FREE(network_driver->networkAutostartDir); - VIR_FREE(network_driver->stateDir); - VIR_FREE(network_driver->pidDir); - VIR_FREE(network_driver->dnsmasqStateDir); - VIR_FREE(network_driver->radvdStateDir); + g_free(network_driver->networkConfigDir); + g_free(network_driver->networkAutostartDir); + g_free(network_driver->stateDir); + g_free(network_driver->pidDir); + g_free(network_driver->dnsmasqStateDir); + g_free(network_driver->radvdStateDir); =20 virObjectUnref(network_driver->dnsmasqCaps); =20 virMutexDestroy(&network_driver->lock); =20 - VIR_FREE(network_driver); + g_clear_pointer(&network_driver, g_free); =20 return 0; } @@ -2194,7 +2194,7 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj) /* Prevent guests from hijacking the host network by sending out * their own router advertisements. */ - VIR_FREE(field); + g_free(field); field =3D g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf/%s/accept_ra", def->bridge); =20 @@ -2207,7 +2207,7 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj) /* All interfaces used as a gateway (which is what this is, by * definition), must always have autoconf=3D0. */ - VIR_FREE(field); + g_free(field); field =3D g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf/%s/autoconf", de= f->bridge); =20 if (virFileWriteStr(field, "0", 0) < 0) { @@ -2714,19 +2714,19 @@ networkCreateInterfacePool(virNetworkDefPtr netdef) for (i =3D 0; i < netdef->forward.nifs; i++) { if (netdef->forward.ifs[i].type =3D=3D VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV) - VIR_FREE(netdef->forward.ifs[i].device.dev); + g_free(netdef->forward.ifs[i].device.dev); } netdef->forward.nifs =3D 0; } if (netdef->forward.nifs =3D=3D 0) - VIR_FREE(netdef->forward.ifs); + g_clear_pointer(&netdef->forward.ifs, g_free); =20 for (i =3D 0; i < numVirtFns; i++) { - VIR_FREE(vfNames[i]); - VIR_FREE(virtFns[i]); + g_free(vfNames[i]); + g_free(virtFns[i]); } - VIR_FREE(vfNames); - VIR_FREE(virtFns); + g_free(vfNames); + g_free(virtFns); return ret; } =20 @@ -3162,7 +3162,7 @@ networkFindUnusedBridgeName(virNetworkObjListPtr nets, */ if (!(virNetworkObjBridgeInUse(nets, newname, def->name) || virNetDevExists(newname) =3D=3D 1)) { - VIR_FREE(def->bridge); /*could contain template */ + g_free(def->bridge); /*could contain template */ def->bridge =3D g_steal_pointer(&newname); return 0; } @@ -4272,7 +4272,7 @@ networkGetDHCPLeases(virNetworkPtr net, if (leases_ret) { for (i =3D 0; i < nleases; i++) virNetworkDHCPLeaseFree(leases_ret[i]); - VIR_FREE(leases_ret); + g_free(leases_ret); } goto cleanup; } @@ -4396,7 +4396,7 @@ networkAllocatePort(virNetworkObjPtr obj, return -1; } if (portprofile) { - VIR_FREE(port->virtPortProfile); + g_free(port->virtPortProfile); port->virtPortProfile =3D portprofile; } =20 @@ -5513,9 +5513,10 @@ networkPortSetParameters(virNetworkPortPtr port, * So if no average or floor is given, we free inbound/outbound * here which causes inbound/outbound to not be set. */ if (!bandwidth->in->average && !bandwidth->in->floor) - VIR_FREE(bandwidth->in); + g_clear_pointer(&bandwidth->in, g_free); + if (!bandwidth->out->average) - VIR_FREE(bandwidth->out); + g_clear_pointer(&bandwidth->out, g_free); =20 if (networkUpdatePortBandwidth(obj, &portdef->mac, --=20 2.25.4 From nobody Mon Nov 25 19:48:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1594156389; cv=none; d=zohomail.com; s=zohoarc; b=IO63MzMz4uB/VeVC8D4OQlhMH8C8VQxfbZry1OIIThwYglgtFYfAY1NCVMhatQg4jEdfUxQ04Trhkjm42D4wMSslcTIBWagdSocS9h0qOqx8N3fYD1yYaQdxwIw8VcV5xBaymw/6/q5oDFV3493BTQlatcn86oOUiRnBGxJkF9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594156389; 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=1MfuAcG7gLx2vgfXqwNNsm4Xt/FMPCRqkXNKSa89JCk=; b=DlEGra2cocv0PdF8/TWnx4cTOSzw9dE/tnM+jVYSVPfU9nABJawek30thdKh8zdW5Mmun5IKcqtCrLn5WGQXe7bM8D+PRsGxlWJdg9NWzCKe6p4wxno5kU6JdDNQ7j+B1MqP7Hm8VI0KmQcBM4U7SQg17xDuftkjbQg/c8kpPpQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1594156389385551.6535531534926; Tue, 7 Jul 2020 14:13:09 -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-181-sfdmL6ChMmeHA5L--lzE7g-1; Tue, 07 Jul 2020 17:12:10 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7D4A6107ACF2; Tue, 7 Jul 2020 21:12:04 +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 5DB625D9DC; Tue, 7 Jul 2020 21:12:04 +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 2F8AA72F77; Tue, 7 Jul 2020 21:12:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067L8Rnk007987 for ; Tue, 7 Jul 2020 17:08:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id F3E2E797E0; Tue, 7 Jul 2020 21:08:26 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD39479220 for ; Tue, 7 Jul 2020 21:08:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594156388; 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=1MfuAcG7gLx2vgfXqwNNsm4Xt/FMPCRqkXNKSa89JCk=; b=Ct5y7ZJ7FV/FK324WD4GBgHekjgQUKXZ7TtGeF2aIFCN9rDJ7Zm7Xdlf7uSnI214iUwkR4 GNcC1/+JYqHC8akH+vdV21wlcznumHkCkr9vDdTGlL+jCZF6CAHVGeRGh8FLqgyKPM/crb 2rqXGIlb3in0Ly6/SDtBui6P3MpngGg= X-MC-Unique: sfdmL6ChMmeHA5L--lzE7g-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 08/15] nwfilter: remove unnecessary code from ebtablesGetSubChainInsts() Date: Tue, 7 Jul 2020 17:08:08 -0400 Message-Id: <20200707210815.1797463-9-laine@redhat.com> In-Reply-To: <20200707210815.1797463-1-laine@redhat.com> References: <20200707210815.1797463-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.79 on 10.5.11.14 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) Content-Type: text/plain; charset="utf-8" On failure, this function would clear out and free the list of subchains it had been called with. This is unnecessary, because the *only* caller of this function will also clear out and free the list of subchains if it gets a failure from ebtablesGetSubChainInsts(). (It also makes more logical sense for the function that is creating the entire list to be the one freeing the entire list, rather than having a function whose purpose is only to create *one item* on the list freeing the entire list). Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/nwfilter/nwfilter_ebiptables_driver.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfil= ter_ebiptables_driver.c index 78a52408b2..426212e0dc 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -3328,12 +3328,6 @@ ebtablesGetSubChainInsts(virHashTablePtr chains, =20 cleanup: VIR_FREE(filter_names); - if (ret < 0) { - for (i =3D 0; i < *ninsts; i++) - VIR_FREE(*insts[i]); - VIR_FREE(*insts); - *ninsts =3D 0; - } return ret; =20 } --=20 2.25.4 From nobody Mon Nov 25 19:48:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1594156441; cv=none; d=zohomail.com; s=zohoarc; b=lFBDtjkoxkcerSJqVyjAT2RXfoXlvJuYr0zuYDUN/E/LxeZgpG4OArC6CkTdURGlcVvwiCixdjSXddAOK+POh3Tbmp1NottvXZP6TkL5FqdGCCfgUFHNDanv4sU/y9HusnnMk2Y+4z2sGlhtyehMDvrNvilXHHW2jj6z+/JtjT0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594156441; 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=jppcayGG2ARd0LCc2Z/wBUhFK/+AFFCmol+eQQV4M50=; b=kJqS92qpspWmNFb64xpfBc3Uk4cxEiFUm/0tbdy8fw7RyDRqOYf6HqSjHbOisOl0PY6UtKb4IWa3fHQNtkFK9i2AnfOGBqGwzmIy/YtTlgHKJG8FJAX9TL9OCtjoR3nAHQNoSgKrCriJFkAMsAUcGjLhKp6BWF4BC8dyHzbz3WE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1594156440997288.7150271484827; Tue, 7 Jul 2020 14:14:00 -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-88-oEuRUYq2Pr6A9rMNVmpxAA-1; Tue, 07 Jul 2020 17:13:57 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B695780058A; Tue, 7 Jul 2020 21:13:51 +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 98B6C79220; Tue, 7 Jul 2020 21:13:51 +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 6A80472F77; Tue, 7 Jul 2020 21:13:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067L8RF8008000 for ; Tue, 7 Jul 2020 17:08:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 763E179220; Tue, 7 Jul 2020 21:08:27 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F307797E9 for ; Tue, 7 Jul 2020 21:08:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594156439; 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=jppcayGG2ARd0LCc2Z/wBUhFK/+AFFCmol+eQQV4M50=; b=E32YV/LGCpMV7KqCjeT+GGNLJjYK1CJ4Tx5NtdWvvAivgs5UBTJIfYGjgkFX6oViV4DBcf AjEjcusvvrfXjrWS7JtDmzaeWYx/ikxVhCtYdol10QWfZCeUjukj1hDQrjtOU0pBrZ73jf H8AYn42OPnkf6P0fF5nXe+q3q8mYtbA= X-MC-Unique: oEuRUYq2Pr6A9rMNVmpxAA-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 09/15] nwfilter: clear nrules when resetting virNWFilterInst Date: Tue, 7 Jul 2020 17:08:09 -0400 Message-Id: <20200707210815.1797463-10-laine@redhat.com> In-Reply-To: <20200707210815.1797463-1-laine@redhat.com> References: <20200707210815.1797463-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.79 on 10.5.11.13 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) Content-Type: text/plain; charset="utf-8" It's possible/probable the callers to virNWFilterInstReset() make it unnecessary to set the object's nrules to 0 after freeing all its rules, but that same function is setting nfilters to 0, so let's do the same for the sake of consistency. Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/nwfilter/nwfilter_gentech_driver.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index b7633eb10a..aff42cbfb0 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -240,6 +240,7 @@ virNWFilterInstReset(virNWFilterInstPtr inst) for (i =3D 0; i < inst->nrules; i++) virNWFilterRuleInstFree(inst->rules[i]); VIR_FREE(inst->rules); + inst->nrules =3D 0; } =20 =20 --=20 2.25.4 From nobody Mon Nov 25 19:48:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1594156445; cv=none; d=zohomail.com; s=zohoarc; b=J+9F9AxosHjk9rg+6eqTzIlyKKCX+5IW8/WlWhjXP923TMqR9SGfAsjXaxDixFsWSqKdQsDOwgDkxVr8bXr56L8d8uYPcRIvHjCcyizQVGMhgmyiYVYXeur4eVMAitutB7DK0PkatzOOCrVYIm+aVR8Y9yCK8Jszdhl04nxpj7I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594156445; 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=cN1IqZ6Sn5BnhSiGfDdqh4Y1/gHKDfoNGCuAPFCF5OU=; b=l7/MlfbuTcv7hfS2wZZwlQEqbrqqFXy1nQH6i4gcriwO/Ph7dxVzZKs8YqflrIRUFG2ffvZndrmV+RcL30uc5Hx1An+kFY9k8a/EaQuiXWaECoFmkxxr+6m55wQbYUbdP3txSTVGgls86prz2UdvnYUb+LH2YMlUtFTfREQbrSE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1594156445800890.3948389498447; Tue, 7 Jul 2020 14:14:05 -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-379-cAGyQ2fzP16E3pSqJOTi8Q-1; Tue, 07 Jul 2020 17:14:02 -0400 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 2142BEC1A0; Tue, 7 Jul 2020 21:13:54 +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 EF6A81A921; Tue, 7 Jul 2020 21:13:53 +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 BFC8B1809547; Tue, 7 Jul 2020 21:13:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067L8RUt008009 for ; Tue, 7 Jul 2020 17:08:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id ED866797E0; Tue, 7 Jul 2020 21:08:27 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id A441C79220 for ; Tue, 7 Jul 2020 21:08:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594156444; 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=cN1IqZ6Sn5BnhSiGfDdqh4Y1/gHKDfoNGCuAPFCF5OU=; b=Y2Fccdats9x4mdOwx1q3tpXFaH1K83DhCpGWIqq7dNjLqIBbrpnKqI0ZTM0EzMCBRm3lHW Kt2Ih408OYNnjfCOYgsFxttulAT0XDm5bb8747or46d0Acx1bX84hsYoYNO9rDye0jgMxB 4fK7QuFVVHo/ps1i6zqEs4uCChjl2aQ= X-MC-Unique: cAGyQ2fzP16E3pSqJOTi8Q-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 10/15] nwfilter: define a typedef for struct ebtablesSubChainInst Date: Tue, 7 Jul 2020 17:08:10 -0400 Message-Id: <20200707210815.1797463-11-laine@redhat.com> In-Reply-To: <20200707210815.1797463-1-laine@redhat.com> References: <20200707210815.1797463-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/nwfilter/nwfilter_ebiptables_driver.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfil= ter_ebiptables_driver.c index 426212e0dc..cc0f3f93d9 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -3269,7 +3269,9 @@ ebtablesRuleInstCommand(virFirewallPtr fw, return ret; } =20 -struct ebtablesSubChainInst { +typedef struct _ebtablesSubChainInst ebtablesSubChainInst; +typedef ebtablesSubChainInst *ebtablesSubChainInstPtr; +struct _ebtablesSubChainInst { virNWFilterChainPriority priority; bool incoming; enum l3_proto_idx protoidx; @@ -3280,8 +3282,8 @@ struct ebtablesSubChainInst { static int ebtablesSubChainInstSort(const void *a, const void *b) { - const struct ebtablesSubChainInst **insta =3D (const struct ebtablesSu= bChainInst **)a; - const struct ebtablesSubChainInst **instb =3D (const struct ebtablesSu= bChainInst **)b; + const ebtablesSubChainInst **insta =3D (const ebtablesSubChainInst **)= a; + const ebtablesSubChainInst **instb =3D (const ebtablesSubChainInst **)= b; =20 /* priorities are limited to range [-1000, 1000] */ return (*insta)->priority - (*instb)->priority; @@ -3291,7 +3293,7 @@ ebtablesSubChainInstSort(const void *a, const void *b) static int ebtablesGetSubChainInsts(virHashTablePtr chains, bool incoming, - struct ebtablesSubChainInst ***insts, + ebtablesSubChainInstPtr **insts, size_t *ninsts) { virHashKeyValuePairPtr filter_names; @@ -3304,7 +3306,7 @@ ebtablesGetSubChainInsts(virHashTablePtr chains, return -1; =20 for (i =3D 0; filter_names[i].key; i++) { - struct ebtablesSubChainInst *inst; + ebtablesSubChainInstPtr inst; enum l3_proto_idx idx =3D ebtablesGetProtoIdxByFiltername( filter_names[i].key); =20 @@ -3344,7 +3346,7 @@ ebiptablesApplyNewRules(const char *ifname, bool haveEbtables =3D false; bool haveIptables =3D false; bool haveIp6tables =3D false; - struct ebtablesSubChainInst **subchains =3D NULL; + ebtablesSubChainInstPtr *subchains =3D NULL; size_t nsubchains =3D 0; int ret =3D -1; =20 --=20 2.25.4 From nobody Mon Nov 25 19:48:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1594156447; cv=none; d=zohomail.com; s=zohoarc; b=AGau1Gd7n1HibLBvlkeHLj+gY4KBKmEhvwcQa5iP1mRGO2QtA6bfkMLhjx2aczpZeh+KtBKQQ6pald/T9QI8Kh4PMxKh53QXCbur04Bcx1j4jgZdl4mkjdneHOpHQgzOZFHYuWyOIicIEHqNY1XVl03aIbG6QzxVc7950NQ7yio= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594156447; 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=MHLbBvUyrxE+t0ibPIjbtBT8bMqrxucpD1T9ev/Pom4=; b=fqP6rS6j1F5lsaOfldDfsqp+ptAp4nWROO+orHoKpz1JAOTq63f7BvwshNiagY2Yc98H6YXX4CgN/erEYej2Ra4x4CJS8or19zsylAClcEa5VKpZ3o3vkfLtd4IBjYmSwC94tiFFaX6ctyEyye9VRfO0UBbg6nulGLtQ/zXKnkU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1594156447142979.9913597971417; Tue, 7 Jul 2020 14:14:07 -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-455-VAZ3-hr2NSq_q6xCr9AJ6Q-1; Tue, 07 Jul 2020 17:14:02 -0400 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 6A3FF1009613; Tue, 7 Jul 2020 21:13:56 +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 437681A921; Tue, 7 Jul 2020 21:13:56 +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 147671809557; Tue, 7 Jul 2020 21:13:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067L8SnT008017 for ; Tue, 7 Jul 2020 17:08:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6E87A797E0; Tue, 7 Jul 2020 21:08:28 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26C3E79220 for ; Tue, 7 Jul 2020 21:08:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594156445; 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=MHLbBvUyrxE+t0ibPIjbtBT8bMqrxucpD1T9ev/Pom4=; b=IKGE9UsttvekPGdYMkm9Vie/UfV188bqo6xknl7/hlA1IZNY0DKhp3BSXeLCxd6KgFrHpP 5RH4m/faJRcHglsiSlQ4mmEHG51fOIHNACJ7yv74Juve/kQfz3fGfPAMWpSpwsaxogU3wz YEM88k4zSRhZHqAg1l77QrlJlydgJrU= X-MC-Unique: VAZ3-hr2NSq_q6xCr9AJ6Q-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 11/15] nwfilter: transform logic in virNWFilterRuleInstSort to eliminate label Date: Tue, 7 Jul 2020 17:08:11 -0400 Message-Id: <20200707210815.1797463-12-laine@redhat.com> In-Reply-To: <20200707210815.1797463-1-laine@redhat.com> References: <20200707210815.1797463-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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) Content-Type: text/plain; charset="utf-8" This rewrite of a nested conditional produces the same results, but eliminate a goto and corresponding label. Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/nwfilter/nwfilter_ebiptables_driver.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfil= ter_ebiptables_driver.c index cc0f3f93d9..94eaac927a 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -3113,13 +3113,12 @@ virNWFilterRuleInstSort(const void *a, const void *= b) /* ensure root chain commands appear before all others since we will need them to create the child chains */ if (root_a) { - if (root_b) - goto normal; - return -1; /* a before b */ - } - if (root_b) + if (!root_b) + return -1; /* a before b */ + } else if (root_b) { return 1; /* b before a */ - normal: + } + /* priorities are limited to range [-1000, 1000] */ return insta->priority - instb->priority; } --=20 2.25.4 From nobody Mon Nov 25 19:48:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1594156507; cv=none; d=zohomail.com; s=zohoarc; b=cPqx7zChgs6IpWnHm/OXXVIuqs7KRX4ThnAGRcyo7BDxnCx2i/5mqo46sxEmasxwqFU5RABFvtUE5oE5sZOrS3h5PTbrUdrIdczKKcS77POqAOwEJ9OZNINHt3e50c9Zx5zerhjHEd5sWzfbMu4wHqQuQdd1BsjJC3gt+bCJ4hY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594156507; 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=B53q1TwZXfXS+QBeQuNnw1rlSoknyYusGolxu8JnKCI=; b=g4foKBQGYWk46LkgOBBsZW23pb+ZQHBtU1C+ffhI+z12n+ZOzmvEZQCgDRMf1JXH7ufehxLx4qbBOjpP+v+tNTXQVoTMUXSU4OFSXWO3ynZ3a7qSw7U1DG1kn0pLI0rm+h+MuzPqyXDDwrHpSttwl7XBdidcYyljck0qZpJgDlY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1594156507624914.0270657950582; Tue, 7 Jul 2020 14:15:07 -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-444-Z0JTvsNmPIyYk8LeMyUMmA-1; Tue, 07 Jul 2020 17:15:03 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6CF81107ACF7; Tue, 7 Jul 2020 21:14:57 +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 4E1F77846E; Tue, 7 Jul 2020 21:14:57 +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 1F3C51806B0A; Tue, 7 Jul 2020 21:14:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067L8Swo008022 for ; Tue, 7 Jul 2020 17:08:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id E5C13797E0; Tue, 7 Jul 2020 21:08:28 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CEF579220 for ; Tue, 7 Jul 2020 21:08:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594156506; 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=B53q1TwZXfXS+QBeQuNnw1rlSoknyYusGolxu8JnKCI=; b=eDzbtdszqqjdwW+PpIL1WX3CK4RzU7QNYU5XtFj5ldc3N24n1FbzUCEPbHFS6dalqJICdh /TO7/jv+x6hKyJpyn2IgMgwpWwvyPn26FJ8N4i5tu1RH4S8HHkuea9HpM3x2RS+oYC0o9b vFd9xJOdErAXLeM+C4XBbgncpfHhKz4= X-MC-Unique: Z0JTvsNmPIyYk8LeMyUMmA-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 12/15] nwfilter: use standard label names when reasonable Date: Tue, 7 Jul 2020 17:08:12 -0400 Message-Id: <20200707210815.1797463-13-laine@redhat.com> In-Reply-To: <20200707210815.1797463-1-laine@redhat.com> References: <20200707210815.1797463-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.79 on 10.5.11.11 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) Content-Type: text/plain; charset="utf-8" Rather than having labels named exit, done, exit_snooprequnlock, skip_rename, etc, use the standard "cleanup" label. And instead of err_exit, malformed, tear_down_tmpebchains, use "error". Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/nwfilter/nwfilter_dhcpsnoop.c | 36 +++++++++++------------ src/nwfilter/nwfilter_ebiptables_driver.c | 12 ++++---- src/nwfilter/nwfilter_gentech_driver.c | 32 ++++++++++---------- src/nwfilter/nwfilter_learnipaddr.c | 24 +++++++-------- 4 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.c index f530341872..6de41ff209 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -456,11 +456,11 @@ virNWFilterSnoopIPLeaseInstallRule(virNWFilterSnoopIP= LeasePtr ipl, virNWFilterSnoopReqLock(req); =20 if (virNWFilterIPAddrMapAddIPAddr(req->binding->portdevname, ipaddr) <= 0) - goto exit_snooprequnlock; + goto cleanup; =20 if (!instantiate) { rc =3D 0; - goto exit_snooprequnlock; + goto cleanup; } =20 /* instantiate the filters */ @@ -471,7 +471,7 @@ virNWFilterSnoopIPLeaseInstallRule(virNWFilterSnoopIPLe= asePtr ipl, req->ifindex); } =20 - exit_snooprequnlock: + cleanup: virNWFilterSnoopReqUnlock(req); =20 VIR_FREE(ipaddr); @@ -732,7 +732,7 @@ virNWFilterSnoopReqLeaseAdd(virNWFilterSnoopReqPtr req, =20 virNWFilterSnoopReqUnlock(req); =20 - goto exit; + goto cleanup; } =20 virNWFilterSnoopReqUnlock(req); @@ -757,7 +757,7 @@ virNWFilterSnoopReqLeaseAdd(virNWFilterSnoopReqPtr req, =20 g_atomic_int_add(&virNWFilterSnoopState.nLeases, 1); =20 - exit: + cleanup: if (update_leasefile) virNWFilterSnoopLeaseFileSave(pl); =20 @@ -902,7 +902,7 @@ virNWFilterSnoopDHCPGetOpt(virNWFilterSnoopDHCPHdrPtr p= d, int len, switch (pd->d_opts[oind]) { case DHCPO_LEASE: if (olen - oind < 6) - goto malformed; + goto error; if (*pleasetime) return -1; /* duplicate lease time */ memcpy(&nwint, (char *)pd->d_opts + oind + 2, sizeof(nwint)); @@ -910,7 +910,7 @@ virNWFilterSnoopDHCPGetOpt(virNWFilterSnoopDHCPHdrPtr p= d, int len, break; case DHCPO_MTYPE: if (olen - oind < 3) - goto malformed; + goto error; if (*pmtype) return -1; /* duplicate message type */ *pmtype =3D pd->d_opts[oind + 2]; @@ -922,12 +922,12 @@ virNWFilterSnoopDHCPGetOpt(virNWFilterSnoopDHCPHdrPtr= pd, int len, return 0; default: if (olen - oind < 2) - goto malformed; + goto error; } oind +=3D pd->d_opts[oind + 1] + 2; } return 0; - malformed: + error: VIR_WARN("got lost in the options!"); return -1; } @@ -1386,7 +1386,7 @@ virNWFilterDHCPSnoopThread(void *req0) virNWFilterSnoopReqUnlock(req); =20 if (req->threadStatus !=3D THREAD_STATUS_OK) - goto exit; + goto cleanup; =20 while (!error) { if (virNWFilterSnoopAdjustPoll(pcapConf, @@ -1414,7 +1414,7 @@ virNWFilterDHCPSnoopThread(void *req0) */ if (!virNWFilterSnoopIsActive(threadkey) || req->jobCompletionStatus !=3D 0) - goto exit; + goto cleanup; =20 for (i =3D 0; n > 0 && i < G_N_ELEMENTS(fds); i++) { if (!fds[i].revents) @@ -1531,7 +1531,7 @@ virNWFilterDHCPSnoopThread(void *req0) virNWFilterSnoopReqUnlock(req); virNWFilterSnoopUnlock(); =20 - exit: + cleanup: virThreadPoolFree(worker); =20 virNWFilterSnoopReqPut(req); @@ -1774,14 +1774,14 @@ virNWFilterSnoopLeaseFileSave(virNWFilterSnoopIPLea= sePtr ipl) virNWFilterSnoopLeaseFileOpen(); if (virNWFilterSnoopLeaseFileWrite(virNWFilterSnoopState.leaseFD, req->ifkey, ipl) < 0) - goto err_exit; + goto error; =20 /* keep dead leases at < ~95% of file size */ if (g_atomic_int_add(&virNWFilterSnoopState.wLeases, 1) >=3D g_atomic_int_get(&virNWFilterSnoopState.nLeases) * 20) virNWFilterSnoopLeaseFileLoad(); /* load & refresh lease file */ =20 - err_exit: + error: virNWFilterSnoopUnlock(); } =20 @@ -1876,7 +1876,7 @@ virNWFilterSnoopLeaseFileRefresh(void) if (VIR_CLOSE(tfd) < 0) { virReportSystemError(errno, _("unable to close %s"), TMPLEASEFILE); /* assuming the old lease file is still better, skip the renaming = */ - goto skip_rename; + goto cleanup; } =20 if (rename(TMPLEASEFILE, LEASEFILE) < 0) { @@ -1886,7 +1886,7 @@ virNWFilterSnoopLeaseFileRefresh(void) } g_atomic_int_set(&virNWFilterSnoopState.wLeases, 0); =20 - skip_rename: + cleanup: virNWFilterSnoopLeaseFileOpen(); } =20 @@ -2051,14 +2051,14 @@ virNWFilterDHCPSnoopInit(void) if (!virNWFilterSnoopState.ifnameToKey || !virNWFilterSnoopState.snoopReqs || !virNWFilterSnoopState.active) - goto err_exit; + goto error; =20 virNWFilterSnoopLeaseFileLoad(); virNWFilterSnoopLeaseFileOpen(); =20 return 0; =20 - err_exit: + error: virHashFree(virNWFilterSnoopState.ifnameToKey); virNWFilterSnoopState.ifnameToKey =3D NULL; =20 diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfil= ter_ebiptables_driver.c index 94eaac927a..8ac3a7271e 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -2893,11 +2893,11 @@ ebtablesApplyBasicRules(const char *ifname, ebtablesRenameTmpRootChainFW(fw, true, ifname); =20 if (virFirewallApply(fw) < 0) - goto tear_down_tmpebchains; + goto error; =20 return 0; =20 - tear_down_tmpebchains: + error: ebtablesCleanAll(ifname); return -1; } @@ -3009,11 +3009,11 @@ ebtablesApplyDHCPOnlyRules(const char *ifname, } =20 if (virFirewallApply(fw) < 0) - goto tear_down_tmpebchains; + goto error; =20 return 0; =20 - tear_down_tmpebchains: + error: ebtablesCleanAll(ifname); return -1; } @@ -3060,11 +3060,11 @@ ebtablesApplyDropAllRules(const char *ifname) ebtablesRenameTmpRootChainFW(fw, false, ifname); =20 if (virFirewallApply(fw) < 0) - goto tear_down_tmpebchains; + goto error; =20 return 0; =20 - tear_down_tmpebchains: + error: ebtablesCleanAll(ifname); return -1; } diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index aff42cbfb0..400d064724 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -204,14 +204,14 @@ virNWFilterCreateVarsFrom(virHashTablePtr vars1, return NULL; =20 if (virNWFilterHashTablePutAll(vars1, res) < 0) - goto err_exit; + goto error; =20 if (virNWFilterHashTablePutAll(vars2, res) < 0) - goto err_exit; + goto error; =20 return res; =20 - err_exit: + error: virHashFree(res); return NULL; } @@ -527,7 +527,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, =20 if (!missing_vars) { rc =3D -1; - goto err_exit; + goto error; } =20 rc =3D virNWFilterDetermineMissingVarsRec(filter, @@ -536,7 +536,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, useNewFilter, driver); if (rc < 0) - goto err_exit; + goto error; =20 lv =3D virHashLookup(binding->filterparams, NWFILTER_VARNAME_CTRL_IP_L= EARNING); if (lv) @@ -558,7 +558,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, rc =3D virNWFilterDHCPSnoopReq(techdriver, binding, driver); - goto err_exit; + goto error; } else if (STRCASEEQ(learning, "any")) { if (!virNWFilterHasLearnReq(ifindex)) { rc =3D virNWFilterLearnIPAddress(techdriver, @@ -567,14 +567,14 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr tec= hdriver, driver, DETECT_DHCP|DETECT_STAT= IC); } - goto err_exit; + goto error; } else { rc =3D -1; virReportError(VIR_ERR_PARSE_FAILED, _("filter '%s' " "learning value '%s' invalid."), filter->name, learning); - goto err_exit; + goto error; } } else { goto err_unresolvable_vars; @@ -583,7 +583,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, goto err_unresolvable_vars; } else if (!forceWithPendingReq && virNWFilterHasLearnReq(ifindex)) { - goto err_exit; + goto error; } =20 rc =3D virNWFilterDefToInst(driver, @@ -593,7 +593,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, &inst); =20 if (rc < 0) - goto err_exit; + goto error; =20 switch (useNewFilter) { case INSTANTIATE_FOLLOW_NEWFILTER: @@ -606,7 +606,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, =20 if (instantiate) { if (virNWFilterLockIface(binding->portdevname) < 0) - goto err_exit; + goto error; =20 rc =3D techdriver->applyNewRules(binding->portdevname, inst.rules,= inst.nrules); =20 @@ -623,7 +623,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, virNWFilterUnlockIface(binding->portdevname); } =20 - err_exit: + error: virNWFilterInstReset(&inst); virHashFree(missing_vars); =20 @@ -640,7 +640,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, } =20 rc =3D -1; - goto err_exit; + goto error; } =20 =20 @@ -707,14 +707,14 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverS= tatePtr driver, if (virNWFilterVarHashmapAddStdValue(binding->filterparams, NWFILTER_STD_VAR_MAC, vmmacaddr) < 0) - goto err_exit; + goto error; =20 ipaddr =3D virNWFilterIPAddrMapGetIPAddr(binding->portdevname); if (ipaddr && virNWFilterVarHashmapAddStdValue(binding->filterparams, NWFILTER_STD_VAR_IP, virNWFilterVarValueGetSimple(ipad= dr)) < 0) - goto err_exit; + goto error; =20 =20 filter =3D virNWFilterObjGetDef(obj); @@ -737,7 +737,7 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverSta= tePtr driver, teardownOld, driver, forceWithPendingReq); =20 - err_exit: + error: virNWFilterObjUnlock(obj); =20 return rc; diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index 14c66cff35..95e21050b4 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -152,13 +152,13 @@ virNWFilterLockIface(const char *ifname) ifaceLock =3D virHashLookup(ifaceLockMap, ifname); if (!ifaceLock) { if (VIR_ALLOC(ifaceLock) < 0) - goto err_exit; + goto error; =20 if (virMutexInitRecursive(&ifaceLock->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("mutex initialization failed")); VIR_FREE(ifaceLock); - goto err_exit; + goto error; } =20 if (virStrcpyStatic(ifaceLock->ifname, ifname) < 0) { @@ -167,12 +167,12 @@ virNWFilterLockIface(const char *ifname) "buffer "), ifaceLock->ifname); VIR_FREE(ifaceLock); - goto err_exit; + goto error; } =20 while (virHashAddEntry(ifaceLockMap, ifname, ifaceLock)) { VIR_FREE(ifaceLock); - goto err_exit; + goto error; } =20 ifaceLock->refctr =3D 0; @@ -186,7 +186,7 @@ virNWFilterLockIface(const char *ifname) =20 return 0; =20 - err_exit: + error: virMutexUnlock(&ifaceMapLock); =20 return -1; @@ -414,7 +414,7 @@ learnIPAddressThread(void *arg) if (virNetDevValidateConfig(req->binding->portdevname, NULL, req->ifin= dex) <=3D 0) { virResetLastError(); req->status =3D ENODEV; - goto done; + goto cleanup; } =20 handle =3D pcap_open_live(listen_if, BUFSIZ, 0, PKT_TIMEOUT_MS, errbuf= ); @@ -422,7 +422,7 @@ learnIPAddressThread(void *arg) if (handle =3D=3D NULL) { VIR_DEBUG("Couldn't open device %s: %s", listen_if, errbuf); req->status =3D ENODEV; - goto done; + goto cleanup; } =20 fds[0].fd =3D pcap_fileno(handle); @@ -436,7 +436,7 @@ learnIPAddressThread(void *arg) NULL, false) < 0) { VIR_DEBUG("Unable to apply DHCP only rules"); req->status =3D EINVAL; - goto done; + goto cleanup; } virBufferAddLit(&buf, "src port 67 and dst port 68"); } else { @@ -444,7 +444,7 @@ learnIPAddressThread(void *arg) &req->binding->mac) < 0) { VIR_DEBUG("Unable to apply basic rules"); req->status =3D EINVAL; - goto done; + goto cleanup; } virBufferAsprintf(&buf, "ether host %s or ether dst ff:ff:ff:ff:ff= :ff", macaddr); @@ -455,14 +455,14 @@ learnIPAddressThread(void *arg) if (pcap_compile(handle, &fp, filter, 1, 0) !=3D 0) { VIR_DEBUG("Couldn't compile filter '%s'", filter); req->status =3D EINVAL; - goto done; + goto cleanup; } =20 if (pcap_setfilter(handle, &fp) !=3D 0) { VIR_DEBUG("Couldn't set filter '%s'", filter); req->status =3D EINVAL; pcap_freecode(&fp); - goto done; + goto cleanup; } =20 pcap_freecode(&fp); @@ -622,7 +622,7 @@ learnIPAddressThread(void *arg) } } /* while */ =20 - done: + cleanup: VIR_FREE(filter); =20 if (handle) --=20 2.25.4 From nobody Mon Nov 25 19:48:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1594156509; cv=none; d=zohomail.com; s=zohoarc; b=cxkzjhgwZZbUesAIFIvNrS9owXVWN/iDutVEcSYaW9bvmrkelCIRl5o+B7EK+W8ik9GzkmqEjagOgZZI0ME0yXsju6zESiwM42FCpXLCOe73PYALPCyOyUI+5Ak9/se8hFeoGUqNIBkH/x8MPk2K89Jsi/nfT4q+GWCYKk5fkFg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594156509; 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=VoiVqym9ZryzJ0VI9blXwKAdYfddgD6y5vMFK/JKXUo=; b=lXl5bjT0bGnf2iWXyxRm2Az4kQskPC0TD2eIy8Sce57vf4tAB2QbOGLTA1Ac1N7orzTfQqA2tEQYNRNWMrScmU6nukZsSFXJKeDLPzBksrZhtg3J8YO14OmjPxGw2h7jzv6JKcxuaIyTFIv6yUJeYpk/ljVaz5OH6vvv6aGrrYk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1594156509072787.4341861414757; Tue, 7 Jul 2020 14:15:09 -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-381--ZKSNuqYP1u7deCYWVHhJg-1; Tue, 07 Jul 2020 17:15:05 -0400 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 BAACF107ACF4; Tue, 7 Jul 2020 21:14:59 +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 997231A7D8; Tue, 7 Jul 2020 21:14:59 +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 69C3172F76; Tue, 7 Jul 2020 21:14:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067L8TCB008027 for ; Tue, 7 Jul 2020 17:08:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 67224797E0; Tue, 7 Jul 2020 21:08:29 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FC8D79220 for ; Tue, 7 Jul 2020 21:08:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594156507; 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=VoiVqym9ZryzJ0VI9blXwKAdYfddgD6y5vMFK/JKXUo=; b=RriEFMek3KXAC7qvkVYuvRvCh9c8JDL4PF3BsapzrvWP40pKtBgF/MAr0X9DgyYa2/PuuC b/G60yhlCIfrdk83X3ZARoLtf9iydEgMC0VrK8UxWOc5xSlDp4BgShgNsne+xF3uI4dwO8 G8zvrm47brAMkUSLWAKak9x5GVgP8h0= X-MC-Unique: -ZKSNuqYP1u7deCYWVHhJg-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 13/15] nwfilter: replace VIR_ALLOC with g_new0 Date: Tue, 7 Jul 2020 17:08:13 -0400 Message-Id: <20200707210815.1797463-14-laine@redhat.com> In-Reply-To: <20200707210815.1797463-1-laine@redhat.com> References: <20200707210815.1797463-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/nwfilter/nwfilter_dhcpsnoop.c | 9 +++------ src/nwfilter/nwfilter_driver.c | 3 +-- src/nwfilter/nwfilter_ebiptables_driver.c | 3 +-- src/nwfilter/nwfilter_gentech_driver.c | 3 +-- src/nwfilter/nwfilter_learnipaddr.c | 6 ++---- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.c index 6de41ff209..4bc1607694 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -562,8 +562,7 @@ virNWFilterSnoopReqNew(const char *ifkey) return NULL; } =20 - if (VIR_ALLOC(req) < 0) - return NULL; + req =3D g_new0(virNWFilterSnoopReq, 1); =20 req->threadStatus =3D THREAD_STATUS_NONE; =20 @@ -737,8 +736,7 @@ virNWFilterSnoopReqLeaseAdd(virNWFilterSnoopReqPtr req, =20 virNWFilterSnoopReqUnlock(req); =20 - if (VIR_ALLOC(pl) < 0) - return -1; + pl =3D g_new0(virNWFilterSnoopIPLease, 1); *pl =3D *plnew; =20 /* protect req->threadkey */ @@ -1160,8 +1158,7 @@ virNWFilterSnoopDHCPDecodeJobSubmit(virThreadPoolPtr = pool, if (len <=3D MIN_VALID_DHCP_PKT_SIZE || len > sizeof(job->packet)) return 0; =20 - if (VIR_ALLOC(job) < 0) - return -1; + job =3D g_new0(virNWFilterDHCPDecodeJob, 1); =20 memcpy(job->packet, pep, len); job->caplen =3D len; diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index 1c407727db..39d0a2128e 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -193,8 +193,7 @@ nwfilterStateInitialize(bool privileged, !(sysbus =3D virDBusGetSystemBus())) return VIR_DRV_STATE_INIT_ERROR; =20 - if (VIR_ALLOC(driver) < 0) - return VIR_DRV_STATE_INIT_ERROR; + driver =3D g_new0(virNWFilterDriverState, 1); =20 driver->lockFD =3D -1; if (virMutexInit(&driver->lock) < 0) diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfil= ter_ebiptables_driver.c index 8ac3a7271e..177e7e62b9 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -3312,8 +3312,7 @@ ebtablesGetSubChainInsts(virHashTablePtr chains, if ((int)idx < 0) continue; =20 - if (VIR_ALLOC(inst) < 0) - goto cleanup; + inst =3D g_new0(ebtablesSubChainInst, 1); inst->priority =3D *(const virNWFilterChainPriority *)filter_names= [i].value; inst->incoming =3D incoming; inst->protoidx =3D idx; diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index 400d064724..acd5614987 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -262,8 +262,7 @@ virNWFilterRuleDefToRuleInst(virNWFilterDefPtr def, virNWFilterRuleInstPtr ruleinst; int ret =3D -1; =20 - if (VIR_ALLOC(ruleinst) < 0) - goto cleanup; + ruleinst =3D g_new0(virNWFilterRuleInst, 1); =20 ruleinst->chainSuffix =3D def->chainsuffix; ruleinst->chainPriority =3D def->chainPriority; diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index 95e21050b4..63fac37132 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -151,8 +151,7 @@ virNWFilterLockIface(const char *ifname) =20 ifaceLock =3D virHashLookup(ifaceLockMap, ifname); if (!ifaceLock) { - if (VIR_ALLOC(ifaceLock) < 0) - goto error; + ifaceLock =3D g_new0(virNWFilterIfaceLock, 1); =20 if (virMutexInitRecursive(&ifaceLock->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -718,8 +717,7 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr tech= driver, return -1; } =20 - if (VIR_ALLOC(req) < 0) - return -1; + req =3D g_new0(virNWFilterIPAddrLearnReq, 1); =20 if (!(req->binding =3D virNWFilterBindingDefCopy(binding))) goto err_free_req; --=20 2.25.4 From nobody Mon Nov 25 19:48:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1594156452; cv=none; d=zohomail.com; s=zohoarc; b=HZr9ddH+MTYr9UT7Xl6jByFxw+EB+jtpI8w7eGRUZyV1V6SxvlO9Qxq7n4vlKcqLhrMCpShvHrWpKrAM5j9bg5MbXnhk5LHFbExLVPVycrKammmNHGIPEFGbpG5GRabZ4og+d7iD/6YnetneO8f+w+lRR9+O6pK/aXIrZ614VLw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594156452; 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=N/ecSF1oyze5ISbX8XQOYNQeYlghvk6kp8h4zoaKdZI=; b=TNFvV8tZugSMln/wbyr1sXS8F04iuPC6ooJzdGuRHP/yZcFdzRObvyYWfckY6xTap5VvIQkH8SfPUDH7LQUPr+0Te7yR/S8JDa3w8GWlowueys7EUcN5nSeq60fW9AFUAfLh8U2Hzp1nIUjt84is+vyOaI0dj0J1zLKQnIdmj5U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1594156452857395.4187077068881; Tue, 7 Jul 2020 14:14:12 -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-260-ffdf8jFVNJij5Y-glbGIqg-1; Tue, 07 Jul 2020 17:14:04 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A2A9C80058A; Tue, 7 Jul 2020 21:13:58 +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 82ED35D9F3; Tue, 7 Jul 2020 21:13:58 +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 539F072F79; Tue, 7 Jul 2020 21:13:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067L8T6B008032 for ; Tue, 7 Jul 2020 17:08:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id E02EF79220; Tue, 7 Jul 2020 21:08:29 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9683B797E9 for ; Tue, 7 Jul 2020 21:08:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594156451; 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=N/ecSF1oyze5ISbX8XQOYNQeYlghvk6kp8h4zoaKdZI=; b=Z7X+MKC/uRkiI62g6926dhYG7dryALX/LIrq4KJ9XUWOsfUaleeNrGCATz8Ggx57kmtEWk vYBCzPKPIcZJlHFGPrksHi3yPkiTwOZAA/HO35ZKImAtaqfnOD9uIqwGJfkPs8YaZHyu7x y8utHLd44N8SnVKXVbk21+m5ZUXE6wk= X-MC-Unique: ffdf8jFVNJij5Y-glbGIqg-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 14/15] nwfilter: convert local pointers to use g_auto* Date: Tue, 7 Jul 2020 17:08:14 -0400 Message-Id: <20200707210815.1797463-15-laine@redhat.com> In-Reply-To: <20200707210815.1797463-1-laine@redhat.com> References: <20200707210815.1797463-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.79 on 10.5.11.14 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/nwfilter/nwfilter_dhcpsnoop.c | 91 +++++++---------------- src/nwfilter/nwfilter_ebiptables_driver.c | 75 +++++++------------ src/nwfilter/nwfilter_gentech_driver.c | 15 ++-- src/nwfilter/nwfilter_learnipaddr.c | 7 +- 4 files changed, 61 insertions(+), 127 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.c index 4bc1607694..64671af135 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -292,18 +292,17 @@ static const unsigned char dhcp_magic[4] =3D { 99, 13= 0, 83, 99 }; static char * virNWFilterSnoopActivate(virNWFilterSnoopReqPtr req) { - char *key; - - key =3D g_strdup_printf("%p-%d", req, req->ifindex); + g_autofree char *key =3D g_strdup_printf("%p-%d", req, req->ifindex); + char *ret =3D NULL; =20 virNWFilterSnoopActiveLock(); =20 - if (virHashAddEntry(virNWFilterSnoopState.active, key, (void *)0x1) < = 0) - VIR_FREE(key); + if (virHashAddEntry(virNWFilterSnoopState.active, key, (void *)0x1) = =3D=3D 0) + ret =3D g_steal_pointer(&key); =20 virNWFilterSnoopActiveUnlock(); =20 - return key; + return ret; } =20 static void @@ -442,11 +441,10 @@ static int virNWFilterSnoopIPLeaseInstallRule(virNWFilterSnoopIPLeasePtr ipl, bool instantiate) { - char *ipaddr; + g_autofree char *ipaddr =3D virSocketAddrFormat(&ipl->ipAddress); int rc =3D -1; virNWFilterSnoopReqPtr req; =20 - ipaddr =3D virSocketAddrFormat(&ipl->ipAddress); if (!ipaddr) return -1; =20 @@ -473,9 +471,6 @@ virNWFilterSnoopIPLeaseInstallRule(virNWFilterSnoopIPLe= asePtr ipl, =20 cleanup: virNWFilterSnoopReqUnlock(req); - - VIR_FREE(ipaddr); - return rc; } =20 @@ -551,7 +546,7 @@ virNWFilterSnoopReqGet(virNWFilterSnoopReqPtr req) static virNWFilterSnoopReqPtr virNWFilterSnoopReqNew(const char *ifkey) { - virNWFilterSnoopReqPtr req; + g_autofree virNWFilterSnoopReqPtr req =3D g_new0(virNWFilterSnoopReq, = 1); =20 if (ifkey =3D=3D NULL || strlen(ifkey) !=3D VIR_IFKEY_LEN - 1) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -562,28 +557,20 @@ virNWFilterSnoopReqNew(const char *ifkey) return NULL; } =20 - req =3D g_new0(virNWFilterSnoopReq, 1); - req->threadStatus =3D THREAD_STATUS_NONE; =20 - if (virStrcpyStatic(req->ifkey, ifkey) < 0|| - virMutexInitRecursive(&req->lock) < 0) - goto err_free_req; + if (virStrcpyStatic(req->ifkey, ifkey) < 0 || + virMutexInitRecursive(&req->lock) < 0) { + return NULL; + } =20 - if (virCondInit(&req->threadStatusCond) < 0) - goto err_destroy_mutex; + if (virCondInit(&req->threadStatusCond) < 0) { + virMutexDestroy(&req->lock); + return NULL; + } =20 virNWFilterSnoopReqGet(req); - - return req; - - err_destroy_mutex: - virMutexDestroy(&req->lock); - - err_free_req: - VIR_FREE(req); - - return NULL; + return g_steal_pointer(&req); } =20 /* @@ -815,7 +802,7 @@ virNWFilterSnoopReqLeaseDel(virNWFilterSnoopReqPtr req, { int ret =3D 0; virNWFilterSnoopIPLeasePtr ipl; - char *ipstr =3D NULL; + g_autofree char *ipstr =3D NULL; =20 /* protect req->start, req->ifname and the lease */ virNWFilterSnoopReqLock(req); @@ -868,8 +855,6 @@ virNWFilterSnoopReqLeaseDel(virNWFilterSnoopReqPtr req, ignore_value(!!g_atomic_int_dec_and_test(&virNWFilterSnoopState.nLease= s)); =20 lease_not_found: - VIR_FREE(ipstr); - virNWFilterSnoopReqUnlock(req); =20 return ret; @@ -1045,7 +1030,7 @@ virNWFilterSnoopDHCPOpen(const char *ifname, virMacAd= dr *mac, pcap_t *handle =3D NULL; struct bpf_program fp; char pcap_errbuf[PCAP_ERRBUF_SIZE]; - char *ext_filter =3D NULL; + g_autofree char *ext_filter =3D NULL; char macaddr[VIR_MAC_STRING_BUFLEN]; =20 virMacAddrFormat(mac, macaddr); @@ -1075,7 +1060,7 @@ virNWFilterSnoopDHCPOpen(const char *ifname, virMacAd= dr *mac, if (handle =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("pcap_create failed")); - goto cleanup_nohandle; + return NULL; } =20 if (pcap_set_snaplen(handle, PCAP_PBUFSIZE) < 0 || @@ -1107,17 +1092,12 @@ virNWFilterSnoopDHCPOpen(const char *ifname, virMac= Addr *mac, } =20 pcap_freecode(&fp); - VIR_FREE(ext_filter); - return handle; =20 cleanup_freecode: pcap_freecode(&fp); cleanup: pcap_close(handle); - cleanup_nohandle: - VIR_FREE(ext_filter); - return NULL; } =20 @@ -1128,7 +1108,7 @@ virNWFilterSnoopDHCPOpen(const char *ifname, virMacAd= dr *mac, static void virNWFilterDHCPDecodeWorker(void *jobdata, void *opaque) { virNWFilterSnoopReqPtr req =3D opaque; - virNWFilterDHCPDecodeJobPtr job =3D jobdata; + g_autofree virNWFilterDHCPDecodeJobPtr job =3D jobdata; virNWFilterSnoopEthHdrPtr packet =3D (virNWFilterSnoopEthHdrPtr)job->p= acket; =20 if (virNWFilterSnoopDHCPDecode(req, packet, @@ -1140,7 +1120,6 @@ static void virNWFilterDHCPDecodeWorker(void *jobdata= , void *opaque) "interface '%s'"), req->binding->portdevname); } ignore_value(!!g_atomic_int_dec_and_test(job->qCtr)); - VIR_FREE(job); } =20 /* @@ -1307,7 +1286,7 @@ virNWFilterDHCPSnoopThread(void *req0) int errcount =3D 0; int tmp =3D -1, rv, n, pollTo; size_t i; - char *threadkey =3D NULL; + g_autofree char *threadkey =3D NULL; virThreadPoolPtr worker =3D NULL; time_t last_displayed =3D 0, last_displayed_queue =3D 0; virNWFilterSnoopPcapConf pcapConf[] =3D { @@ -1533,8 +1512,6 @@ virNWFilterDHCPSnoopThread(void *req0) =20 virNWFilterSnoopReqPut(req); =20 - VIR_FREE(threadkey); - for (i =3D 0; i < G_N_ELEMENTS(pcapConf); i++) { if (pcapConf[i].handle) pcap_close(pcapConf[i].handle); @@ -1721,18 +1698,13 @@ static int virNWFilterSnoopLeaseFileWrite(int lfd, const char *ifkey, virNWFilterSnoopIPLeasePtr ipl) { - char *lbuf =3D NULL; - char *ipstr, *dhcpstr; + g_autofree char *lbuf =3D NULL; + g_autofree char *ipstr =3D virSocketAddrFormat(&ipl->ipAddress); + g_autofree char *dhcpstr =3D virSocketAddrFormat(&ipl->ipServer); int len; - int ret =3D 0; =20 - ipstr =3D virSocketAddrFormat(&ipl->ipAddress); - dhcpstr =3D virSocketAddrFormat(&ipl->ipServer); - - if (!dhcpstr || !ipstr) { - ret =3D -1; - goto cleanup; - } + if (!dhcpstr || !ipstr) + return -1; =20 /* time intf ip dhcpserver */ lbuf =3D g_strdup_printf("%u %s %s %s\n", ipl->timeout, ifkey, ipstr, = dhcpstr); @@ -1740,18 +1712,11 @@ virNWFilterSnoopLeaseFileWrite(int lfd, const char = *ifkey, =20 if (safewrite(lfd, lbuf, len) !=3D len) { virReportSystemError(errno, "%s", _("lease file write failed")); - ret =3D -1; - goto cleanup; + return -1; } =20 ignore_value(g_fsync(lfd)); - - cleanup: - VIR_FREE(lbuf); - VIR_FREE(dhcpstr); - VIR_FREE(ipstr); - - return ret; + return 0; } =20 /* diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfil= ter_ebiptables_driver.c index 177e7e62b9..9c9d63f14b 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -188,10 +188,10 @@ _printDataType(virNWFilterVarCombIterPtr vars, bool asHex, bool directionIn) { bool done; - char *data; + g_autofree char *data =3D NULL; uint8_t ctr; g_auto(virBuffer) vb =3D VIR_BUFFER_INITIALIZER; - char *flags; + g_autofree char *flags =3D NULL; =20 if (printVar(vars, buf, bufsize, item, &done) < 0) return -1; @@ -207,10 +207,8 @@ _printDataType(virNWFilterVarCombIterPtr vars, if (g_snprintf(buf, bufsize, "%s", data) >=3D bufsize) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("buffer too small for IP address")); - VIR_FREE(data); return -1; } - VIR_FREE(data); break; =20 case DATATYPE_IPV6ADDR: @@ -221,10 +219,8 @@ _printDataType(virNWFilterVarCombIterPtr vars, if (g_snprintf(buf, bufsize, "%s", data) >=3D bufsize) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("buffer too small for IPv6 address")); - VIR_FREE(data); return -1; } - VIR_FREE(data); break; =20 case DATATYPE_MACADDR: @@ -308,10 +304,8 @@ _printDataType(virNWFilterVarCombIterPtr vars, if (virStrcpy(buf, flags, bufsize) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Buffer too small for IPSETFLAGS type")); - VIR_FREE(flags); return -1; } - VIR_FREE(flags); break; =20 case DATATYPE_STRING: @@ -1187,19 +1181,19 @@ _iptablesCreateRuleInstance(virFirewallPtr fw, return -1; =20 if (HAS_ENTRY_ITEM(&rule->p.tcpHdrFilter.dataTCPFlags)) { - char *flags; + g_autofree char *mask =3D NULL; + g_autofree char *flags =3D NULL; if (ENTRY_WANT_NEG_SIGN(&rule->p.tcpHdrFilter.dataTCPFlags)) virFirewallRuleAddArg(fw, fwrule, "!"); virFirewallRuleAddArg(fw, fwrule, "--tcp-flags"); =20 - if (!(flags =3D virNWFilterPrintTCPFlags(rule->p.tcpHdrFilter.= dataTCPFlags.u.tcpFlags.mask))) + if (!(mask =3D virNWFilterPrintTCPFlags(rule->p.tcpHdrFilter.d= ataTCPFlags.u.tcpFlags.mask))) return -1; - virFirewallRuleAddArg(fw, fwrule, flags); - VIR_FREE(flags); + virFirewallRuleAddArg(fw, fwrule, mask); + if (!(flags =3D virNWFilterPrintTCPFlags(rule->p.tcpHdrFilter.= dataTCPFlags.u.tcpFlags.flags))) return -1; virFirewallRuleAddArg(fw, fwrule, flags); - VIR_FREE(flags); } =20 if (iptablesHandlePortData(fw, fwrule, @@ -1548,7 +1542,9 @@ iptablesCreateRuleInstanceStateCtrl(virFirewallPtr fw, bool directionIn =3D false; char chainPrefix[2]; bool maySkipICMP, inout =3D false; - char *matchState =3D NULL; + g_autofree char *matchState1 =3D NULL; + g_autofree char *matchState2 =3D NULL; + g_autofree char *matchState3 =3D NULL; bool create; =20 if ((rule->tt =3D=3D VIR_NWFILTER_RULE_DIRECTION_IN) || @@ -1562,7 +1558,6 @@ iptablesCreateRuleInstanceStateCtrl(virFirewallPtr fw, maySkipICMP =3D directionIn || inout; =20 create =3D true; - matchState =3D NULL; =20 if (directionIn && !inout) { if ((rule->flags & IPTABLES_STATE_FLAGS)) @@ -1570,7 +1565,7 @@ iptablesCreateRuleInstanceStateCtrl(virFirewallPtr fw, } =20 if (create && (rule->flags & IPTABLES_STATE_FLAGS)) { - if (printStateMatchFlags(rule->flags, &matchState) < 0) + if (printStateMatchFlags(rule->flags, &matchState1) < 0) return -1; } =20 @@ -1583,11 +1578,10 @@ iptablesCreateRuleInstanceStateCtrl(virFirewallPtr = fw, rule, ifname, vars, - matchState, false, + matchState1, false, "RETURN", maySkipICMP); =20 - VIR_FREE(matchState); if (rc < 0) return rc; } @@ -1601,7 +1595,7 @@ iptablesCreateRuleInstanceStateCtrl(virFirewallPtr fw, } =20 if (create && (rule->flags & IPTABLES_STATE_FLAGS)) { - if (printStateMatchFlags(rule->flags, &matchState) < 0) + if (printStateMatchFlags(rule->flags, &matchState2) < 0) return -1; } =20 @@ -1614,12 +1608,9 @@ iptablesCreateRuleInstanceStateCtrl(virFirewallPtr f= w, rule, ifname, vars, - matchState, false, + matchState2, false, "ACCEPT", maySkipICMP); - - VIR_FREE(matchState); - if (rc < 0) return rc; } @@ -1633,7 +1624,7 @@ iptablesCreateRuleInstanceStateCtrl(virFirewallPtr fw, create =3D false; } else { if ((rule->flags & IPTABLES_STATE_FLAGS)) { - if (printStateMatchFlags(rule->flags, &matchState) < 0) + if (printStateMatchFlags(rule->flags, &matchState3) < 0) return -1; } } @@ -1648,10 +1639,9 @@ iptablesCreateRuleInstanceStateCtrl(virFirewallPtr f= w, rule, ifname, vars, - matchState, false, + matchState3, false, "RETURN", maySkipICMP); - VIR_FREE(matchState); } =20 return rc; @@ -1797,7 +1787,6 @@ ebtablesCreateRuleInstance(virFirewallPtr fw, const char *target; bool hasMask =3D false; virFirewallRulePtr fwrule; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; =20 if (STREQ(chainSuffix, virNWFilterChainSuffixTypeToString( @@ -2320,7 +2309,8 @@ ebtablesCreateRuleInstance(virFirewallPtr fw, HAS_ENTRY_ITEM(&rule->p.ipv6HdrFilter.dataICMPCodeStart) || HAS_ENTRY_ITEM(&rule->p.ipv6HdrFilter.dataICMPCodeEnd)) { bool lo =3D false; - char *r; + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + g_autofree char *r =3D NULL; =20 virFirewallRuleAddArg(fw, fwrule, "--ip6-icmp-type"); @@ -2385,8 +2375,6 @@ ebtablesCreateRuleInstance(virFirewallPtr fw, r =3D virBufferContentAndReset(&buf); =20 virFirewallRuleAddArg(fw, fwrule, r); - - VIR_FREE(r); } break; =20 @@ -3295,9 +3283,8 @@ ebtablesGetSubChainInsts(virHashTablePtr chains, ebtablesSubChainInstPtr **insts, size_t *ninsts) { - virHashKeyValuePairPtr filter_names; + g_autofree virHashKeyValuePairPtr filter_names =3D NULL; size_t i; - int ret =3D -1; =20 filter_names =3D virHashGetItems(chains, ebiptablesFilterOrderSort); @@ -3305,7 +3292,7 @@ ebtablesGetSubChainInsts(virHashTablePtr chains, return -1; =20 for (i =3D 0; filter_names[i].key; i++) { - ebtablesSubChainInstPtr inst; + g_autofree ebtablesSubChainInstPtr inst =3D NULL; enum l3_proto_idx idx =3D ebtablesGetProtoIdxByFiltername( filter_names[i].key); =20 @@ -3318,18 +3305,11 @@ ebtablesGetSubChainInsts(virHashTablePtr chains, inst->protoidx =3D idx; inst->filtername =3D filter_names[i].key; =20 - if (VIR_APPEND_ELEMENT(*insts, *ninsts, inst) < 0) { - VIR_FREE(inst); - goto cleanup; - } + if (VIR_APPEND_ELEMENT(*insts, *ninsts, inst) < 0) + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(filter_names); - return ret; - + return 0; } =20 static int @@ -3339,12 +3319,12 @@ ebiptablesApplyNewRules(const char *ifname, { size_t i, j; g_autoptr(virFirewall) fw =3D virFirewallNew(); - virHashTablePtr chains_in_set =3D virHashCreate(10, NULL); - virHashTablePtr chains_out_set =3D virHashCreate(10, NULL); + g_autoptr(virHashTable) chains_in_set =3D virHashCreate(10, NULL); + g_autoptr(virHashTable) chains_out_set =3D virHashCreate(10, NULL); bool haveEbtables =3D false; bool haveIptables =3D false; bool haveIp6tables =3D false; - ebtablesSubChainInstPtr *subchains =3D NULL; + g_autofree ebtablesSubChainInstPtr *subchains =3D NULL; size_t nsubchains =3D 0; int ret =3D -1; =20 @@ -3538,9 +3518,6 @@ ebiptablesApplyNewRules(const char *ifname, cleanup: for (i =3D 0; i < nsubchains; i++) VIR_FREE(subchains[i]); - VIR_FREE(subchains); - virHashFree(chains_in_set); - virHashFree(chains_out_set); =20 return ret; } diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index acd5614987..071f15caea 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -415,7 +415,6 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr fi= lter, virNWFilterDefPtr next_filter; virNWFilterDefPtr newNext_filter; virNWFilterVarValuePtr val; - virHashTablePtr tmpvars; =20 for (i =3D 0; i < filter->nentries; i++) { virNWFilterRuleDefPtr rule =3D filter->filterEntries[i]->rule; @@ -425,18 +424,16 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr = filter, for (j =3D 0; j < rule->nVarAccess; j++) { if (!virNWFilterVarAccessIsAvailable(rule->varAccess[j], vars)) { - char *varAccess; + g_autofree char *varAccess =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; =20 virNWFilterVarAccessPrint(rule->varAccess[j], &buf); =20 - val =3D virNWFilterVarValueCreateSimpleCopyValue("1"); - if (!val) + if (!(val =3D virNWFilterVarValueCreateSimpleCopyValue= ("1"))) return -1; =20 varAccess =3D virBufferContentAndReset(&buf); rc =3D virHashUpdateEntry(missing_vars, varAccess, val= ); - VIR_FREE(varAccess); if (rc < 0) { virNWFilterVarValueFree(val); return -1; @@ -444,6 +441,8 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr fi= lter, } } } else if (inc) { + g_autoptr(virHashTable) tmpvars =3D NULL; + VIR_DEBUG("Following filter %s", inc->filterref); if (!(obj =3D virNWFilterObjListFindInstantiateFilter(driver->= nwfilters, inc->filte= rref))) @@ -472,9 +471,6 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr fi= lter, missing_vars, useNewFilter, driver); - - virHashFree(tmpvars); - virNWFilterObjUnlock(obj); if (rc < 0) return -1; @@ -515,7 +511,7 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, int rc; virNWFilterInst inst; bool instantiate =3D true; - char *buf; + g_autofree char *buf =3D NULL; virNWFilterVarValuePtr lv; const char *learning; bool reportIP =3D false; @@ -635,7 +631,6 @@ virNWFilterDoInstantiate(virNWFilterTechDriverPtr techd= river, virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot instantiate filter due to unresolvable " "variables or unavailable list elements: %s"), bu= f); - VIR_FREE(buf); } =20 rc =3D -1; diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index 63fac37132..abef0b6457 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -397,7 +397,7 @@ learnIPAddressThread(void *arg) int dhcp_opts_len; char macaddr[VIR_MAC_STRING_BUFLEN]; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - char *filter =3D NULL; + g_autofree char *filter =3D NULL; uint16_t etherType; bool showError =3D true; enum howDetect howDetected =3D 0; @@ -622,8 +622,6 @@ learnIPAddressThread(void *arg) } /* while */ =20 cleanup: - VIR_FREE(filter); - if (handle) pcap_close(handle); =20 @@ -633,7 +631,7 @@ learnIPAddressThread(void *arg) sa.len =3D sizeof(sa.data.inet4); sa.data.inet4.sin_family =3D AF_INET; sa.data.inet4.sin_addr.s_addr =3D vmaddr; - char *inetaddr; + g_autofree char *inetaddr =3D NULL; =20 /* It is necessary to unlock interface here to avoid updateMutex a= nd * interface ordering deadlocks. Otherwise we are going to @@ -656,7 +654,6 @@ learnIPAddressThread(void *arg) req->ifindex); VIR_DEBUG("Result from applying firewall rules on " "%s with IP addr %s : %d", req->binding->portdevname= , inetaddr, ret); - VIR_FREE(inetaddr); } } else { if (showError) --=20 2.25.4 From nobody Mon Nov 25 19:48:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1594156511; cv=none; d=zohomail.com; s=zohoarc; b=HQMhubw5Ue20R8XJ+coIN5W1gOfvOPA3N6Db6F3nWgL2Ra8RdDgVusi1JBN7HMIlZH/Xu7txV0Ar0CiWdoJsg3YCBEPgC/fBpQ7EHPX6gJWHk6kJwO2pa0XNNu0mBjaYw0M71gey9HAhNmGvociZaxfsJ9LgAxDA/INuYw5v9BE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594156511; 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=tuH7lm9x3qMfu2EI0nAX3sJNuOUbHJ4JomqGskk+6cY=; b=ABPQnGvXvciDOSiy5HWQJY5i/ZUEjGl6QyqeqLwHsgltYocOY/zWTV1LOngW0k56LoR7I14/SeADSTje8MFL8zOSSwCZNJmImsUjVosHBHHxug2D+YezYdHCCoT5l1LMt/XCPidvdTwgEQJztV5fAMTy18b4wUBE6g1IXzbIzJM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1594156511527807.1476911150816; Tue, 7 Jul 2020 14:15:11 -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-100-irjtfNiMPQWgblDnGXRXhg-1; Tue, 07 Jul 2020 17:15:07 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6B2F9804006; Tue, 7 Jul 2020 21:15:02 +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 4CF1E5D9DC; Tue, 7 Jul 2020 21:15:02 +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 1D98572F77; Tue, 7 Jul 2020 21:15:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067L8UpW008037 for ; Tue, 7 Jul 2020 17:08:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 617E1797E0; Tue, 7 Jul 2020 21:08:30 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A0FE79220 for ; Tue, 7 Jul 2020 21:08:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594156510; 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=tuH7lm9x3qMfu2EI0nAX3sJNuOUbHJ4JomqGskk+6cY=; b=EZCy5EBfrujPcno7SpXP6E9hz4KmKxJhVsLP2VtdDpnZwQnt+VCX/bRzAzzHOSVO6B+8zE 7TZKKvnmbEGdJFmITTH9Xw1k2+qogwQG4orzqM2w8/67PzWiYsp3lHqEJJ8k6Z98KVR1Gi UZ8S0jAmBSfddsZH3ujoF9uktIEvbWc= X-MC-Unique: irjtfNiMPQWgblDnGXRXhg-1 From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH v2 15/15] nwfilter: convert remaining VIR_FREE() to g_free() Date: Tue, 7 Jul 2020 17:08:15 -0400 Message-Id: <20200707210815.1797463-16-laine@redhat.com> In-Reply-To: <20200707210815.1797463-1-laine@redhat.com> References: <20200707210815.1797463-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.79 on 10.5.11.14 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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/nwfilter/nwfilter_dhcpsnoop.c | 16 ++++++++-------- src/nwfilter/nwfilter_driver.c | 10 +++++----- src/nwfilter/nwfilter_ebiptables_driver.c | 2 +- src/nwfilter/nwfilter_gentech_driver.c | 6 +++--- src/nwfilter/nwfilter_learnipaddr.c | 8 ++++---- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.c index 64671af135..aafa6de322 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -314,7 +314,7 @@ virNWFilterSnoopCancel(char **threadKey) virNWFilterSnoopActiveLock(); =20 ignore_value(virHashRemoveEntry(virNWFilterSnoopState.active, *threadK= ey)); - VIR_FREE(*threadKey); + g_free(*threadKey); =20 virNWFilterSnoopActiveUnlock(); } @@ -600,7 +600,7 @@ virNWFilterSnoopReqFree(virNWFilterSnoopReqPtr req) virCondDestroy(&req->threadStatusCond); virFreeError(req->threadError); =20 - VIR_FREE(req); + g_free(req); } =20 /* @@ -731,7 +731,7 @@ virNWFilterSnoopReqLeaseAdd(virNWFilterSnoopReqPtr req, =20 if (req->threadkey && virNWFilterSnoopIPLeaseInstallRule(pl, true) < 0= ) { virNWFilterSnoopReqUnlock(req); - VIR_FREE(pl); + g_free(pl); return -1; } =20 @@ -850,7 +850,7 @@ virNWFilterSnoopReqLeaseDel(virNWFilterSnoopReqPtr req, } =20 skip_instantiate: - VIR_FREE(ipl); + g_free(ipl); =20 ignore_value(!!g_atomic_int_dec_and_test(&virNWFilterSnoopState.nLease= s)); =20 @@ -1149,7 +1149,7 @@ virNWFilterSnoopDHCPDecodeJobSubmit(virThreadPoolPtr = pool, if (ret =3D=3D 0) g_atomic_int_add(qCtr, 1); else - VIR_FREE(job); + g_free(job); =20 return ret; } @@ -1502,7 +1502,7 @@ virNWFilterDHCPSnoopThread(void *req0) ignore_value(virHashRemoveEntry(virNWFilterSnoopState.ifnameToKey, req->binding->portdevname)); =20 - VIR_FREE(req->binding->portdevname); + g_clear_pointer(&req->binding->portdevname, g_free); =20 virNWFilterSnoopReqUnlock(req); virNWFilterSnoopUnlock(); @@ -1970,7 +1970,7 @@ virNWFilterSnoopRemAllReqIter(const void *payload, */ virNWFilterIPAddrMapDelIPAddr(req->binding->portdevname, NULL); =20 - VIR_FREE(req->binding->portdevname); + g_clear_pointer(&req->binding->portdevname, g_free); } =20 virNWFilterSnoopReqUnlock(req); @@ -2079,7 +2079,7 @@ virNWFilterDHCPSnoopEnd(const char *ifname) /* keep valid lease req; drop interface association */ virNWFilterSnoopCancel(&req->threadkey); =20 - VIR_FREE(req->binding->portdevname); + g_clear_pointer(&req->binding->portdevname, g_free); =20 virNWFilterSnoopReqUnlock(req); =20 diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index 39d0a2128e..7853ad59fa 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -303,7 +303,7 @@ nwfilterStateInitialize(bool privileged, =20 err_free_driverstate: virNWFilterObjListFree(driver->nwfilters); - VIR_FREE(driver); + g_free(driver); =20 return VIR_DRV_STATE_INIT_ERROR; } @@ -367,9 +367,9 @@ nwfilterStateCleanup(void) if (driver->lockFD !=3D -1) virPidFileRelease(driver->stateDir, "driver", driver->lockFD); =20 - VIR_FREE(driver->stateDir); - VIR_FREE(driver->configDir); - VIR_FREE(driver->bindingDir); + g_free(driver->stateDir); + g_free(driver->configDir); + g_free(driver->bindingDir); nwfilterDriverUnlock(); } =20 @@ -379,7 +379,7 @@ nwfilterStateCleanup(void) virNWFilterObjListFree(driver->nwfilters); =20 virMutexDestroy(&driver->lock); - VIR_FREE(driver); + g_free(driver); =20 return 0; } diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfil= ter_ebiptables_driver.c index 9c9d63f14b..6aefbe226b 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -3517,7 +3517,7 @@ ebiptablesApplyNewRules(const char *ifname, =20 cleanup: for (i =3D 0; i < nsubchains; i++) - VIR_FREE(subchains[i]); + g_free(subchains[i]); =20 return ret; } diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index 071f15caea..c93f2ed18f 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -122,7 +122,7 @@ virNWFilterRuleInstFree(virNWFilterRuleInstPtr inst) return; =20 virHashFree(inst->vars); - VIR_FREE(inst); + g_free(inst); } =20 =20 @@ -234,12 +234,12 @@ virNWFilterInstReset(virNWFilterInstPtr inst) =20 for (i =3D 0; i < inst->nfilters; i++) virNWFilterObjUnlock(inst->filters[i]); - VIR_FREE(inst->filters); + g_free(inst->filters); inst->nfilters =3D 0; =20 for (i =3D 0; i < inst->nrules; i++) virNWFilterRuleInstFree(inst->rules[i]); - VIR_FREE(inst->rules); + g_free(inst->rules); inst->nrules =3D 0; } =20 diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index abef0b6457..c6497450eb 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -156,7 +156,7 @@ virNWFilterLockIface(const char *ifname) if (virMutexInitRecursive(&ifaceLock->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("mutex initialization failed")); - VIR_FREE(ifaceLock); + g_free(ifaceLock); goto error; } =20 @@ -165,12 +165,12 @@ virNWFilterLockIface(const char *ifname) _("interface name %s does not fit into " "buffer "), ifaceLock->ifname); - VIR_FREE(ifaceLock); + g_free(ifaceLock); goto error; } =20 while (virHashAddEntry(ifaceLockMap, ifname, ifaceLock)) { - VIR_FREE(ifaceLock); + g_free(ifaceLock); goto error; } =20 @@ -221,7 +221,7 @@ virNWFilterIPAddrLearnReqFree(virNWFilterIPAddrLearnReq= Ptr req) =20 virNWFilterBindingDefFree(req->binding); =20 - VIR_FREE(req); + g_free(req); } =20 =20 --=20 2.25.4