From nobody Mon Feb 9 01:21:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1641977320; cv=none; d=zohomail.com; s=zohoarc; b=KjgFzdwtnjUqR7vUDy3zk/NSSfYqiRh7LPWThV2zqXZ9xvJ25TeySrPCFYjfzax3G9ekUSBP7jHbD08XocI7AbhbbmiG2ZrRIO81yXvbt/SmA8Mcn+VEOKTvdq77nXcHi5lavR7U/xcP25/dtprOl5Sy0V8MQgTL0NailcIg9Io= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641977320; 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=gvOt7v+A5SH7kQzAUl1CnjiHfkg8ATIWnXdUWWQGmDE=; b=LaYIrLXjTNkvkx5onMz5EG1i2XCmmaMau8PgQBFIZpotNMjqNKcYQjB/aYmfXCG5pq62x+iNPezavTV9JUvmRSVMsv/Bn/QWMnvfgTcYONQH31i6a+nkN6orxC1DDxUbexzRD1tvNQV71gpaONy5+GwReoZvt8g2bE+v5Zb3xX0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1641977320123522.0911732794115; Wed, 12 Jan 2022 00:48:40 -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-393-Vj_xnMgIP6GA_gthugtOJQ-1; Wed, 12 Jan 2022 03:48:35 -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 979371006AA5; Wed, 12 Jan 2022 08:48:29 +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 7204570D23; Wed, 12 Jan 2022 08:48:29 +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 EB7054BB7C; Wed, 12 Jan 2022 08:48:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 20C8mRI8017395 for ; Wed, 12 Jan 2022 03:48:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1008967C9D; Wed, 12 Jan 2022 08:48:27 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F0D4752A7 for ; Wed, 12 Jan 2022 08:48:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1641977319; 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=gvOt7v+A5SH7kQzAUl1CnjiHfkg8ATIWnXdUWWQGmDE=; b=egLhqA51mzPEigiqcA2teMIUF2coHq4It2EyiVFneomhXcePvzNZDkEhiLTgFFYqZfxnH3 DvN8NB3VcwKHpJbxo47mGUIdTqf8Mv5wUFsq/aM4L5AEdh7z79YiT2XkCfpf9Fd+ozHcIF FCDJe3/Dk68fRjQh6EjehH2p+uJczBs= X-MC-Unique: Vj_xnMgIP6GA_gthugtOJQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 2/7] lib: Prefer g_autoptr(dnsmasqCaps) instead of explicit unref Date: Wed, 12 Jan 2022 09:47:53 +0100 Message-Id: <029c2671f4ecd979d4eb1b04855c1d2152c41bac.1641976729.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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: 1641977321601100002 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 | 18 ++++++++---------- tests/networkxml2conftest.c | 7 +++---- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index d304929d51..f4bdab116e 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -715,31 +715,29 @@ dnsmasqCapsNewEmpty(void) 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