From nobody Sat Feb 7 06:49:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1642516710; cv=none; d=zohomail.com; s=zohoarc; b=TlFs7VsuAefW7k83YIjulLAlgSp2K3hcmv8e3VJW8ZEfp84DtDCL0rR/3/H3wbEf+DvPou3tvfwJwwiqhD2xVyhFjbrdvqk4qVqt7TbfR+7xq6kBdVnaw9eO0AY9mBA5syt94rE73XyaVpgE/iYoUd6F02cHiTlvDUa6lZxb2j4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642516710; 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=b3e0gRN6udBkXMGafKzRDLMBMV1kkYef/j97eJKy7y4=; b=CfrhlNIwC9Ku0om/CBqSrN6PbzIH3f7h3G8RC/um9Ac/JNlfQibAWAzgge7j/5TpLBux7iwr/MflCtuvvfCql1N3YkMABrBN33Yctq/fxytRW8vAUXtw4rsKJEnVzaBPg0MVMcaKWmH5VEKx4hWA5QdrcSmGTRy8EahXmi3jy/Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1642516710894414.10612688317246; Tue, 18 Jan 2022 06:38:30 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-480-Q50uBWDKOImcwb6zNP8J0w-1; Tue, 18 Jan 2022 09:38:27 -0500 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 D16ED3E75E; Tue, 18 Jan 2022 14:38:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A654D753CF; Tue, 18 Jan 2022 14:38:21 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6C43F1809CB9; Tue, 18 Jan 2022 14:38:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 20IEbf8D016629 for ; Tue, 18 Jan 2022 09:37:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2C0652C1AE; Tue, 18 Jan 2022 14:37:41 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA4B32BE7F for ; Tue, 18 Jan 2022 14:37:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642516709; 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=b3e0gRN6udBkXMGafKzRDLMBMV1kkYef/j97eJKy7y4=; b=By05OMKTa1trPHcmzsYgx9m8fg792D1acYnR/df24wgVmmNV9Y39oUXJQL5tpTcHx4qkMr 35o2ZkKuMng3VCdavpvPjjtNPAAWWADnQFuWyHM8TbCvq5MLH8YDxs7J3MwuahOY2Vcm1d 1/EmD95PfQeCRAyF84gNrwJKhJu0TUQ= X-MC-Unique: Q50uBWDKOImcwb6zNP8J0w-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v5 02/13] lib: Prefer g_autoptr(dnsmasqCaps) instead of explicit unref Date: Tue, 18 Jan 2022 15:37:09 +0100 Message-Id: <6944c78d38d8e2f1531ca713cd0c51746765909a.1642516422.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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) X-ZM-MESSAGEID: 1642516713057100001 Content-Type: text/plain; charset="utf-8" The dnsmasqCaps type has its own cleanup function defined and ready to use via g_autoptr(). Use automatic cleanup instead of an explicit one. Signed-off-by: Michal Privoznik Reviewed-by: Andrea Bolognani --- src/util/virdnsmasq.c | 22 ++++++++++------------ tests/networkxml2conftest.c | 7 +++---- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index d304929d51..9f3da1d5e6 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -702,44 +702,42 @@ dnsmasqCapsRefreshInternal(dnsmasqCaps *caps, bool fo= rce) static dnsmasqCaps * dnsmasqCapsNewEmpty(void) { - dnsmasqCaps *caps; + g_autoptr(dnsmasqCaps) caps =3D NULL; =20 if (dnsmasqCapsInitialize() < 0) return NULL; if (!(caps =3D virObjectNew(dnsmasqCapsClass))) return NULL; caps->binaryPath =3D g_strdup(DNSMASQ); - return caps; + return g_steal_pointer(&caps); } =20 dnsmasqCaps * dnsmasqCapsNewFromBuffer(const char *buf) { - dnsmasqCaps *caps =3D dnsmasqCapsNewEmpty(); + g_autoptr(dnsmasqCaps) caps =3D dnsmasqCapsNewEmpty(); =20 if (!caps) return NULL; =20 - if (dnsmasqCapsSetFromBuffer(caps, buf) < 0) { - virObjectUnref(caps); + if (dnsmasqCapsSetFromBuffer(caps, buf) < 0) return NULL; - } - return caps; + + return g_steal_pointer(&caps); } =20 dnsmasqCaps * dnsmasqCapsNewFromBinary(void) { - dnsmasqCaps *caps =3D dnsmasqCapsNewEmpty(); + g_autoptr(dnsmasqCaps) caps =3D dnsmasqCapsNewEmpty(); =20 if (!caps) return NULL; =20 - if (dnsmasqCapsRefreshInternal(caps, true) < 0) { - virObjectUnref(caps); + if (dnsmasqCapsRefreshInternal(caps, true) < 0) return NULL; - } - return caps; + + return g_steal_pointer(&caps); } =20 const char * diff --git a/tests/networkxml2conftest.c b/tests/networkxml2conftest.c index 178c74d9af..d79c2b4783 100644 --- a/tests/networkxml2conftest.c +++ b/tests/networkxml2conftest.c @@ -112,8 +112,9 @@ static int mymain(void) { int ret =3D 0; - dnsmasqCaps *full - =3D dnsmasqCapsNewFromBuffer("Dnsmasq version 2.67\n--bind-dynamic= \n--ra-param"); + g_autoptr(dnsmasqCaps) full =3D NULL; + + full =3D dnsmasqCapsNewFromBuffer("Dnsmasq version 2.67\n--bind-dynami= c\n--ra-param"); =20 #define DO_TEST(xname, xcaps) \ do { \ @@ -154,8 +155,6 @@ mymain(void) DO_TEST("leasetime-hours", full); DO_TEST("leasetime-infinite", full); =20 - virObjectUnref(full); - return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 --=20 2.34.1