From nobody Tue May 13 18:39:36 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 1530481523835415.2440918297257; Sun, 1 Jul 2018 14:45:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AE1CB81DEB; Sun, 1 Jul 2018 21:45:22 +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 76573308BDA7; Sun, 1 Jul 2018 21:45:22 +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 2BA9624F57; Sun, 1 Jul 2018 21:45:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w61LjFAg009484 for ; Sun, 1 Jul 2018 17:45:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9DDD82010CC5; Sun, 1 Jul 2018 21:45:15 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92DF72010CA6 for ; Sun, 1 Jul 2018 21:45:12 +0000 (UTC) Received: from mail-pg0-f65.google.com (mail-pg0-f65.google.com [74.125.83.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 DDC91307D859 for ; Sun, 1 Jul 2018 21:44:59 +0000 (UTC) Received: by mail-pg0-f65.google.com with SMTP id m19-v6so2674501pgv.3 for ; Sun, 01 Jul 2018 14:44:59 -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.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Jul 2018 14:44:58 -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=rAhu08CpMkl8FXidtesYOYaipgvlKrTCVrJqH3Aq1eo=; b=d2JzPZaK+A0Y9tne+d5xm73XdQ/QmNKFgNDmmDlmRjXMF0eUOoqpnzjnkSU2CtbJlM AotaZOIMYsc3ZxmXsXC4MygKL21GgI+UbiF1OXn0967M4FTsX5oU6XeBbhVYwt+rrDb1 P0t8HmzjHMk73BEUYONVIaiTdodCCsYxMpfTETwKsqd5xEaxub/ZDgIUDb8ajUOm6XX9 KOinRx1ZMzY4NqH42bDNPjr1Q4/OFW0mUlahQJrJCUd5TqEcBjZJ8007E/GSs4NW3Vfv nGd7pnikp6qso1n6xO/VHzaHH1J1GjcVe9A6jCtGfgtmltjeZ1VjMeTgWYPRzw2m9KfG 2TRA== 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=rAhu08CpMkl8FXidtesYOYaipgvlKrTCVrJqH3Aq1eo=; b=NVvDcIsOQz1pJRlbtl90tx+p5PLRdv3qsbUjGIylMoW2WiYZm+RnPRmOY2Jg+UnCH1 8PFaFBip/Sz0eZ4FdHiYUD4ANnH67AZt48y8ZPGGjaEyt9UmodVKisMiYmq1Woiyb/mr Y2NaB4T4PcKO7+J2SFujT7Bhy3rSdAJx+dTl6eJRL7OjCktjpuwwt1i9sR0FXiHK5HqE GXJVa0MKoZaavwiK/K5fh19SX4SHJghhjDKIfmqOMd8jfBpz5GmhV8SI60/rjMr0xnKZ A5Aw3bFC6S6mAw21BBX1ul5exzLS1KHdqKiumuR3iWP1/7/oKWk6f9zGebZ+npzEFOwc dcNQ== X-Gm-Message-State: APt69E0BlCfQN6vScn4pVwsQNVQWiAu2UtFASCaeSxf18SLWUZyhyvRp 1EKYkkBMTGbqZR5kuijGPVC8eHyV X-Google-Smtp-Source: AAOMgpd50xNgRF+IOuxcIAZWnShhzAzlY1f/odV6lKw52W15A4FhYRbYOVLupV2cABovqEnpuAIXFg== X-Received: by 2002:a62:3b89:: with SMTP id w9-v6mr15406136pfj.80.1530481499150; Sun, 01 Jul 2018 14:44:59 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 30 Jun 2018 14:30:28 +0530 Message-Id: <1530349239-22049-25-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.48]); Sun, 01 Jul 2018 21:45:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sun, 01 Jul 2018 21:45:00 +0000 (UTC) for IP:'74.125.83.65' DOMAIN:'mail-pg0-f65.google.com' HELO:'mail-pg0-f65.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.65 mail-pg0-f65.google.com 74.125.83.65 mail-pg0-f65.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 24/35] util: json: 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sun, 01 Jul 2018 21:45:23 +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 --- src/util/virjson.c | 49 ++++++++++++++----------------------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 92f3994..82f539f 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -496,65 +496,50 @@ virJSONValueNewNumber(const char *data) virJSONValuePtr virJSONValueNewNumberInt(int data) { - virJSONValuePtr val =3D NULL; - char *str; + VIR_AUTOFREE(char *) str =3D NULL; if (virAsprintf(&str, "%i", data) < 0) return NULL; - val =3D virJSONValueNewNumber(str); - VIR_FREE(str); - return val; + return virJSONValueNewNumber(str); } =20 =20 virJSONValuePtr virJSONValueNewNumberUint(unsigned int data) { - virJSONValuePtr val =3D NULL; - char *str; + VIR_AUTOFREE(char *) str =3D NULL; if (virAsprintf(&str, "%u", data) < 0) return NULL; - val =3D virJSONValueNewNumber(str); - VIR_FREE(str); - return val; + return virJSONValueNewNumber(str); } =20 =20 virJSONValuePtr virJSONValueNewNumberLong(long long data) { - virJSONValuePtr val =3D NULL; - char *str; + VIR_AUTOFREE(char *) str =3D NULL; if (virAsprintf(&str, "%lld", data) < 0) return NULL; - val =3D virJSONValueNewNumber(str); - VIR_FREE(str); - return val; + return virJSONValueNewNumber(str); } =20 =20 virJSONValuePtr virJSONValueNewNumberUlong(unsigned long long data) { - virJSONValuePtr val =3D NULL; - char *str; + VIR_AUTOFREE(char *) str =3D NULL; if (virAsprintf(&str, "%llu", data) < 0) return NULL; - val =3D virJSONValueNewNumber(str); - VIR_FREE(str); - return val; + return virJSONValueNewNumber(str); } =20 =20 virJSONValuePtr virJSONValueNewNumberDouble(double data) { - virJSONValuePtr val =3D NULL; - char *str; + VIR_AUTOFREE(char *) str =3D NULL; if (virDoubleToStr(&str, data) < 0) return NULL; - val =3D virJSONValueNewNumber(str); - VIR_FREE(str); - return val; + return virJSONValueNewNumber(str); } =20 =20 @@ -1171,10 +1156,9 @@ int virJSONValueGetArrayAsBitmap(const virJSONValue *val, virBitmapPtr *bitmap) { - int ret =3D -1; virJSONValuePtr elem; size_t i; - unsigned long long *elems =3D NULL; + VIR_AUTOFREE(unsigned long long *) elems =3D NULL; unsigned long long maxelem =3D 0; =20 *bitmap =3D NULL; @@ -1191,25 +1175,20 @@ virJSONValueGetArrayAsBitmap(const virJSONValue *va= l, =20 if (elem->type !=3D VIR_JSON_TYPE_NUMBER || virStrToLong_ullp(elem->data.number, NULL, 10, &elems[i]) < 0) - goto cleanup; + return -1; =20 if (elems[i] > maxelem) maxelem =3D elems[i]; } =20 if (!(*bitmap =3D virBitmapNewQuiet(maxelem + 1))) - goto cleanup; + return -1; =20 /* second pass sets the correct bits in the map */ for (i =3D 0; i < val->data.array.nvalues; i++) ignore_value(virBitmapSetBit(*bitmap, elems[i])); =20 - ret =3D 0; - - cleanup: - VIR_FREE(elems); - - return ret; + return 0; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list