From nobody Sun Feb 8 07:07:40 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 1532806910824656.0098563238776; Sat, 28 Jul 2018 12:41:50 -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 12DE63001777; Sat, 28 Jul 2018 19:41:49 +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 C96F967CEF; Sat, 28 Jul 2018 19:41:48 +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 794E41800B7D; Sat, 28 Jul 2018 19:41:48 +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 w6SJfeOh021098 for ; Sat, 28 Jul 2018 15:41:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8337716C17; Sat, 28 Jul 2018 19:41:40 +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 77FA619486 for ; Sat, 28 Jul 2018 19:41:40 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) (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 24ED8C04F4D1 for ; Sat, 28 Jul 2018 19:41:39 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id j26-v6so2875519pfi.10 for ; Sat, 28 Jul 2018 12:41:39 -0700 (PDT) Received: from centos.localdomain ([49.32.98.239]) by smtp.gmail.com with ESMTPSA id m26-v6sm20270426pfi.102.2018.07.28.12.41.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Jul 2018 12:41:37 -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=POMIfPDvEbPPXQDkw6kZX7m4l8GbIwzz+T5Izvkh3xA=; b=UKJc1NC/1YKX0FE5qhIV0cVexXPktw9prMPRyrCMt01eN0ihNDmRkQnH7F4Yw8Pxee tL4/OYrTEUFYneQF1gCGCcZUUfbFlIxSQmuz/y22VuA3qidDfQ02+NaCgurPlDzrC0zz 2TNQpOm3bJf2ZvsLhu5TjAiWpfS92ltoHUXtj1nII5LXtKc9u0J0Muths27l4d3uGS8G 2Hq8PWuInpfiUpIw6x5LGQjnkMUzi/e/ZyB0qeSjbA0YdWdW0qaNbGLpQ+smbz60IthV ThxzAx4+AXQf4Dw0bGt1fA6dAEZbofyVOO1mFy8NGP1HuiXBolwFcLXg2UMORZpUEKm1 XzrQ== 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=POMIfPDvEbPPXQDkw6kZX7m4l8GbIwzz+T5Izvkh3xA=; b=DiSTWZLRlUpm6TtHIicIgmKU3T7FOTrixPvtQ5DPaHY4xmosBD6Nea+AEIKPRXBqmX ZPtet8PRdWOq1TDkbPBDOhq2CzM73AooRggT+2PlvzVDs8SbavYnwc/RomMsjFMne64N 8kqtA9/Rl2yg6JUsA8NyxFFVPQjhQJxApXV52+Fyh2/O137eO2F57cMYZsHNDz6XE9Mr mL16cATa8KQ6P9BWx0OJpDuCL9bTVPPQ2vKWXINd5BWw3oWlQXDrdfzoX5A7B4aJpv0I CXHR7UlfSWwpGKDFskawbmEbS9Qb0Mq6UTkc96AlgkIWHa4eRsXphE0sCnAjz/L9fpTb 94fQ== X-Gm-Message-State: AOUpUlH0a57rxbZa7iDKsL3+877+9NqgkkO8TDXPx+eVpBtwJnDqTOI3 w+oJOiYNnpgCFNKFvFUOLXZsv1kS X-Google-Smtp-Source: AAOMgpfOHI3+fx1c7nM2IPpqqNzaBaPFao5o7gS1SyN0Zbb98dNjJJmxKwSIkQKYBYqC04tHFb5CXQ== X-Received: by 2002:a63:c44a:: with SMTP id m10-v6mr10746652pgg.416.1532806898301; Sat, 28 Jul 2018 12:41:38 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 28 Jul 2018 23:31:45 +0530 Message-Id: <1532800907-29115-31-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532800907-29115-1-git-send-email-skrtbhtngr@gmail.com> References: <1532800907-29115-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]); Sat, 28 Jul 2018 19:41:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 28 Jul 2018 19:41:39 +0000 (UTC) for IP:'209.85.210.196' DOMAIN:'mail-pf1-f196.google.com' HELO:'mail-pf1-f196.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.210.196 mail-pf1-f196.google.com 209.85.210.196 mail-pf1-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 30/32] 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.46]); Sat, 28 Jul 2018 19:41:49 +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 --- 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 1dd14de..b51d899 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -982,16 +982,15 @@ int virProcessGetStartTime(pid_t pid, { VIR_AUTOFREE(char *) filename =3D NULL; VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOPTR(virString) tokens =3D NULL; char *tmp; - int ret =3D -1; int len; - char **tokens =3D NULL; =20 if (virAsprintf(&filename, "/proc/%llu/stat", (long long) pid) < 0) 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 @@ -1002,14 +1001,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); @@ -1018,7 +1017,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], @@ -1028,14 +1027,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