From nobody Tue May 13 22:25: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 1528400158013403.8282113850087; Thu, 7 Jun 2018 12:35:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B0BCF4E4C3; Thu, 7 Jun 2018 19:35:56 +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 5E6DE60927; Thu, 7 Jun 2018 19:35:56 +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 E01631801218; Thu, 7 Jun 2018 19:35:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w57JZlf1019115 for ; Thu, 7 Jun 2018 15:35:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8DBE45D761; Thu, 7 Jun 2018 19:35:47 +0000 (UTC) Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8692D5B680 for ; Thu, 7 Jun 2018 19:35:42 +0000 (UTC) Received: from mail-pg0-f43.google.com (mail-pg0-f43.google.com [74.125.83.43]) (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 66DBB3082144 for ; Thu, 7 Jun 2018 19:35:31 +0000 (UTC) Received: by mail-pg0-f43.google.com with SMTP id p9-v6so5220485pgc.9 for ; Thu, 07 Jun 2018 12:35:31 -0700 (PDT) Received: from centos.localdomain ([49.32.106.159]) by smtp.gmail.com with ESMTPSA id d23-v6sm86686407pfn.3.2018.06.07.12.35.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 12:35:30 -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=AQt4B54qTp0e6xJaHJk2Dh50SeV4Crd4xQNnJydMDK8=; b=bWk0CSH9zk/ZSyTRsXz1EMcoW/yvZAGmA0b2mc5ILPdPd1AeINYTFedFy5KqLX5e/t pgEBntU8IKC8WU5i1Bd3zqNuabdsUROcL7YAtr53qsj/VFECH8cDR729glYlZ9EMWCWt /8zw3irXyA4wIrM3lTSy4Dl9gKrzusr8sleYZa53qzbqISrUQOwNUCPr/NkjvonQQd0I 9h3XwA/+CNTmIr0HRhll9Iap6uBHvm6471DRDdLVeE0JF7aNd0P7rZ3/keO81FbriuuV 4YZr9l9i9AAvgjZEHJ/Uoe8fAwvGuLTe2JDWnztQaKcxw94rYkpsWGgSEOjBGGpBf3jl ypvg== 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=AQt4B54qTp0e6xJaHJk2Dh50SeV4Crd4xQNnJydMDK8=; b=VoCUu8GWsZpXusTKdDx8203g4WyC3eOMYGVgVkBJ7r/YtpgvRYo6L7U+V4q0s381/X WnpyswA4EoTNTnyX+xxFRfyOgF8ewUjj9ba2WVdOaONWiPqLRMk4vXPnzvIza0rVKbK/ UI4PYCLHdCLpOTEBH78H3bM0JQWz4Co23lp6PXnrpx0sGZsRQHUDlM2FfAv8DorzpjrR M2tzH6dLWnTmcQrLK5Ibg8pJXBBvsR5nc5yXNAWsOT7mUCDaEzmTGNOF7Z7z3kzD4tFW HjLsShgg0GxiwCnLmgufn5+tA/jbqn30T+XShE8Kr9GjuX5XiuJcjKS7ZGeKycR6/PEu nsUA== X-Gm-Message-State: APt69E2IHNc653vrfG+AVsBAU//WO8kKAOUAPSfjmn4G49Lqgi09b7yo PRxtfEMEx9ISC+PwAVLCIzMhQaqE X-Google-Smtp-Source: ADUXVKKScxZ4IFcp7iDLko7qCQeGXmK0VyYeth8zkA8UcdjOQgYng40JOtt/SWabsOCiQcwejck9sg== X-Received: by 2002:a65:62cd:: with SMTP id m13-v6mr2687955pgv.207.1528400130522; Thu, 07 Jun 2018 12:35:30 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 8 Jun 2018 01:04:38 +0530 Message-Id: <1528400083-6788-17-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528400083-6788-1-git-send-email-skrtbhtngr@gmail.com> References: <1528400083-6788-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.42]); Thu, 07 Jun 2018 19:35:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 07 Jun 2018 19:35:31 +0000 (UTC) for IP:'74.125.83.43' DOMAIN:'mail-pg0-f43.google.com' HELO:'mail-pg0-f43.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) 74.125.83.43 mail-pg0-f43.google.com 74.125.83.43 mail-pg0-f43.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.42 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 16/21] 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.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 07 Jun 2018 19:35:57 +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 the GCC's __attribute__((cleanup)) handled by VIR_AUTOFREE macro, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. --- src/util/virjson.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 92f3994..1391a3b 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -497,11 +497,10 @@ 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; } =20 @@ -510,11 +509,10 @@ 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; } =20 @@ -523,11 +521,10 @@ 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; } =20 @@ -536,11 +533,10 @@ 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; } =20 @@ -549,11 +545,10 @@ 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; } =20 @@ -1171,10 +1166,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 +1185,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