From nobody Sat Feb 7 05:35:23 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 1533714277636879.6288116486503; Wed, 8 Aug 2018 00:44:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6EE341B7F; Wed, 8 Aug 2018 07:44:35 +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 2A4B33001A65; Wed, 8 Aug 2018 07:44:35 +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 B351B24602; Wed, 8 Aug 2018 07:44:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w787iThR006058 for ; Wed, 8 Aug 2018 03:44:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4E11ACBD6B; Wed, 8 Aug 2018 07:44:29 +0000 (UTC) Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3CEC0CD6AB for ; Wed, 8 Aug 2018 07:44:19 +0000 (UTC) Received: from mail-pl0-f47.google.com (mail-pl0-f47.google.com [209.85.160.47]) (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 F1D3430820E4 for ; Wed, 8 Aug 2018 07:44:17 +0000 (UTC) Received: by mail-pl0-f47.google.com with SMTP id g6-v6so655009plq.9 for ; Wed, 08 Aug 2018 00:44:17 -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.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:44:16 -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=6/T5fx/nOf0Nfb0EKHp82mo0Bc+N6MYHKYHXZ5Qqc4o=; b=tB3hRQDSqHlsJthewXXuk2+FU2Zeccdub86u19jBsRmB919f9ezx1QRTSu122dyIsv eHi67kzGgp4jE6v0/gYJUe4iOsm+JIY1t50iCZSGRHoBN5l6vB66FcvRdrhsAvcVBJO3 mO5M/HytmceqBdoElV2iSg/eJmwCmUkZz5RCdo2g18yQTsrV055OpY7aOZF0MAoqWdLB e66RxwKbFJZBxKhwfstPjh7u1rDaHQZ5pC+orL/HkBk5Ojj25XWmLOQbIKmEu5Dx+z+C AAR1uvUnrf2wfHa8NVJItCcVxMII+BPvrpRpdzqfQSCxfxV7OwW/3fJ4XKUQSdXok0i9 yJQw== 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=6/T5fx/nOf0Nfb0EKHp82mo0Bc+N6MYHKYHXZ5Qqc4o=; b=uQnevJPZAD7D5MIe0YLn04fziCdpohxeteD035m42W92nXgwHA/kTT1CImL/a1KxLq rUkGvk83In4fdn3XGNcA8bFemNDIThG+c3z6VPnYk34DoEwNfGNKzVRO7H0hMAuMgwta mgr3dfjlHHlwGJ33L72JNr3KVc+svJhtK0R+VaAMNcj2qOfJqboreqnaqN9V45baML9Z xcDOYnJDLcec6qyAAcyS+SIG04SURoTrpCjach8P0KX59If7qgMQ9f0e1TBlQXAcm8su hzoCaaehwezlPT2nwsY+vbFOzdcefGX1bn2qpJMMF1/CwccRYvUgAHuF6gS2HZzUN+wO yFZg== X-Gm-Message-State: AOUpUlGtLwTkewrEQkhbE85KUE4H1aJ3iUsO0T3TgyQxa4PG2he58wCA +ey5GQVFMkuRnWAsoomBoftCoMFm X-Google-Smtp-Source: AA+uWPym7F5Kna6y9y6EbOwRTOSZhYierizHtOh2aLwMBQF/JxwNmDe5kq5ZaxxX5S/qPJj6JtMoPw== X-Received: by 2002:a17:902:2f84:: with SMTP id t4-v6mr1492111plb.87.1533714257194; Wed, 08 Aug 2018 00:44:17 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:59 +0530 Message-Id: <1533501842-24503-33-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.47]); Wed, 08 Aug 2018 07:44:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 08 Aug 2018 07:44:18 +0000 (UTC) for IP:'209.85.160.47' DOMAIN:'mail-pl0-f47.google.com' HELO:'mail-pl0-f47.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.160.47 mail-pl0-f47.google.com 209.85.160.47 mail-pl0-f47.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 32/35] util: process: use VIR_AUTOFREE instead of VIR_FREE for scalar 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.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 08 Aug 2018 07:44:36 +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_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls 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 | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index f92b0dc..215e05d 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -158,7 +158,7 @@ virProcessAbort(pid_t pid) int saved_errno; int ret; int status; - char *tmp =3D NULL; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 if (pid <=3D 0) return; @@ -199,7 +199,6 @@ virProcessAbort(pid_t pid) VIR_DEBUG("failed to reap child %lld, abandoning it", (long long) pid); =20 cleanup: - VIR_FREE(tmp); errno =3D saved_errno; } #else @@ -238,6 +237,7 @@ virProcessWait(pid_t pid, int *exitstatus, bool raw) { int ret; int status; + VIR_AUTOFREE(char *) st =3D NULL; =20 if (pid <=3D 0) { if (pid !=3D -1) @@ -270,13 +270,10 @@ virProcessWait(pid_t pid, int *exitstatus, bool raw) return 0; =20 error: - { - char *st =3D virProcessTranslateStatus(status); - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Child process (%lld) unexpected %s"), - (long long) pid, NULLSTR(st)); - VIR_FREE(st); - } + st =3D virProcessTranslateStatus(status); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Child process (%lld) unexpected %s"), + (long long) pid, NULLSTR(st)); return -1; } =20 @@ -603,7 +600,7 @@ virProcessGetAffinity(pid_t pid ATTRIBUTE_UNUSED) int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids) { int ret =3D -1; - char *taskPath =3D NULL; + VIR_AUTOFREE(char *) taskPath =3D NULL; DIR *dir =3D NULL; int value; struct dirent *ent; @@ -636,7 +633,6 @@ int virProcessGetPids(pid_t pid, size_t *npids, pid_t *= *pids) =20 cleanup: VIR_DIR_CLOSE(dir); - VIR_FREE(taskPath); if (ret < 0) VIR_FREE(*pids); return ret; @@ -648,7 +644,6 @@ int virProcessGetNamespaces(pid_t pid, int **fdlist) { int ret =3D -1; - char *nsfile =3D NULL; size_t i =3D 0; const char *ns[] =3D { "user", "ipc", "uts", "net", "pid", "mnt" }; =20 @@ -656,6 +651,7 @@ int virProcessGetNamespaces(pid_t pid, *fdlist =3D NULL; =20 for (i =3D 0; i < ARRAY_CARDINALITY(ns); i++) { + VIR_AUTOFREE(char *) nsfile =3D NULL; int fd; =20 if (virAsprintf(&nsfile, "/proc/%llu/ns/%s", @@ -671,14 +667,11 @@ int virProcessGetNamespaces(pid_t pid, =20 (*fdlist)[(*nfdlist)-1] =3D fd; } - - VIR_FREE(nsfile); } =20 ret =3D 0; =20 cleanup: - VIR_FREE(nsfile); if (ret < 0) { for (i =3D 0; i < *nfdlist; i++) VIR_FORCE_CLOSE((*fdlist)[i]); @@ -977,12 +970,12 @@ virProcessSetMaxCoreSize(pid_t pid ATTRIBUTE_UNUSED, int virProcessGetStartTime(pid_t pid, unsigned long long *timestamp) { - char *filename =3D NULL; - char *buf =3D NULL; char *tmp; int ret =3D -1; int len; char **tokens =3D NULL; + VIR_AUTOFREE(char *) filename =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; =20 if (virAsprintf(&filename, "/proc/%llu/stat", (long long) pid) < 0) return -1; @@ -1032,8 +1025,6 @@ int virProcessGetStartTime(pid_t pid, =20 cleanup: virStringListFree(tokens); - VIR_FREE(filename); - VIR_FREE(buf); return ret; } #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) @@ -1080,7 +1071,7 @@ static int virProcessNamespaceHelper(int errfd, virProcessNamespaceCallback cb, void *opaque) { - char *path; + VIR_AUTOFREE(char *) path =3D NULL; int fd =3D -1; int ret =3D -1; =20 @@ -1109,7 +1100,6 @@ static int virProcessNamespaceHelper(int errfd, ignore_value(safewrite(errfd, err->message, len)); } } - VIR_FREE(path); VIR_FORCE_CLOSE(fd); return ret; } @@ -1145,7 +1135,7 @@ virProcessRunInMountNamespace(pid_t pid, VIR_FORCE_CLOSE(errfd[1]); _exit(ret < 0 ? EXIT_CANCELED : ret); } else { - char *buf =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; int status; =20 VIR_FORCE_CLOSE(errfd[1]); @@ -1159,7 +1149,6 @@ virProcessRunInMountNamespace(pid_t pid, NULLSTR(buf)); } } - VIR_FREE(buf); } =20 cleanup: @@ -1226,7 +1215,7 @@ virProcessNamespaceAvailable(unsigned int ns) int flags =3D 0; int cpid; char *childStack; - char *stack; + VIR_AUTOFREE(char *)stack =3D NULL; int stacksize =3D getpagesize() * 4; =20 if (ns & VIR_PROCESS_NAMESPACE_MNT) @@ -1251,7 +1240,7 @@ virProcessNamespaceAvailable(unsigned int ns) childStack =3D stack + stacksize; =20 cpid =3D clone(virProcessDummyChild, childStack, flags, NULL); - VIR_FREE(stack); + if (cpid < 0) { char ebuf[1024] ATTRIBUTE_UNUSED; VIR_DEBUG("clone call returned %s, container support is not enable= d", --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list