From nobody Tue May 13 11:07:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532639134118805.8649939179878; Thu, 26 Jul 2018 14:05:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 310CF307D85C; Thu, 26 Jul 2018 21:05:32 +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 E563F308BDB4; Thu, 26 Jul 2018 21:05:31 +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 888271800540; Thu, 26 Jul 2018 21:05:31 +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 w6QL5UX9024915 for ; Thu, 26 Jul 2018 17:05:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id F0ED5608F7; Thu, 26 Jul 2018 21:05:29 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8880B6091C for ; Thu, 26 Jul 2018 21:05:28 +0000 (UTC) Received: from mail-pl0-f68.google.com (mail-pl0-f68.google.com [209.85.160.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A260AC04AC43 for ; Thu, 26 Jul 2018 21:05:27 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id e11-v6so1344303plb.3 for ; Thu, 26 Jul 2018 14:05:27 -0700 (PDT) Received: from centos.localdomain ([42.106.3.93]) by smtp.gmail.com with ESMTPSA id z10-v6sm3279182pfh.83.2018.07.26.14.05.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 14:05:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=GXSz+omG0gwdwLoastA3SCD9QAdj1C9IsusSFlM71FI=; b=h51sRHgPa8QWED/QH0aw7brRjGBEhLJL1SdAZDL+WFOnzk2C6HYE9q4G2lfze5oc40 E7dmnjDsQEIPuh5Qggl62BIK5VkvwnGO0P21hQvDyNODUjzQ5ZZ2QTlVIq00FHf/a78M ekauwwio4Qd9GoFEs+co/N/+nP6jwh5jqSsSVe9ZFs+O4IcE3Gp/CfAaCodtV8A1fQnV xWqQJtZRE2XjA51y9pe0H2TewyxuIrgjeANFcYIfNloZrxloggSdfMBMMhVFMkDt6pzA lbqGgGlh03WMEidKNNMYiiWkAxCZxQz7B6igiYdaYGxVLvxAXKCCCRVio0N9KTH8Zn8W 5qjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=GXSz+omG0gwdwLoastA3SCD9QAdj1C9IsusSFlM71FI=; b=lB3UmZXpNdvl9ZGzHaJtNTm7HIi3oE7RnX2yBG+0x/yEk85Jy0ezAzKtLxdMzt6rnp U2gPhzohXI19CrOqSp1IQZPLHZFe1872AH+uJ3Sz+hVMhM15SXum2DDqZkoYzfx5PpF2 N5WfG7HiMJehYWhuJtC5YC15f3cx/t8RnTjp28sZJBqqJ9V7HpT/Gw/OFLxT6NepWlR/ SvrxF6a3mp31CAwK7fypI3SGbWXDqnc5jZCvXmzenVHoAWwQ0sqVkB8XzvcVQlpW63+b 3hUCYWpy9V+EyzWaZPVBnV8dXUQB+GfEidVpqlLzb4YOn+YZztY68Xh52VKeKnu/+rc1 ZDKQ== X-Gm-Message-State: AOUpUlFa7NoTGjE92lkJPrR0rdB2yO3hWQLG0IUcrd+TaE0+iFUcpS31 5va0/4Nt/CbuqboSpEjSm7TU9IxO X-Google-Smtp-Source: AAOMgpd3uS+ws/Y4Ph0wM5VD8y+UlxVjcbUQ8lwMzhb0nECTrQbWnbapOiYXJKxZ4xmni633AW1KFA== X-Received: by 2002:a17:902:ab94:: with SMTP id f20-v6mr3319482plr.231.1532639126919; Thu, 26 Jul 2018 14:05:26 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Tue, 24 Jul 2018 21:22:26 +0530 Message-Id: <1532447562-24010-26-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532447562-24010-1-git-send-email-skrtbhtngr@gmail.com> References: <1532447562-24010-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 26 Jul 2018 21:05:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 26 Jul 2018 21:05:27 +0000 (UTC) for IP:'209.85.160.68' DOMAIN:'mail-pl0-f68.google.com' HELO:'mail-pl0-f68.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.37 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_PASS) 209.85.160.68 mail-pl0-f68.google.com 209.85.160.68 mail-pl0-f68.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 25/41] util: usb: use VIR_AUTOPTR for aggregate types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 26 Jul 2018 21:05:32 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virusb.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/util/virusb.c b/src/util/virusb.c index 47b407b..df94959 100644 --- a/src/util/virusb.c +++ b/src/util/virusb.c @@ -123,8 +123,10 @@ virUSBDeviceSearch(unsigned int vendor, bool found =3D false; char *ignore =3D NULL; struct dirent *de; - virUSBDeviceListPtr list =3D NULL, ret =3D NULL; - virUSBDevicePtr usb; + virUSBDeviceListPtr list =3D NULL; + virUSBDeviceListPtr ret =3D NULL; + VIR_AUTOPTR(virUSBDevice) usb =3D NULL; + virUSBDevicePtr *ptr =3D NULL; int direrr; =20 if (!(list =3D virUSBDeviceListNew())) @@ -173,13 +175,13 @@ virUSBDeviceSearch(unsigned int vendor, } =20 usb =3D virUSBDeviceNew(found_bus, found_devno, vroot); + ptr =3D &usb; + if (!usb) goto cleanup; =20 - if (virUSBDeviceListAdd(list, &usb) < 0) { - virUSBDeviceFree(usb); + if (virUSBDeviceListAdd(list, ptr) < 0) goto cleanup; - } =20 if (found) break; @@ -508,8 +510,7 @@ void virUSBDeviceListDel(virUSBDeviceListPtr list, virUSBDevicePtr dev) { - virUSBDevicePtr ret =3D virUSBDeviceListSteal(list, dev); - virUSBDeviceFree(ret); + VIR_AUTOPTR(virUSBDevice) ret =3D virUSBDeviceListSteal(list, dev); } =20 virUSBDevicePtr --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list