From nobody Tue Jul 1 05:36:49 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 1531504577934176.91998750951598; Fri, 13 Jul 2018 10:56:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 54FB036A5DC; Fri, 13 Jul 2018 17:56:15 +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 17AC5C6A3B; Fri, 13 Jul 2018 17:56:15 +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 A6517239; Fri, 13 Jul 2018 17:56:14 +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 w6DHtoXD008406 for ; Fri, 13 Jul 2018 13:55:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id C6C25C6A37; Fri, 13 Jul 2018 17:55:50 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BF784BEDEB for ; Fri, 13 Jul 2018 17:55:47 +0000 (UTC) Received: from mail-pf0-f177.google.com (mail-pf0-f177.google.com [209.85.192.177]) (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 027D080F94 for ; Fri, 13 Jul 2018 17:55:36 +0000 (UTC) Received: by mail-pf0-f177.google.com with SMTP id b17-v6so23044263pfi.0 for ; Fri, 13 Jul 2018 10:55:35 -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.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:34 -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=hM9uYfHjM62FsCCW/JxHbsTPrbD80F2iJr2v4NDBzhg=; b=UDpZgPVIibNSd8BkKc0EhBvRnL6jIbjF3aVRQJY6PYrAZXo8MsuabLIco5OAreFzWd JDWj3XpTPlBJ47EZiDUkzeyPmUowyOw6G99nJnIM4vSkGqv8nPp+0NVjR5Z5HzmmGx2u goFgFOez0X/50XfpIwQwNrUzomrTKvBfm51d2vvM+w4F/JK8vi4PEeqU2CCSLMf68akH J3+EyC8A6tAOgQq5iw/y7SQ3wIYbk2eRnmVZnoHSW8tv5H+7SWfGHJj5RVZ3iXGIdUZA Tmv5sCvCc5vQI5cPkZeaic4F4twt/UCjY0Z5AprS9IWJsS5J4NhSDM3Z5i1yGYhpPsOI /N9w== 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=hM9uYfHjM62FsCCW/JxHbsTPrbD80F2iJr2v4NDBzhg=; b=t9F3MIlJK7hRiIdL7Ku+fXexESu9FcOYYCoVdPgnxpjssPnvsr7XUiXcg2uIo76dWU UkEnjmmDdaRutjjzHsRp3bCYWQOl7vhyvjif492sYRy2MeGtQqzFB1w9QIS8EPKB3fBj 2km3yK9U6P7U6xu91Rbej7dmc/9XtwSLBX78lWzn2uZDBenK1qbuKDJOUnm9elTRN2ur KmjeS+WGta/zfc/TYGb4roZMKbbFM3gGXCXyobyKO9byU5gjfIdDnWw0d0SNk9Oii/z0 oa8iKsbA9WONMrVLJdfZZrOZtyOlQb6pxQuAP8Y3GWwyErIKv7LN/MrmElZEe1e1lUiw Ug3A== X-Gm-Message-State: AOUpUlHNp24INTuzaVtXRxp/L0MxkG9EkAqhDa044TiUfINsBv9eDImx vxqdF3RZIYmveDiQdmLB3p5JE8Qe X-Google-Smtp-Source: AAOMgpcBpkGS3aUScmZbuSWnLC1dR5fSU7A4WahwyU8dzCi7XAaQUBppjxS4f3/gk/KqMKah838r4w== X-Received: by 2002:a63:943:: with SMTP id 64-v6mr6861545pgj.368.1531504535208; Fri, 13 Jul 2018 10:55:35 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:44 +0530 Message-Id: <1531504509-7930-7-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.27]); Fri, 13 Jul 2018 17:55:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 13 Jul 2018 17:55:36 +0000 (UTC) for IP:'209.85.192.177' DOMAIN:'mail-pf0-f177.google.com' HELO:'mail-pf0-f177.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.192.177 mail-pf0-f177.google.com 209.85.192.177 mail-pf0-f177.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 06/31] util: command: 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 13 Jul 2018 17:56:17 +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_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 Reviewed-by: Erik Skultety --- src/util/vircommand.c | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 8681e7b..d328431 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -507,11 +507,11 @@ virExec(virCommandPtr cmd) int childout =3D -1; int childerr =3D -1; int tmpfd; - char *binarystr =3D NULL; + VIR_AUTOFREE(char *) binarystr =3D NULL; const char *binary =3D NULL; int ret; struct sigaction waxon, waxoff; - gid_t *groups =3D NULL; + VIR_AUTOFREE(gid_t *) groups =3D NULL; int ngroups; =20 if (cmd->args[0][0] !=3D '/') { @@ -604,9 +604,6 @@ virExec(virCommandPtr cmd) =20 cmd->pid =3D pid; =20 - VIR_FREE(groups); - VIR_FREE(binarystr); - return 0; } =20 @@ -796,9 +793,6 @@ virExec(virCommandPtr cmd) /* This is cleanup of parent process only - child should never jump here on error */ =20 - VIR_FREE(binarystr); - VIR_FREE(groups); - /* NB we don't virReportError() on any failures here because the code which jumped here already raised an error condition which we must not overwrite */ @@ -2386,7 +2380,7 @@ int virCommandRunAsync(virCommandPtr cmd, pid_t *pid) { int ret =3D -1; - char *str =3D NULL; + VIR_AUTOFREE(char *) str =3D NULL; size_t i; bool synchronous =3D false; int infd[2] =3D {-1, -1}; @@ -2511,7 +2505,6 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid) VIR_FORCE_CLOSE(cmd->infd); VIR_FORCE_CLOSE(cmd->inpipe); } - VIR_FREE(str); return ret; } =20 @@ -2588,8 +2581,8 @@ virCommandWait(virCommandPtr cmd, int *exitstatus) if (exitstatus && (cmd->rawStatus || WIFEXITED(status))) { *exitstatus =3D cmd->rawStatus ? status : WEXITSTATUS(status); } else if (status) { - char *str =3D virCommandToString(cmd); - char *st =3D virProcessTranslateStatus(status); + VIR_AUTOFREE(char *) str =3D virCommandToString(cmd); + VIR_AUTOFREE(char *) st =3D virProcessTranslateStatus(status); bool haveErrMsg =3D cmd->errbuf && *cmd->errbuf && (*cmd->errb= uf)[0]; =20 virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2597,8 +2590,6 @@ virCommandWait(virCommandPtr cmd, int *exitstatus) str ? str : cmd->args[0], NULLSTR(st), haveErrMsg ? ": " : "", haveErrMsg ? *cmd->errbuf : ""); - VIR_FREE(str); - VIR_FREE(st); return -1; } } @@ -2718,7 +2709,7 @@ int virCommandHandshakeWait(virCommandPtr cmd) return -1; } if (c !=3D '1') { - char *msg; + VIR_AUTOFREE(char *) msg =3D NULL; ssize_t len; if (VIR_ALLOC_N(msg, 1024) < 0) { VIR_FORCE_CLOSE(cmd->handshakeWait[0]); @@ -2731,7 +2722,6 @@ int virCommandHandshakeWait(virCommandPtr cmd) =20 if ((len =3D saferead(cmd->handshakeWait[0], msg, 1024)) < 0) { VIR_FORCE_CLOSE(cmd->handshakeWait[0]); - VIR_FREE(msg); virReportSystemError(errno, "%s", _("No error message from child failure")); return -1; @@ -2739,7 +2729,6 @@ int virCommandHandshakeWait(virCommandPtr cmd) VIR_FORCE_CLOSE(cmd->handshakeWait[0]); msg[len-1] =3D '\0'; virReportError(VIR_ERR_INTERNAL_ERROR, "%s", msg); - VIR_FREE(msg); return -1; } VIR_FORCE_CLOSE(cmd->handshakeWait[0]); @@ -2853,8 +2842,8 @@ virCommandFree(virCommandPtr cmd) * This requests asynchronous string IO on @cmd. It is useful in * combination with virCommandRunAsync(): * - * virCommandPtr cmd =3D virCommandNew*(...); - * char *buf =3D NULL; + * VIR_AUTOPTR(virCommand) cmd =3D virCommandNew*(...); + * VIR_AUTOFREE(char *) buf =3D NULL; * * ... * @@ -2862,21 +2851,18 @@ virCommandFree(virCommandPtr cmd) * virCommandDoAsyncIO(cmd); * * if (virCommandRunAsync(cmd, NULL) < 0) - * goto cleanup; + * return; * * ... * * if (virCommandWait(cmd, NULL) < 0) - * goto cleanup; + * return; * * // @buf now contains @cmd's stdout * VIR_DEBUG("STDOUT: %s", NULLSTR(buf)); * * ... * - * cleanup: - * VIR_FREE(buf); - * virCommandFree(cmd); * * The libvirt's event loop is used for handling stdios of @cmd. * Since current implementation uses strlen to determine length @@ -2969,11 +2955,11 @@ virCommandRunRegex(virCommandPtr cmd, { int err; regex_t *reg; - regmatch_t *vars =3D NULL; + VIR_AUTOFREE(regmatch_t *) vars =3D NULL; size_t i, j, k; int totgroups =3D 0, ngroup =3D 0, maxvars =3D 0; char **groups; - char *outbuf =3D NULL; + VIR_AUTOFREE(char *) outbuf =3D NULL; char **lines =3D NULL; int ret =3D -1; =20 @@ -3054,13 +3040,11 @@ virCommandRunRegex(virCommandPtr cmd, ret =3D 0; cleanup: virStringListFree(lines); - VIR_FREE(outbuf); if (groups) { for (j =3D 0; j < totgroups; j++) VIR_FREE(groups[j]); VIR_FREE(groups); } - VIR_FREE(vars); =20 for (i =3D 0; i < nregex; i++) regfree(®[i]); --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list