From nobody Wed May 14 01:24:23 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 1528124448225710.8402342669248; Mon, 4 Jun 2018 08:00:48 -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 D848E387D84; Mon, 4 Jun 2018 15:00:45 +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 650EA30BD340; Mon, 4 Jun 2018 15:00:45 +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 EF47D18033EF; Mon, 4 Jun 2018 15:00:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w54Ean4Y008114 for ; Mon, 4 Jun 2018 10:36:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id D84BA600D1; Mon, 4 Jun 2018 14:36:49 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D0003600CC for ; Mon, 4 Jun 2018 14:36:49 +0000 (UTC) Received: from mail-pl0-f68.google.com (mail-pl0-f68.google.com [209.85.160.68]) (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 22BDF3153785 for ; Mon, 4 Jun 2018 14:36:38 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id n10-v6so19840589plp.0 for ; Mon, 04 Jun 2018 07:36:38 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36:36 -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=FJzwz3jFDWZzBqA2Xps0+kRI380uwzkw/ZP+6aJqjaQ=; b=rGgPaqzp9b8vD6vHQGry9WgRAx+vdAbE6zYSVZK1XU+9DidtaK7S18WAkGxlZgskX6 NqL2CFmKxhD4IAHnC0JpddfQGAukEm0DDz2Jy0IQO2XoxLDo/juOxuFwvRO1x1SW+QTe 35XAd0PMmJYhYLMciTjTnw/SPGnCmACyGOArfl7+gEJoavUW5Jh1+Q1kfofV41Q9qGq8 rh+GiWYJ9ekZ7rDn1SBViCHwZd/PqK1g0vvjmT+wPm1H38i1isHfTPItfjIusIX5OUWa lGNM9FtNTkxkvigqvpTDSMTY0UibaNzX4E582n4KKl6QQ1VJKS+f7fTSnEm+BWgMZqPR xZZA== 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=FJzwz3jFDWZzBqA2Xps0+kRI380uwzkw/ZP+6aJqjaQ=; b=bHOp880pu40k+ehMJeanYHktWoaQ06HB64xpPcGfAjo72aKZ9cv1e5DJwrZLk36xkp qqnAfe/2cKPAovQML5zN9dFiHPKHLhGxLYeQLICG5Xb944S31Vg0kud5yVBI3fu/KIpm Z/bPn6ZAbi5kBaK+yQfII7xL5+IbSAlouvEOWizjrhclDaQDTsveyULgn0ZcKiXJXw2u aQT1/DFmCQnQQZAQLnRDQHgyNmrELcWuGYBIa2RdMaRS8NBEsEIkqY9SAIE0APQA7n6v IoG9h4Zg9CGBsrNByWxA0gg7IrBDFkgW5g++HagFdBk0q1R7yd5gqxFbXLEnZ1JO9NJR uH/Q== X-Gm-Message-State: ALKqPwc4L6I6UiQHOCb7SlJuVBdsUou+L69Y53sKviyFS246cins1kNi p4GV1mHcec3yLkgPT5WNf/fD388+ X-Google-Smtp-Source: ADUXVKLZaL/w94WhFDPm7fNgo1VqhQ31on7DYBqoAoRB87mzlcVd60/1XXIcon9h4CHrStBm+8IZZg== X-Received: by 2002:a17:902:246a:: with SMTP id m39-v6mr13345312plg.141.1528122997128; Mon, 04 Jun 2018 07:36:37 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:05 +0530 Message-Id: <1528013536-22196-8-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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.49]); Mon, 04 Jun 2018 14:36:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 04 Jun 2018 14:36:38 +0000 (UTC) for IP:'209.85.160.68' DOMAIN:'mail-pl0-f68.google.com' HELO:'mail-pl0-f68.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.766 * (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.160.68 mail-pl0-f68.google.com 209.85.160.68 mail-pl0-f68.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 07/18] use VIR_AUTOFREE in src/util/virbuffer.c 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.29]); Mon, 04 Jun 2018 15:00:46 +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" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- src/util/virbuffer.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 3d6defb..5152f73 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 @@ -675,11 +675,11 @@ virBufferEscapeN(virBufferPtr buf, { int len; size_t i; - char *escaped =3D NULL; + VIR_AUTOFREE(char *) escaped =3D NULL; char *out; const char *cur; struct _virBufferEscapePair escapeItem; - struct _virBufferEscapePair *escapeList =3D NULL; + VIR_AUTOFREE(struct _virBufferEscapePair *) escapeList =3D NULL; size_t nescapeList =3D 0; va_list ap; =20 @@ -696,7 +696,8 @@ virBufferEscapeN(virBufferPtr buf, while ((escapeItem.escape =3D va_arg(ap, int))) { if (!(escapeItem.toescape =3D va_arg(ap, char *))) { virBufferSetError(buf, errno); - goto cleanup; + va_end(ap); + return; } =20 if (strcspn(str, escapeItem.toescape) =3D=3D len) @@ -704,19 +705,22 @@ virBufferEscapeN(virBufferPtr buf, =20 if (VIR_APPEND_ELEMENT_QUIET(escapeList, nescapeList, escapeItem) = < 0) { virBufferSetError(buf, errno); - goto cleanup; + va_end(ap); + return; } } =20 if (nescapeList =3D=3D 0) { virBufferAsprintf(buf, format, str); - goto cleanup; + va_end(ap); + return; } =20 if (xalloc_oversized(2, len) || VIR_ALLOC_N_QUIET(escaped, 2 * len + 1) < 0) { virBufferSetError(buf, errno); - goto cleanup; + va_end(ap); + return; } =20 cur =3D str; @@ -734,11 +738,6 @@ virBufferEscapeN(virBufferPtr buf, *out =3D 0; =20 virBufferAsprintf(buf, format, escaped); - - cleanup: - va_end(ap); - VIR_FREE(escapeList); - VIR_FREE(escaped); } =20 =20 @@ -803,7 +802,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)) @@ -847,7 +847,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