From nobody Tue May 13 11:07:57 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 1532639117465197.1043715622834; Thu, 26 Jul 2018 14:05:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 915993084047; Thu, 26 Jul 2018 21:05:15 +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 53C545ED3A; Thu, 26 Jul 2018 21:05: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 F018A18037F6; Thu, 26 Jul 2018 21:05:14 +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 w6QL4lSQ024662 for ; Thu, 26 Jul 2018 17:04:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0632116D23; Thu, 26 Jul 2018 21:04:47 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EEA8419487 for ; Thu, 26 Jul 2018 21:04:46 +0000 (UTC) Received: from mail-pl0-f65.google.com (mail-pl0-f65.google.com [209.85.160.65]) (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 B42CBC057F9F for ; Thu, 26 Jul 2018 21:04:45 +0000 (UTC) Received: by mail-pl0-f65.google.com with SMTP id s17-v6so1342034plp.7 for ; Thu, 26 Jul 2018 14:04:45 -0700 (PDT) Received: from centos.localdomain ([42.106.3.93]) by smtp.gmail.com with ESMTPSA id z10-v6sm3279182pfh.83.2018.07.26.14.04.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 14:04:44 -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=+emJQstfauwQDKbn11+aN5e433UOJyogClu+oNYg6eo=; b=TXt07V/JxN/DDouXtqN28mXhvAsr7bPqteSltN9u8gHC9k/XcGNCRIxVDGwj+/6zzH jDKnPQGNYsmbAaVXM/RFaVIWptgVutBS1cetmMHQ/GANfSmvQW5ZSGSeZ6Vhrgz8Zs9N xYykDzFmLkOa1mfxTfjNYKKBMd7MYg8WrlD32nNAELIE3oCnj3KfEK3sIwECWr8xo/ok eNMZ4ZECQSltS7lvBIj7Dv5PThlLjDCpv4W5FDS7qhJs+R2WlfN5/Ma/scQFDoNwZcz7 vSjxt3B/86FNVWYYMxbLXpnKQiXbMC7uPKBnAwCjv0t8B6ETXe+Xm0RHAfMy7KY5oO4D 48lg== 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=+emJQstfauwQDKbn11+aN5e433UOJyogClu+oNYg6eo=; b=p+6blEh8TMl6gHOPU7027jTH4w7Lez7xVwC/XTHBraM+HWVS1fJLsUIC/GPF7gVg6F gaplEuQGk3sIqW7kB9ONDmvooPHLQoaBH2DfqRraH7vgl05q9vzI8D5uDDR662qTLmu5 PplfxTEMzi7F00fSBgRUXcZJdmscWb1/zyOz2A0mqqYtPLYzjBtMqQbB2KW7/FMvJ8ag gbmyurTpTOgHgsz2E8TisPXkTcfMpgCGNdKpRKVf4U8GcgcuawPnAdkk+OVj3smkei6j biELnfPxKJht0CSsqQBFR5slw26i+60So5jczoAU0xqGoOGyVc6i/+gYwjVY50H6uUBA HDvg== X-Gm-Message-State: AOUpUlH/2PEjtHFPYrLVo7ZmvcV0BgYp3W0gc9ZrQ/qacMHgayLxkwew wXaU3tNfW/24j4Z/5KILm3BghZdz X-Google-Smtp-Source: AAOMgpd/q+lw8rpAYPKoJ+rbHm7CbcGR6kVXtYuk8K2FqPVYu/TQ37n/rlfiKYugn3DRv+Gm3jLGRQ== X-Received: by 2002:a17:902:9042:: with SMTP id w2-v6mr3402376plz.61.1532639084983; Thu, 26 Jul 2018 14:04:44 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Tue, 24 Jul 2018 21:22:05 +0530 Message-Id: <1532447562-24010-5-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532447562-24010-1-git-send-email-skrtbhtngr@gmail.com> References: <1532447562-24010-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.32]); Thu, 26 Jul 2018 21:04:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 26 Jul 2018 21:04:45 +0000 (UTC) for IP:'209.85.160.65' DOMAIN:'mail-pl0-f65.google.com' HELO:'mail-pl0-f65.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.37 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_PASS) 209.85.160.65 mail-pl0-f65.google.com 209.85.160.65 mail-pl0-f65.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 04/41] util: buffer: 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.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 26 Jul 2018 21:05:16 +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/virbuffer.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 0640cfa..f70069e 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -456,7 +456,8 @@ void virBufferEscapeString(virBufferPtr buf, const char *format, const char *st= r) { int len; - char *escaped, *out; + VIR_AUTOFREE(char *) escaped =3D NULL; + char *out; const char *cur; const char forbidden_characters[] =3D { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, @@ -533,7 +534,6 @@ virBufferEscapeString(virBufferPtr buf, const char *for= mat, const char *str) *out =3D 0; =20 virBufferAsprintf(buf, format, escaped); - VIR_FREE(escaped); } =20 /** @@ -612,7 +612,8 @@ virBufferEscape(virBufferPtr buf, char escape, const ch= ar *toescape, const char *format, const char *str) { int len; - char *escaped, *out; + VIR_AUTOFREE(char *) escaped =3D NULL; + char *out; const char *cur; =20 if ((format =3D=3D NULL) || (buf =3D=3D NULL) || (str =3D=3D NULL)) @@ -644,7 +645,6 @@ virBufferEscape(virBufferPtr buf, char escape, const ch= ar *toescape, *out =3D 0; =20 virBufferAsprintf(buf, format, escaped); - VIR_FREE(escaped); } =20 =20 @@ -689,7 +689,7 @@ virBufferEscapeN(virBufferPtr buf, { int len; size_t i; - char *escaped =3D NULL; + VIR_AUTOFREE(char *) escaped =3D NULL; char *out; const char *cur; virBufferEscapePair escapeItem; @@ -752,7 +752,6 @@ virBufferEscapeN(virBufferPtr buf, cleanup: va_end(ap); VIR_FREE(escapeList); - VIR_FREE(escaped); } =20 =20 @@ -817,7 +816,8 @@ void virBufferEscapeShell(virBufferPtr buf, const char *str) { int len; - char *escaped, *out; + VIR_AUTOFREE(char *) escaped =3D NULL; + char *out; const char *cur; =20 if ((buf =3D=3D NULL) || (str =3D=3D NULL)) @@ -861,7 +861,6 @@ virBufferEscapeShell(virBufferPtr buf, const char *str) *out =3D 0; =20 virBufferAdd(buf, escaped, -1); - VIR_FREE(escaped); } =20 /** --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list