From nobody Tue Jul 1 05:38:13 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 1531504589225449.7704927399061; Fri, 13 Jul 2018 10:56:29 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 629C1307D84F; Fri, 13 Jul 2018 17:56:27 +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 234562010D58; Fri, 13 Jul 2018 17:56:27 +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 C345D1800BA6; Fri, 13 Jul 2018 17:56:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHuK4h008921 for ; Fri, 13 Jul 2018 13:56:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 54499171E7; Fri, 13 Jul 2018 17:56:20 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 45CC45C70F for ; Fri, 13 Jul 2018 17:56:15 +0000 (UTC) Received: from mail-pf0-f176.google.com (mail-pf0-f176.google.com [209.85.192.176]) (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 0BBCB859FF for ; Fri, 13 Jul 2018 17:56:04 +0000 (UTC) Received: by mail-pf0-f176.google.com with SMTP id l9-v6so11409254pff.9 for ; Fri, 13 Jul 2018 10:56:04 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.56.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:56:02 -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=wLlCUfUoVWYAvUPitpx7zeGKOCttlgsmnxY4d8zua6w=; b=Z3+UQ6qwbXxvI1/gzX2JlnX1/le7hCYPZt+r4C728iJ90Ww9HyUwUiXOjO7P/efapG lix+6HNHrb1D8ZC40ei9jP0VG8KOeJj/yHgJNn0UAMWIY6klGgIrwHOTM8fCJEYYyKcr UEsH2lL+IYlxtqK2DXwJZ+RXWwfh+yVgBlbC251Hi6LbtSf8WhriJPOUWpUwE/rLf/Di ls88PTrWnl9Dwaro0bosDR1EJLEWM31pYipIzF9+c8EzWZ6bbjkfQLo3B5E12uUDt/Gh zSyfSy3LJuSmHAj0f3uzxHG/7/3wzMPMF3anJJ/vj+b4QQRJE01Pz2kYUMBQc+1bBkfZ 5CaA== 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=wLlCUfUoVWYAvUPitpx7zeGKOCttlgsmnxY4d8zua6w=; b=oK6X8AnaxEERx/NNENxRyQ04wFOVMHGVuHCOqzOfrvcM8qZOcoEmY7n0Xyk6zuURcZ mdg+1OK5a9AWfAzbvybbGxOACwF9f8SsgvJxQmDQjgN7/KXxxYUH79g7MVNENvfGcla5 PVHCbXTHND4PGGXHh2i7pmGdvaCML6gAa4kQyotnteDhl82/xEPhb3azo5lq29UUDDe4 6hcUlzvXxA2fprpBoLiaGgAoE7KJ1dIzabEH+VSSg4vywzBI2eMK8VJ8CcgFJcDPnHhW sVYemqiYdFaRZ4bwrEmjZrwpXC9XN9hdnbSsIxz9v7LWDUluJ9y7vzW9BtdPKnLUmzUK lwXw== X-Gm-Message-State: AOUpUlHXtEBYqcJqnWDJNsz7p7EsaJewd5c/S13Bmgq4iPY6VDd3M3Fj tsrVaI9TLLm1+VUfxd2tP6ShsD3x X-Google-Smtp-Source: AAOMgpfemkfdr0UDNoVlveKrVD/r+BjnW1Y0ggNNx6k6elPj24dEWDV/OMQdfQC9k1gdeDmG8YEGFw== X-Received: by 2002:a62:283:: with SMTP id 125-v6mr8111159pfc.51.1531504563153; Fri, 13 Jul 2018 10:56:03 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:59 +0530 Message-Id: <1531504509-7930-22-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.26]); Fri, 13 Jul 2018 17:56:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 13 Jul 2018 17:56:04 +0000 (UTC) for IP:'209.85.192.176' DOMAIN:'mail-pf0-f176.google.com' HELO:'mail-pf0-f176.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.176 mail-pf0-f176.google.com 209.85.192.176 mail-pf0-f176.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 21/31] util: json: use VIR_AUTOPTR for aggregate 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.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 13 Jul 2018 17:56:28 +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_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions 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/virjson.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 82f539f..29530dc 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1786,7 +1786,7 @@ virJSONValueFromString(const char *jsonstring) size_t len =3D strlen(jsonstring); # ifndef WITH_YAJL2 yajl_parser_config cfg =3D { 0, 1 }; /* Match yajl 2 default behavior = */ - virJSONValuePtr tmp; + VIR_AUTOPTR(virJSONValue) tmp =3D NULL; # endif =20 VIR_DEBUG("string=3D%s", jsonstring); @@ -1850,7 +1850,6 @@ virJSONValueFromString(const char *jsonstring) jsonstring); else ret =3D virJSONValueArraySteal(tmp, 0); - virJSONValueFree(tmp); # endif } =20 @@ -2023,16 +2022,12 @@ char * virJSONStringReformat(const char *jsonstr, bool pretty) { - virJSONValuePtr json; - char *ret; + VIR_AUTOPTR(virJSONValue) json =3D NULL; =20 if (!(json =3D virJSONValueFromString(jsonstr))) return NULL; =20 - ret =3D virJSONValueToString(json, pretty); - - virJSONValueFree(json); - return ret; + return virJSONValueToString(json, pretty); } =20 =20 @@ -2121,7 +2116,7 @@ virJSONValueObjectDeflattenWorker(const char *key, virJSONValuePtr virJSONValueObjectDeflatten(virJSONValuePtr json) { - virJSONValuePtr deflattened; + VIR_AUTOPTR(virJSONValue) deflattened =3D NULL; virJSONValuePtr ret =3D NULL; =20 if (!(deflattened =3D virJSONValueNewObject())) @@ -2130,12 +2125,9 @@ virJSONValueObjectDeflatten(virJSONValuePtr json) if (virJSONValueObjectForeachKeyValue(json, virJSONValueObjectDeflattenWorke= r, deflattened) < 0) - goto cleanup; + return NULL; =20 VIR_STEAL_PTR(ret, deflattened); =20 - cleanup: - virJSONValueFree(deflattened); - return ret; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list