From nobody Mon Dec 15 23:27:42 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 1532639135860862.9109112581679; Thu, 26 Jul 2018 14:05:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A87673086275; Thu, 26 Jul 2018 21:05:33 +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 5E7586017E; Thu, 26 Jul 2018 21:05:33 +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 0CBB83D3BE; Thu, 26 Jul 2018 21:05:33 +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 w6QL4kQs024657 for ; Thu, 26 Jul 2018 17:04:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 82A5B16D23; Thu, 26 Jul 2018 21:04:46 +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 7B0D319487 for ; Thu, 26 Jul 2018 21:04:44 +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 F300CC0587CE for ; Thu, 26 Jul 2018 21:04:42 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id f6-v6so1350023plo.1 for ; Thu, 26 Jul 2018 14:04:42 -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.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 14:04:41 -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=saKLeHUBPj1hmyVG7gvG6nZzEOFu5LWOYUZ53fvGZJI=; b=I8JLKNZeEp2vIifZXi2HhzXGHYDDojoy/eEb41KffRiVn0khxCO3RkJXu7AuXIXVpD hYcsDgFfHhZkIC9HskEzJXJIdoPjSAu5DDb0okswiKCZb3kSavuyVH2M7uIRRSZJTWj/ u0qmN4rhG4jdGOG6tPrcsYWjqQcB/H78Lm82SxKZJF+An9kSf9UMxbZKIWe4oTLPpi75 bduUI6ZC85ZKRINDJlux/ksUxX6L7ez+1M/39jYr8S/Deo0ghdHjyKNm+jy6bwDh52i8 rx1E80gTbOIB87sY1MaHx26q0lTUiepDFQVlCn9uoABmpA+fX22HB7K5RpW+Gi7kypPh 5b3A== 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=saKLeHUBPj1hmyVG7gvG6nZzEOFu5LWOYUZ53fvGZJI=; b=VsKoN9pmqwOWOsIGxehTh/ki4omNeAeiutyBqcTsPeCN9qc2jkWgAuRsidR1fPB932 5gA7dW5TV4cLG7uR4XZR2g4rAqG4MERnqlt1JoVGL6Ma5R07OCON7FagYdYTwJcvAcmG WHk3r4ui8w2wQeM7Lm0dQ+AagwOjtaqA1fqc16xrZpIjFubRfjnzAL1BV2ns878xbxAQ G1nmkLQ4grgJGAix02IRzzGqFaaoKKEvKvCho5KgD4uilqDMdqMt9UFBcwkmsk+bAdcq 37FlYK4ZTAOL10FVLcULyBWXIx/xOb8hhwtJhC69T3K60OXk1/0o6Ifa2SeiLg7X+EuL hmcg== X-Gm-Message-State: AOUpUlFhaETSr7T9sk5lggsS7/7n9N82AyoR5cp4zJX/g5GKrZ1usooT hK0DAGE/G2CRV/Ju/0u/eIp9c/+6 X-Google-Smtp-Source: AAOMgpeRJqNAD7mWE4QOrbfKd5wvQWjJCQwIXqwOxV9jdOUkxwjwjOk63qG/YIESRIbzqgYefLATFw== X-Received: by 2002:a17:902:bd44:: with SMTP id b4-v6mr3429048plx.144.1532639082237; Thu, 26 Jul 2018 14:04:42 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Tue, 24 Jul 2018 21:22:04 +0530 Message-Id: <1532447562-24010-4-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:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 26 Jul 2018 21:04:43 +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.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.68 mail-pl0-f68.google.com 209.85.160.68 mail-pl0-f68.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 03/41] util: buffer: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 26 Jul 2018 21:05:34 +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" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When variables of type virBufferPtr and virBufferEscapePairPtr are declared using VIR_AUTOPTR, the functions virBufferFreeAndReset and virBufferEscapePairFree, respectively, will be run automatically on them when they go out of scope. Signed-off-by: Sukrit Bhatnagar --- src/util/virbuffer.c | 16 ++++++++++++++-- src/util/virbuffer.h | 9 +++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index ea96704..0640cfa 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -31,10 +31,10 @@ #define __VIR_BUFFER_C__ =20 #include "virbuffer.h" -#include "viralloc.h" #include "virerror.h" #include "virstring.h" =20 +#define VIR_FROM_THIS VIR_FROM_NONE =20 /* If adding more fields, ensure to edit buf.h to match the number of fields */ @@ -656,6 +656,18 @@ struct _virBufferEscapePair { char *toescape; }; =20 +static void +virBufferEscapePairFree(virBufferEscapePairPtr pair) +{ + if (!pair) + return; + + VIR_FREE(pair->toescape); + VIR_FREE(pair); +} +VIR_DEFINE_AUTOPTR_FUNC(virBufferEscapePair, virBufferEscapePairFree) + + /** * virBufferEscapeN: * @buf: the buffer to append to @@ -696,7 +708,7 @@ virBufferEscapeN(virBufferPtr buf, va_start(ap, str); =20 while ((escapeItem.escape =3D va_arg(ap, int))) { - if (!(escapeItem.toescape =3D va_arg(ap, char *))) { + if (VIR_STRDUP(escapeItem.toescape, va_arg(ap, char *)) < 0) { virBufferSetError(buf, errno); goto cleanup; } diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index e95ee87..3b31060 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -23,10 +23,13 @@ #ifndef __VIR_BUFFER_H__ # define __VIR_BUFFER_H__ =20 -# include "internal.h" - # include =20 +# include "internal.h" + +# include "viralloc.h" + + /** * virBuffer: * @@ -119,4 +122,6 @@ int virBufferGetIndent(const virBuffer *buf, bool dynam= ic); void virBufferTrim(virBufferPtr buf, const char *trim, int len); void virBufferAddStr(virBufferPtr buf, const char *str); =20 +VIR_DEFINE_AUTOPTR_FUNC(virBuffer, virBufferFreeAndReset) + #endif /* __VIR_BUFFER_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list