From nobody Sat May 4 14:57:42 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=1595043533; cv=none; d=zohomail.com; s=zohoarc; b=B+ptPunC6veg8suaOzE4jsonndurV4cPLZH586LgUbM+jhLzYWkwxs5MRm5is0fQc/rqYcKZ9Lc/S7HONAuOKDkIoyUjnr1kr0O3/cqUZA0RpJgT2SlRMAc0KGcs2DSLH86ot48koy1ed830pfDJdY2vTuBgo6HetYLBm6i98gQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595043533; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=ZinqOt1lJ2Jmv9/eqidoovLfdzytUsDxfPzIyiZQzw0=; b=POD1VCNjvmbE1+iH2s4AYi+pAB41am87pDDguOl6hSZ4uNjw43k8fZokUl68mc9kRqrFt5yy69EXzF+oH7Zl0jxdTV/VhmKL4Uzr2p7+lh6oQP/1jPUxkSgZeQEd2P5mjOM5Js+PgB/HV9gBmW3rZbqaa+FahdT4ipnREJ8mqVc= 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 159504353349128.626300760102936; Fri, 17 Jul 2020 20:38:53 -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-350-mhBHZjlYNxSlgEtCptLKWQ-1; Fri, 17 Jul 2020 23:38:50 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A48A8809881; Sat, 18 Jul 2020 03:38:43 +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 4B5AE100164C; Sat, 18 Jul 2020 03:38:40 +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 5338096258; Sat, 18 Jul 2020 03:38:34 +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 06I3XrgK031997 for ; Fri, 17 Jul 2020 23:33:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 858677BD47; Sat, 18 Jul 2020 03:33:53 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-16.phx2.redhat.com [10.3.112.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24A577BD7C; Sat, 18 Jul 2020 03:33:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595043532; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ZinqOt1lJ2Jmv9/eqidoovLfdzytUsDxfPzIyiZQzw0=; b=cEtQ0DgKPVCdAJg7ld80x5oV9HrDlj9iOe1NE9vvgH15pUme/qcjNo1ni9pBTA80Me1huR l/U8IHkbigyiGtvfH8xBT49BkLwimWPEnkIiujlI4W76tkgiEPNPjZS+RZWDJN35FicmA7 od4J/ln1dwVFRLsisMlKs4vAM+8zLNY= X-MC-Unique: mhBHZjlYNxSlgEtCptLKWQ-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH] network: refactor networkSetIPv6Sysctls() for proper g_autofree usage Date: Fri, 17 Jul 2020 23:33:46 -0400 Message-Id: <20200718033346.816154-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 Cc: Jan Tomko 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.22 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 function used the same char* three times for different purposes, freeing it after each use. Since we don't want to ever manually free an autofree'd pointer, modify it to use three separate char*, and make them all g_autofree. Signed-off-by: Laine Stump --- This was suggested by Jan in https://www.redhat.com/archives/libvir-list/2020-July/msg00805.html pushing this patch along with the patch 5 referenced there will permit pushing patch 06/15 of that series unmodified. src/network/bridge_driver.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index dd8f34e543..6d341dba7c 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -2248,7 +2248,9 @@ static int networkSetIPv6Sysctls(virNetworkObjPtr obj) { virNetworkDefPtr def =3D virNetworkObjGetDef(obj); - char *field =3D NULL; + g_autofree char *disable_ipv6 =3D NULL; + g_autofree char *accept_ra =3D NULL; + g_autofree char *autoconf =3D NULL; int ret =3D -1; bool enableIPv6 =3D !!virNetworkDefGetIPByIndex(def, AF_INET6, 0); =20 @@ -2256,10 +2258,10 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj) * network. But also unset it if there *are* ipv6 addresses, as we * can't be sure of its default value. */ - field =3D g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf/%s/disable_ipv6", - def->bridge); + disable_ipv6 =3D g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf/%s/disabl= e_ipv6", + def->bridge); =20 - if (access(field, W_OK) < 0 && errno =3D=3D ENOENT) { + if (access(disable_ipv6, W_OK) < 0 && errno =3D=3D ENOENT) { if (!enableIPv6) VIR_DEBUG("ipv6 appears to already be disabled on %s", def->bridge); @@ -2267,13 +2269,12 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj) goto cleanup; } =20 - if (virFileWriteStr(field, enableIPv6 ? "0" : "1", 0) < 0) { + if (virFileWriteStr(disable_ipv6, enableIPv6 ? "0" : "1", 0) < 0) { virReportSystemError(errno, _("cannot write to %s to enable/disable IPv6 " - "on bridge %s"), field, def->bridge); + "on bridge %s"), disable_ipv6, 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,30 +2283,29 @@ networkSetIPv6Sysctls(virNetworkObjPtr obj) /* Prevent guests from hijacking the host network by sending out * their own router advertisements. */ - field =3D g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf/%s/accept_ra", - def->bridge); + accept_ra =3D g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf/%s/accept_ra= ", + def->bridge); =20 - if (virFileWriteStr(field, "0", 0) < 0) { + if (virFileWriteStr(accept_ra, "0", 0) < 0) { virReportSystemError(errno, - _("cannot disable %s"), field); + _("cannot disable %s"), accept_ra); goto cleanup; } - VIR_FREE(field); =20 /* All interfaces used as a gateway (which is what this is, by * definition), must always have autoconf=3D0. */ - field =3D g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf/%s/autoconf", de= f->bridge); + autoconf =3D g_strdup_printf(SYSCTL_PATH "/net/ipv6/conf/%s/autoconf", + def->bridge); =20 - if (virFileWriteStr(field, "0", 0) < 0) { + if (virFileWriteStr(autoconf, "0", 0) < 0) { virReportSystemError(errno, - _("cannot disable %s"), field); + _("cannot disable %s"), autoconf); goto cleanup; } =20 ret =3D 0; cleanup: - VIR_FREE(field); return ret; } =20 --=20 2.25.4