From nobody Mon Feb 9 15:08:38 2026 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 1533714292025236.11584790554684; Wed, 8 Aug 2018 00:44:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1FABB80F75; Wed, 8 Aug 2018 07:44:50 +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 B7EE26886A; Wed, 8 Aug 2018 07:44:49 +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 BD573245FF; Wed, 8 Aug 2018 07:44:48 +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 w787ilRb006270 for ; Wed, 8 Aug 2018 03:44:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 372CB6090D; Wed, 8 Aug 2018 07:44:47 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C7CB6090B for ; Wed, 8 Aug 2018 07:44:20 +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 0B1B781DF6 for ; Wed, 8 Aug 2018 07:44:20 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id f14-v6so674186pgv.13 for ; Wed, 08 Aug 2018 00:44:20 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.44.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:44:18 -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=h5F/rhXLq8rzyLRwgvu7H5wo1Wz8Vz/l+4Qd7RpGrgA=; b=kEwwqYDC74SZN580ewdt1fZjRNmXF0XpY1duif+Qj6pWnUMjgzRQdNGDgF1/sDIIDW Qrpe1ZoFFG3Lsa+AOegv1VWwmDTerUe2gPa75ts77g0OEaoJpgDtlwD2gLkny/rCwzvn af5v+9uOLuoWR6M8Vs4Ee/fA7ULhYWkWFvvVuQmeLO1ColGzjnyVKThnitAamMoUfJwF 9Gr7Hbldo+JpEzKLJg2vMHxvMiEo3/TNsdVCbVvokyRVd79SBp1opQ+2FmV2nfpBS+Ed hodDkyXCh9o8XJvtKtL3KnqyPt/TftBDOoaeDnww1lTFop3OU7A2nwkXU7ry7l+wvZ+m gsiQ== 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=h5F/rhXLq8rzyLRwgvu7H5wo1Wz8Vz/l+4Qd7RpGrgA=; b=PEM2Rc69NGr+9yWfr5tCxlnY3yn210TjI7If1LUH1c5TEDCqL0ikSW/KPMgk7bsjVt 0nSJRkgxMGQ8/vFWV7SCryIyf30R6cCCZopfg/e1eH6ZaL5DGScHUSsdwGdwi1a6/d6G SZxyUctsC8QV+XFIDCm4hryRTScKZpOG9e97dKKSx/lM8/D6OWClXBeNxgw60wFgwWLt B2MmUVHtN7zjlTjah79PiwMymFgruNzmixgBiLH5tYEk4dePsckpeN+8PbOAaeh+GeHW 1Sn7NAuctl5vyYUVz+dH0gdlsBBUAQM+ZPM2/GKU4LqUfs5EUXeP9sTSaI78X1flQ78S OE4w== X-Gm-Message-State: AOUpUlGOg4BK0MMG9oY0yNFZI6MJiy65waOuG3D82OaUjw7URLQP9I74 Lt5isY7cPenv8e5evRpG9OYy52v1 X-Google-Smtp-Source: AA+uWPySOPraq5kTLTIkjVhBDIKP8AVGMROWRxJufZv3Tjoy/E4xvVMjagjQqRlB6tm1B8ZE+8Wszg== X-Received: by 2002:a63:5421:: with SMTP id i33-v6mr1473408pgb.417.1533714259267; Wed, 08 Aug 2018 00:44:19 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:14:00 +0530 Message-Id: <1533501842-24503-34-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-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.25]); Wed, 08 Aug 2018 07:44:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 08 Aug 2018 07:44:20 +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: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.215.174 mail-pg1-f174.google.com 209.85.215.174 mail-pg1-f174.google.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 33/35] util: process: 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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 08 Aug 2018 07:44:50 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 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/virprocess.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 215e05d..1fbbe0c 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -971,9 +971,8 @@ int virProcessGetStartTime(pid_t pid, unsigned long long *timestamp) { char *tmp; - int ret =3D -1; int len; - char **tokens =3D NULL; + VIR_AUTOPTR(virString) tokens =3D NULL; VIR_AUTOFREE(char *) filename =3D NULL; VIR_AUTOFREE(char *) buf =3D NULL; =20 @@ -981,7 +980,7 @@ int virProcessGetStartTime(pid_t pid, return -1; =20 if ((len =3D virFileReadAll(filename, 1024, &buf)) < 0) - goto cleanup; + return -1; =20 /* start time is the token at index 19 after the '(process name)' entr= y - since only this * field can contain the ')' character, search backwards for this to a= void malicious @@ -992,14 +991,14 @@ int virProcessGetStartTime(pid_t pid, virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find start time in %s"), filename); - goto cleanup; + return -1; } tmp +=3D 2; /* skip ') ' */ if ((tmp - buf) >=3D len) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find start time in %s"), filename); - goto cleanup; + return -1; } =20 tokens =3D virStringSplit(tmp, " ", 0); @@ -1008,7 +1007,7 @@ int virProcessGetStartTime(pid_t pid, virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find start time in %s"), filename); - goto cleanup; + return -1; } =20 if (virStrToLong_ull(tokens[19], @@ -1018,14 +1017,10 @@ int virProcessGetStartTime(pid_t pid, virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot parse start time %s in %s"), tokens[19], filename); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - virStringListFree(tokens); - return ret; + return 0; } #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) int virProcessGetStartTime(pid_t pid, --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list