From nobody Tue May 13 18:27:40 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 1530481492004594.7522354911893; Sun, 1 Jul 2018 14:44:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 040BCC0587E3; Sun, 1 Jul 2018 21:44:51 +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 B5185308BDA5; Sun, 1 Jul 2018 21:44:50 +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 650534BB78; Sun, 1 Jul 2018 21:44:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w61LiSYk009098 for ; Sun, 1 Jul 2018 17:44:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id A820660BE3; Sun, 1 Jul 2018 21:44:28 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9D8F660BEC for ; Sun, 1 Jul 2018 21:44:28 +0000 (UTC) Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) (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 E9AF23680B for ; Sun, 1 Jul 2018 21:44:15 +0000 (UTC) Received: by mail-pf0-f195.google.com with SMTP id l123-v6so3475222pfl.13 for ; Sun, 01 Jul 2018 14:44:15 -0700 (PDT) Received: from centos.localdomain ([157.37.164.55]) by smtp.gmail.com with ESMTPSA id v68-v6sm15006933pfv.143.2018.07.01.14.44.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Jul 2018 14:44:14 -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=lvRM8Dqj/U9Ss7FQFnHMF02vr/oSugsz8ASkCWcZ/+Q=; b=f7C1wwWGsGkRPdHdT14glWpYUfi38xqKZR/L7nFqTPafNGEQsr88L00dhOFOMX0qiG QAb2T+DePF+JY/DNwXBxbwWRMm/4E6I0WjMv2QS6nRgvmoCgcc6VXQdw381ya3RUsr9g uWJ/o1a/opvVg1o2Mpfz+ub+hNgCkIcVS7o6ibgRfuXIWmqyfHbXDyNWkJY29V0KVMGu 0LM/q+cTSi72nAvUE2zOcwU/9SFiYZimYdbxYxReEAhEU5HtIpCWRfbDEqynUhaz8mZS x/6gBsD87Vna1HpX8ysCb3ZRa/v4E3pE5DvVp36WDSGKqiJoSf0DOLAUAnNUJhZ5YASm kblQ== 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=lvRM8Dqj/U9Ss7FQFnHMF02vr/oSugsz8ASkCWcZ/+Q=; b=KT8mcatXfcD3h3xFUJy07nV16M+uDIM6a+MKxraT0Z8RL1Zb/9PZpJ49Bd0h4P+9Z6 xgxrRyTB+pszYOeAfeaIdH9yW+XT+0HtbIa3CB3xlkZBEq77N97bxcss1Xyz293ZaIRO QJwGW2whlUhpAycBPJ/JIQcoqpuJWDpVI2e6zYG1DWhis+WvKmQKmg4fqLZ1zdSNd7Mj gltIFCA7uhhGZz6oGRmDdLJZlyRBOc9mvqUDpix8kcHS1R4iRw3FtkvXJpBW3p79i83t hoYcrcqk2xieuKTN/2XZuWgA0YQ+bnQgZx5V5jq1OzrphUrG8lPTaXBSqwC3KEDjn6c1 qQjg== X-Gm-Message-State: APt69E05kxM779PgKFow15Ab1aI5xIjFYubogfvKm6aV0ytxoy8uSCHS G1LEKKZH4FDxPi0W2UUARhuYWMh/ X-Google-Smtp-Source: AAOMgpeab8Xdkr6+k32K5DVzAAOpnNB7G9zQJDJMjF1GS5QIW3IPHAPp2Qinj5sh8Z8AQ84f+QlpIA== X-Received: by 2002:a63:5c10:: with SMTP id q16-v6mr1038235pgb.452.1530481455214; Sun, 01 Jul 2018 14:44:15 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 30 Jun 2018 14:30:14 +0530 Message-Id: <1530349239-22049-11-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1530349239-22049-1-git-send-email-skrtbhtngr@gmail.com> References: <1530349239-22049-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.30]); Sun, 01 Jul 2018 21:44:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sun, 01 Jul 2018 21:44:16 +0000 (UTC) for IP:'209.85.192.195' DOMAIN:'mail-pf0-f195.google.com' HELO:'mail-pf0-f195.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.785 * (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.192.195 mail-pf0-f195.google.com 209.85.192.195 mail-pf0-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 10/35] 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.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sun, 01 Jul 2018 21:44:51 +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