From nobody Tue Jul 1 05:38:14 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 1531504595839349.1740977551656; Fri, 13 Jul 2018 10:56:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68AE5308A945; Fri, 13 Jul 2018 17:56:32 +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 0F5FB2010D5B; Fri, 13 Jul 2018 17:56:32 +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 917F3264D3; Fri, 13 Jul 2018 17:56:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHtxhI008466 for ; Fri, 13 Jul 2018 13:55:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2A6D12010CC6; Fri, 13 Jul 2018 17:55:59 +0000 (UTC) Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 189AE2010CCE for ; Fri, 13 Jul 2018 17:55:56 +0000 (UTC) Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 42E20308FBB3 for ; Fri, 13 Jul 2018 17:55:45 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id g2-v6so384994pgs.6 for ; Fri, 13 Jul 2018 10:55:45 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:44 -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=T+H8SFa+LmTwyrUZ9ocje81gauVgyt7pcnyPdoNw8O0=; b=u3K1xgDVl+BzgfnEH/xEM98hT90mSIuZSyT/dAOyRXzACBPAkaN65p/QcZnXCyGh2R y2S4q6wrDwH0nBnI1+pfrKGpqQJzdLo+9OAtKrLk9WFnAGmkxsRoo6mUS3OtvMbUvVo5 jd1MPkORsRIHUL3+k1VmxVx4Gy4IeqJm30ByAgsS5lb9TW/i9YSfuyKdTlBJiAjyNlYf K/IoNxcgq3KVTa5oeIrW/y8Bd8cv6U7VuObxGtai3CKVU9e/28DMVrPnVOP9RrchdoKY zoNSirtDGST0e81xEKyJpEajugyZg6fPoi8G0Dm3aSOoHcHTwRx4MpS9DD3f8g2NUKv5 +r0A== 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=T+H8SFa+LmTwyrUZ9ocje81gauVgyt7pcnyPdoNw8O0=; b=fw6WmkcdkiC4duW0D13nlHL4G1EYT9PnY639qS4Hi0L15iZrpQEpt6Mk8KlSawGCz6 wcy0wUcqFZb4kLLgS3GTnZOoB1tMfyKFZNU8boqvvroImBm8OfA0CJadnkcr5GlrA/y2 2M2knPon9FEbjLewV7YI5uw/grGKcs1Eyv3wbtbF3uwuPlPmiTRPcG+theGoYjcIBTiD NC/U9QtI6S+5mQMnd0tn+OXGGxKRqcj0R6gZpqcmtaDcXysCFRyM8U4Hf1tmRhj/s8fl r/hRRkVj/Xq1HD2Bfcy5VRDJ3QhcKkC6UyGkl+c9cAQ6l3YjN+8n7lk+89nQGe+E/ppg p3CA== X-Gm-Message-State: AOUpUlGwHMJsBn8fp1Kbi4zmtSNhlrqxxWGo+XBQwIo4ApAoOLTnYB+C XhogfUIXcGe2MPmlsXy4yJ6Ca+wD X-Google-Smtp-Source: AAOMgpepWmeSW/ig0jE6HQJGOdUGKP2RDsKyaINm+sJFB2/AfCDnpcDqJVuy0u0OgP8dCsMQoAuQKw== X-Received: by 2002:a62:e18:: with SMTP id w24-v6mr8128425pfi.145.1531504544506; Fri, 13 Jul 2018 10:55:44 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:49 +0530 Message-Id: <1531504509-7930-12-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1531504509-7930-1-git-send-email-skrtbhtngr@gmail.com> References: <1531504509-7930-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.43]); Fri, 13 Jul 2018 17:55:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 13 Jul 2018 17:55:45 +0000 (UTC) for IP:'209.85.215.174' DOMAIN:'mail-pg1-f174.google.com' HELO:'mail-pg1-f174.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.215.174 mail-pg1-f174.google.com 209.85.215.174 mail-pg1-f174.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.43 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 11/31] util: file: 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.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 13 Jul 2018 17:56:35 +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/virfile.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 3a7445f..6b94885 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -888,20 +888,19 @@ int virFileNBDDeviceAssociate(const char *file, { VIR_AUTOFREE(char *) nbddev =3D NULL; VIR_AUTOFREE(char *) qemunbd =3D NULL; - virCommandPtr cmd =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; const char *fmtstr =3D NULL; =20 if (!virFileNBDLoadDriver()) - goto cleanup; + return -1; =20 if (!(nbddev =3D virFileNBDDeviceFindUnused())) - goto cleanup; + return -1; =20 if (!(qemunbd =3D virFindFileInPath("qemu-nbd"))) { virReportSystemError(ENOENT, "%s", _("Unable to find 'qemu-nbd' binary in $PATH"= )); - goto cleanup; + return -1; } =20 if (fmt > 0) @@ -926,17 +925,14 @@ int virFileNBDDeviceAssociate(const char *file, /* qemu-nbd will daemonize itself */ =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Associated NBD device %s with file %s and format %s", nbddev, file, fmtstr); *dev =3D nbddev; nbddev =3D NULL; - ret =3D 0; =20 - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 #else /* __linux__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list