From nobody Tue May 13 18:26: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 1530481521927948.2573516684874; Sun, 1 Jul 2018 14:45:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB18AC059B7F; Sun, 1 Jul 2018 21:45:20 +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 6EAA452FCA; Sun, 1 Jul 2018 21:45:20 +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 20A8624F5B; Sun, 1 Jul 2018 21:45:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w61LjIHe009516 for ; Sun, 1 Jul 2018 17:45:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 34C9186F95; Sun, 1 Jul 2018 21:45:18 +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 2DA7B86F19 for ; Sun, 1 Jul 2018 21:45:13 +0000 (UTC) Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) (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 84005C059B7F for ; Sun, 1 Jul 2018 21:45:02 +0000 (UTC) Received: by mail-pg0-f67.google.com with SMTP id q14-v6so6196121pgt.13 for ; Sun, 01 Jul 2018 14:45:02 -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.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Jul 2018 14:45:01 -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=L8kGehXgvwdlsF1kIazBHRKiH3s4jscaFCs8JxSc8zc=; b=m+kMdpnUfCBQQXRmt6WVp7tujJjcedfDIeZotisDWJoBellEoWLIrXRvmzTqmmZkCx DBCrfoJQdIZhp8yZxV9aXErQwsThd6+FpG4Ou90H0SInIssuJxr/nMj6iF8gN//pKFZI YKXx1qEY4+iv6myZ3o/+s4LV4DvzwfBexC7M/tuNHv25L65EpAhiINXh/3MtW4AnWl57 O4zhhjDCoL5F6NcJbxsfrzTKUF+1R9EDhVcTtoWHo5cnI8/rcPPCeHOfQCjrlclFrLR7 vbOO9rlMlLad0rhHdnpXEzrzgsnicy4Fdmv1drOU+9TvT/lQN38kxBIkvlkdeLHHmtj+ hlig== 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=L8kGehXgvwdlsF1kIazBHRKiH3s4jscaFCs8JxSc8zc=; b=N1TWH83lMw3MhS2vBISPclMl6XycpHmXZhxODeog2Jn50u+6MB+C/oa80T4TM/S3eR dY5j94ySFcW4fxTZBJ2qPiMLvXIXe0mxfEJO8jZ9O+uH0uA3nuEDPPXU9LVm7eVKed6C YA6kODukNIsxpTGNeDLA0DKRxmknDgjbkztjvtBio3Wzealjmak2SeX3fr4xgLnwU+B5 hLKEXHjJJ9J5KlUWX28eh3jt0HBIUyU4hX7EKEeE+DABUS9E+MipNvkoeIzN40oFNlJD n0gF5DIDl0sSuUpGzpaPnmcPn6/LZ+N3YJ1cPAgkYWNEmZ7yOfxLnbf2IF8PJWn1fuyU xzjg== X-Gm-Message-State: APt69E0OWOEBqsgAbbUmSaUkzyqQi1SxXQk+VFTM7SqqegTYFW6WNR5N ga/fyC6+oDiQv68fF9TlCsASUBy+ X-Google-Smtp-Source: AAOMgpf6TTsOxFZuKKwmIPVEB1PSoOKcmXseeghuPw8MdXwmVpogvKPSXTxO4lwcjFTvI+6qK2l2wQ== X-Received: by 2002:a62:e03:: with SMTP id w3-v6mr22851834pfi.173.1530481501726; Sun, 01 Jul 2018 14:45:01 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 30 Jun 2018 14:30:29 +0530 Message-Id: <1530349239-22049-26-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.32]); Sun, 01 Jul 2018 21:45:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sun, 01 Jul 2018 21:45:02 +0000 (UTC) for IP:'74.125.83.67' DOMAIN:'mail-pg0-f67.google.com' HELO:'mail-pg0-f67.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) 74.125.83.67 mail-pg0-f67.google.com 74.125.83.67 mail-pg0-f67.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 25/35] 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.79 on 10.5.11.15 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:45:21 +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 --- 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