From nobody Mon May 13 08:39:18 2024 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 1531504546666329.8219830779169; Fri, 13 Jul 2018 10:55:46 -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 B29BD3086253; Fri, 13 Jul 2018 17:55:44 +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 D695F308BDA9; Fri, 13 Jul 2018 17:55:43 +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 34EDE18037F0; Fri, 13 Jul 2018 17:55:41 +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 w6DHteRh008353 for ; Fri, 13 Jul 2018 13:55:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 012735D761; Fri, 13 Jul 2018 17:55:40 +0000 (UTC) Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA9D35D70C for ; Fri, 13 Jul 2018 17:55:37 +0000 (UTC) Received: from mail-pl0-f65.google.com (mail-pl0-f65.google.com [209.85.160.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 97D4F308FBAD for ; Fri, 13 Jul 2018 17:55:26 +0000 (UTC) Received: by mail-pl0-f65.google.com with SMTP id b1-v6so12503538pls.5 for ; Fri, 13 Jul 2018 10:55:26 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:25 -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=RpOfWCU33lphAAxIRxvjrwtFk2t62DslpZHxXhlo1mI=; b=oL50KNgbi0U6rH23ZdW1XJqETQtstJ+cj0v80imttI5W4QLH++uAtoUcyHGsYIcM8G +4csKyQ8hmkPJ/wsvc7U+kn/phW0arDLKxe3O8RDCTZ1Ed2t13BUDAU5lHsnhLXbnoRb bSth6TrN6b05GrixCcXIfYW14GSnlda8cvz3ekZeOPpbB16RjVxE2LBqiJg8jsVLVbic ZvCe9sT72Kw8mbtUXy2dOst34v0ahjI60v/RgmOsOv9ylkmrQaGcdqE4yf80c0w3jM1u 8koSq2r/6yauBWQiVrwjm2kRtjZZ42OOob6pwiHGptHT39I4ZkyPfW1NDk2zw9dNiu8g FbfQ== 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=RpOfWCU33lphAAxIRxvjrwtFk2t62DslpZHxXhlo1mI=; b=HK0cxpuBUtUtD87NBSTuCpY+MTVGT3OZBBWlIf8+CLCzFrAlI50r8id+HLHN7uZ5G+ V3oEX3B4amdgi/RjcJYUM+X3LtzvP/dPrJiGiYIz5xZN7hCHePElAjXC+acJObIG696I cWnePmAeE+6Ryrc7zEKG8LZcfu72tyZUIqBZAcmoyuyRjuBEwXyokMMERksCeqXI0Yxe r0UUr12HemP2uK3qg8r+tEp9BjMkuH2kwInK/DtmSG1jg/RywezFq93Fambax6EowaCW RZShFkPh/FJIpkki/FEa/fFA03BlxVUK5UtwVzg3sDHOCMO3jVHo9+fbe3akmeIIUiul tN9A== X-Gm-Message-State: AOUpUlEqFbDJMFxTZttiuuoQcGjscWZ6jadZWRaljkWKspsc0QEQFmer 9WlSkwpcpOjeSirzE25EsWyCwXk0 X-Google-Smtp-Source: AAOMgpfZlcoh08bq2+ZxX68A9h1VCVhI6dGlHkI7gu/Zs5VXMeuC5rc/oBCe8wZjaESZMNx5BTVeLw== X-Received: by 2002:a17:902:6845:: with SMTP id f5-v6mr7297073pln.173.1531504525772; Fri, 13 Jul 2018 10:55:25 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:39 +0530 Message-Id: <1531504509-7930-2-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.43]); Fri, 13 Jul 2018 17:55:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 13 Jul 2018 17:55:26 +0000 (UTC) for IP:'209.85.160.65' DOMAIN:'mail-pl0-f65.google.com' HELO:'mail-pl0-f65.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (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) 209.85.160.65 mail-pl0-f65.google.com 209.85.160.65 mail-pl0-f65.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.43 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 01/31] util: alloc: add macros for implementing automatic cleanup functionality 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.49]); Fri, 13 Jul 2018 17:55:45 +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" New macros are introduced which help in adding GNU C's cleanup attribute to variable declarations. Variables declared with these macros will have their allocated memory freed automatically when they go out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/viralloc.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 69d0f90..a23aa18 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -596,4 +596,46 @@ void virAllocTestInit(void); int virAllocTestCount(void); void virAllocTestOOM(int n, int m); void virAllocTestHook(void (*func)(int, void*), void *data); + +# define VIR_AUTOPTR_FUNC_NAME(type) type##AutoPtrFree + +/** + * VIR_DEFINE_AUTOPTR_FUNC: + * @type: type of the variable to be freed automatically + * @func: cleanup function to be automatically called + * + * This macro defines a function for automatic freeing of + * resources allocated to a variable of type @type. This newly + * defined function works as a necessary wrapper around @func. + */ +# define VIR_DEFINE_AUTOPTR_FUNC(type, func) \ + static inline void VIR_AUTOPTR_FUNC_NAME(type)(type **_ptr) \ + { \ + if (*_ptr) \ + (func)(*_ptr); \ + *_ptr =3D NULL; \ + } \ + +/** + * VIR_AUTOFREE: + * @type: type of the variable to be freed automatically + * + * Macro to automatically free the memory allocated to + * the variable declared with it by calling virFree + * when the variable goes out of scope. + */ +# define VIR_AUTOFREE(type) __attribute__((cleanup(virFree))) type + +/** + * VIR_AUTOPTR: + * @type: type of the variable to be freed automatically + * + * Macro to automatically free the memory allocated to + * the variable declared with it by calling the function + * defined by VIR_DEFINE_AUTOPTR_FUNC when the variable + * goes out of scope. + */ +# define VIR_AUTOPTR(type) \ + __attribute__((cleanup(VIR_AUTOPTR_FUNC_NAME(type)))) type * + #endif /* __VIR_MEMORY_H_ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504547300562.4612992917432; Fri, 13 Jul 2018 10:55:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 239261E31B; Fri, 13 Jul 2018 17:55:45 +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 E32C5BEDEB; Fri, 13 Jul 2018 17:55:44 +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 1C02618037F2; Fri, 13 Jul 2018 17:55:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHtgt9008363 for ; Fri, 13 Jul 2018 13:55:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 99407600C4; Fri, 13 Jul 2018 17:55:42 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 903F7600C0 for ; Fri, 13 Jul 2018 17:55:39 +0000 (UTC) Received: from mail-pf0-f174.google.com (mail-pf0-f174.google.com [209.85.192.174]) (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 500303B564 for ; Fri, 13 Jul 2018 17:55:28 +0000 (UTC) Received: by mail-pf0-f174.google.com with SMTP id u16-v6so23031901pfh.3 for ; Fri, 13 Jul 2018 10:55:28 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:27 -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=c5ZO99xOWUeIVu6WAmM5TmhaAYgV/CX7av9/o+M3rnE=; b=Sb9xBVzgYe/7mhsI8l1NLWgb15aKckEaBEkFi+PkqY5tnrgxdOhyoteaALhSzpV4CX 8jdep0BMDSS/r0OrZx/h68Iy2ieitWflYbaxKWCUfrdnIjzX+x/hn+CaRn+ycs7sGw5r 6uLWJDagkkUE1u5cH6KfQT7zz7/vRzC/Hh4Iyze2GPr/pp4ND167GntJupuDGiMIWd65 3e4v3SkTMxs9FIxdtj9P1HbKcKoTSC+fcR5zBytfa+L6aPcvBocIVQUqd/c4eatXcVyP oiuW8jXqa73jy6/R70aX/z0Y6xD4XEtXUvZu8eJXCBJnIrleHF+BGxd8FXmJ/YKYcL/u ImCw== 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=c5ZO99xOWUeIVu6WAmM5TmhaAYgV/CX7av9/o+M3rnE=; b=sP4A2Cu4tBXRlk7QrF0SkfF9Ch9Z174tkAjgrw1D2DiVVV3t6KL7C/wKzeBb2pDeh0 5yQmTaaoV2BaorfuddZSZXKbQH/QY5ChaPaPWnwb8Dmfz/mMBCgesO22jkrI49avpfsY greD7NR0dFZBI3Yb94i3lXvRF0RKKbUedCm526Ac2hdCxynw8MQC7jHbFLB+eUR4Ok9s 5liGaSf93WJt3gguRqcboqtQaudCh8P46J0tbcTaqY8eV/Odu6ul/MnnUHM5Ral9EBX+ i4qlB8IM10Q7I3y+m7nScQgAMKdSchYmen5yhf/KOLq/AvcnBkgcoAbvRcHBvQ1sGg3k 1bpg== X-Gm-Message-State: AOUpUlF4V63kTgqF0IE7p1U+yXAMnKejVBAjM/eAUGCMOuWTXFQRum81 gRlnI4WE6BBshpnXnanPLEgdsCv2 X-Google-Smtp-Source: AAOMgpcPggJQ3KA1HFesT1AZL2fZ35SynY4lR8zI6w8oSphdQ517edrGBInUa4qu6ScMw9ldIj1wTQ== X-Received: by 2002:aa7:84cf:: with SMTP id x15-v6mr8067136pfn.220.1531504527588; Fri, 13 Jul 2018 10:55:27 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:40 +0530 Message-Id: <1531504509-7930-3-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.38]); Fri, 13 Jul 2018 17:55:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 13 Jul 2018 17:55:28 +0000 (UTC) for IP:'209.85.192.174' DOMAIN:'mail-pf0-f174.google.com' HELO:'mail-pf0-f174.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.174 mail-pf0-f174.google.com 209.85.192.174 mail-pf0-f174.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 02/31] cfg.mk: variable initialization when declared with cleanup macro 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 13 Jul 2018 17:55:46 +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" A variable, which is never assigned a value in the function, might get passed into the cleanup function which may or may not raise any errors. To maintain the correct usage, the variable must be initialized, either with a value or with NULL. This syntax-check rule takes care of that. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- cfg.mk | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cfg.mk b/cfg.mk index 6bebd0a..609ae86 100644 --- a/cfg.mk +++ b/cfg.mk @@ -1057,6 +1057,17 @@ sc_prohibit_backslash_alignment: halt=3D'Do not attempt to right-align backslashes' \ $(_sc_search_regexp) =20 +# Some syntax rules pertaining to the usage of cleanup macros +# implementing GNU C's cleanup attribute + +# Rule to ensure that varibales declared using a cleanup macro are +# always initialized. +sc_require_attribute_cleanup_initialization: + @prohibit=3D'VIR_AUTO(FREE|PTR)\(.+\) *[^=3D]+;' \ + in_vc_files=3D'\.[chx]$$' \ + halt=3D'variable declared with a cleanup macro must be initialized' \ + $(_sc_search_regexp) + # We don't use this feature of maint.mk. prev_version_file =3D /dev/null =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504567936604.1006574200505; Fri, 13 Jul 2018 10:56:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 49C574DB00; Fri, 13 Jul 2018 17:56:05 +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 EE27010694F0; Fri, 13 Jul 2018 17:56:04 +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 736A14A465; Fri, 13 Jul 2018 17:56:04 +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 w6DHtggF008373 for ; Fri, 13 Jul 2018 13:55:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id CFAE46148; Fri, 13 Jul 2018 17:55:42 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C632D19489 for ; Fri, 13 Jul 2018 17:55:41 +0000 (UTC) Received: from mail-pf0-f172.google.com (mail-pf0-f172.google.com [209.85.192.172]) (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 23C835D5F8 for ; Fri, 13 Jul 2018 17:55:30 +0000 (UTC) Received: by mail-pf0-f172.google.com with SMTP id j3-v6so23037433pfh.11 for ; Fri, 13 Jul 2018 10:55:30 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:28 -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=QNOGJsaOwLv5ll/f1hXgPsw/5lo5hmyp5mJcSTebGVY=; b=MXrg/HuNHOEcwCQmEiZi9Ufl3SfBQXT6mIlK/+zuBkgVo4raiIX4jNjTe3DlIetUO+ tmfEQwS05SPyZFhr95DqIoZtpv/MmhYVdPVVFNFwl9gwjnuTdDCXp+4LHitR1rQH7JnC xfCuIwbz1vvVSLbNai8ulc3TlCnDfMUEEd6h3hqqfGsS2no1JHwyq3Tkl5x5Xz5gDoBt Y6hhWUH/tib7QS5xNwYmGGnp2+LWgX7Y8NuBoUjpQ37oEPbv82VP2e6t46kiu20epoh5 usa6qUXtEAT/Kl2QyFyI0Uc4KrcBilrJqlZDkFyjxDcR4riXcq7eaxH0gQU8Kj5NExMd t2Jg== 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=QNOGJsaOwLv5ll/f1hXgPsw/5lo5hmyp5mJcSTebGVY=; b=cs+QTokwRrPpebLeWoNDZu03rH98uQS/8z8kSmrcYIdQKhol67ZiJteZzfWu8L1lfA ADw/oIlPOlOhQNDIvXKSAjAMXmBWC6a8C8D3t2h7ZrGZYDK2NzIJNmZTRyP0eVhhM5gL zi6t9nPe9y+mXro5rlNfnzlFFE5PvbvdeYc4USRBSyihG3+Xb640Uetw0BRryicjHZNm 8GjLGzk9SG/oVrSnNHq1v4rgwXzvTeUvY2TgvRmAELxjmdzbZuofJ3W6PzID9l9gtkgf Q8WcOqlDkqStpIXvdgHpR/WqqJRraFxbbshcObsPFGqJynbCHTIzU6M1DOHiwSxJAar7 qBYA== X-Gm-Message-State: AOUpUlEC1i/cX9+LUUbIUOI+dWb457R4sVY4d36g2410hxHg5fshNqR1 NVnElieHolwfvApnThaVYbH2/l/e X-Google-Smtp-Source: AAOMgpdL6FdkyOas5cyed9px+putCJov6NBn7uVikIM0/HcShqy/y5lJtAqpKy+V1j7Ee0Pk6GUEcg== X-Received: by 2002:a62:ed5:: with SMTP id 82-v6mr8151990pfo.198.1531504529388; Fri, 13 Jul 2018 10:55:29 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:41 +0530 Message-Id: <1531504509-7930-4-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.39]); Fri, 13 Jul 2018 17:55:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 13 Jul 2018 17:55:30 +0000 (UTC) for IP:'209.85.192.172' DOMAIN:'mail-pf0-f172.google.com' HELO:'mail-pf0-f172.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.192.172 mail-pf0-f172.google.com 209.85.192.172 mail-pf0-f172.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 03/31] util: string: 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 13 Jul 2018 17:56:06 +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. Alias virString to (char *) so that the new cleanup macros can be used for a list of strings (char **). When a list of strings (virString *) is declared using VIR_AUTOPTR, the function virStringListFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virstring.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/util/virstring.h b/src/util/virstring.h index 607ae66..726e02b 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -25,6 +25,9 @@ # include =20 # include "internal.h" +# include "viralloc.h" + +typedef char *virString; =20 char **virStringSplitCount(const char *string, const char *delim, @@ -309,4 +312,6 @@ int virStringParsePort(const char *str, unsigned int *port) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; =20 +VIR_DEFINE_AUTOPTR_FUNC(virString, virStringListFree) + #endif /* __VIR_STRING_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504566845383.79055410677506; Fri, 13 Jul 2018 10:56:06 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C6D680F8D; Fri, 13 Jul 2018 17:56:05 +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 07ED760BE4; Fri, 13 Jul 2018 17:56:05 +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 7A4064A46C; Fri, 13 Jul 2018 17:56:04 +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 w6DHtgX6008368 for ; Fri, 13 Jul 2018 13:55:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id BAE9D5D761; Fri, 13 Jul 2018 17:55:42 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B3CD85D70C for ; Fri, 13 Jul 2018 17:55:42 +0000 (UTC) Received: from mail-pf0-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) (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 DA8903084054 for ; Fri, 13 Jul 2018 17:55:31 +0000 (UTC) Received: by mail-pf0-f196.google.com with SMTP id e10-v6so23051358pfn.1 for ; Fri, 13 Jul 2018 10:55:31 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55: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=njo/pVRghcqkv++YG4ujCsjVrnmdM0CG1Qhhk57zImc=; b=ajx3N3dtTr742lh1SL/utDvu1ZURCLl87MkfaJrVpPGvYFSgLDkpFHcbqa48V7NM9Y Dv2FsMUKgiJi2I9N7hm0PcJCBzEdJWP+rwBZSpf76A6kcwIMh/kC50IC9padtrng7gV1 9dVUE5581lqLONjZ3dLFDhBnvbfypBnqOf3xYPsI44ul5MvCAcVPgAa2nVH9r2iF/ruQ EMMwEeP/nk6Pg8MxEFGI1ZqnTCBHuMYEdVCF15tPvpTyBhPI6/bqdrTjsQEjAH6QzQJn DBYRJjioXM4K5ZtXNp1IT6OpJpVMQK7+Oz7yhCW7/vF1YkPOjQQWsmAIReEf3aLdVU2e POLg== 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=njo/pVRghcqkv++YG4ujCsjVrnmdM0CG1Qhhk57zImc=; b=qB6nt169dIbTvIhcEiV1UT4m22FN1TkBI+5+riJ5SoiqTmicpkfk9mUUdg+LDkP3L5 ZM4Un7z/Mzmwzxmyf209Y36r0UBV0MNZKfal7CnKylHRy2rsHNuRv0III3+WprsrqK5Y VxpfY13JpjdVrsuZ0sG7imah5m98ikWxCC7rKCrLHzqt6NL2xQMLzyqKC1A7ZC3R4s2R qjWAiUlh+2iN69HHReD6pcgWFZl6vnZiXDBVnz98zPYDwA/juB2o7eLx3p0wynTShYAo CwUjHmTp6Mhw3xc0h7lT0hyzAEs/9ViEeik4HHbnYPc80aWPLaRNazmfP8AFB0p2zhx3 ovdA== X-Gm-Message-State: AOUpUlGAdJgG3spMkD/hnLdatgDqaoU6okFetqkENxW65htem/+Ugh2S vpgUpW4OcqhQVcuW0EMH+l2aMsey X-Google-Smtp-Source: AAOMgpeEjqSZCm+79h2H6A7z1GGDqeQVqL3RNz1iAmfiGn57MqHfu0IgaYeyOUNw3HOBqyTbwmi1cA== X-Received: by 2002:a62:1f8c:: with SMTP id l12-v6mr8212893pfj.143.1531504531159; Fri, 13 Jul 2018 10:55:31 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:42 +0530 Message-Id: <1531504509-7930-5-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.40]); Fri, 13 Jul 2018 17:55:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 13 Jul 2018 17:55:31 +0000 (UTC) for IP:'209.85.192.196' DOMAIN:'mail-pf0-f196.google.com' HELO:'mail-pf0-f196.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.192.196 mail-pf0-f196.google.com 209.85.192.196 mail-pf0-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 04/31] util: command: 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 13 Jul 2018 17:56:06 +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. When a variable of type virCommandPtr is declared using VIR_AUTOPTR, the function virCommandFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/vircommand.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/vircommand.h b/src/util/vircommand.h index 883e212..90bcc6c 100644 --- a/src/util/vircommand.h +++ b/src/util/vircommand.h @@ -24,6 +24,7 @@ =20 # include "internal.h" # include "virbuffer.h" +# include "viralloc.h" =20 typedef struct _virCommand virCommand; typedef virCommand *virCommandPtr; @@ -218,5 +219,6 @@ int virCommandRunNul(virCommandPtr cmd, virCommandRunNulFunc func, void *data); =20 +VIR_DEFINE_AUTOPTR_FUNC(virCommand, virCommandFree) =20 #endif /* __VIR_COMMAND_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 153150456813978.43518611064621; Fri, 13 Jul 2018 10:56:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 37004308212A; Fri, 13 Jul 2018 17:56:06 +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 ECED360BE5; Fri, 13 Jul 2018 17:56:05 +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 8E10D4A46C; Fri, 13 Jul 2018 17:56:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHtmV3008394 for ; Fri, 13 Jul 2018 13:55:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 37124308BDB0; Fri, 13 Jul 2018 17:55:48 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2D5F1308BDAE for ; Fri, 13 Jul 2018 17:55:45 +0000 (UTC) Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (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 1B9265F758 for ; Fri, 13 Jul 2018 17:55:34 +0000 (UTC) Received: by mail-pg1-f181.google.com with SMTP id n9-v6so4927520pgp.12 for ; Fri, 13 Jul 2018 10:55:34 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:32 -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=cunBn6J32o+r2OFl1DYp7HYcDWENj+ZDBG5Nm/5tdXw=; b=uzTMpWnkFMwgzgkFjPldiBYVDeBkPb9HpmQXa95GHMeMLAN7FuohfhHEZBSc2WPSCk yPtOZD51Ac1rl65n9CI2QnN1Pvu8cPai+hSOrLZtTmC/k5zwL3muwgtJSRkgDUf9owNx VtjrwtB3tCWR3STL7pVFkk+4kjiXaAznniTZLkqi4ZAtNuYOKV+IF/mJM6v5DOFjPZ7z rQ0lhXw3dbnwFIoP9e3hgXEL8NBNoSpY8sVxgf/Cbju/Z+GNDdA7BErGCZRsdGs2gBMq DvvXHmeLcM0D9hfgsWAGIULBDKBPunGrPsuvXED3QAi+SquOErRVD+zU5shn85ZPXnk+ 4B/w== 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=cunBn6J32o+r2OFl1DYp7HYcDWENj+ZDBG5Nm/5tdXw=; b=OY8yn1mVISiG8wkLAsQDp47Il9KmFrCruvquOeagZp7j8o/++yLh+o52UGUw/2iKL3 D0nVDLczxkZ7uxOKFAelIAjwg1SsTGsKQMZJ3kRGnCZOg8TfNpcJop2eK4Ten8M0tCVU Ng833bDlwRyl0yvNWZAtM/anNPPXqMBkRQLB4vaPIOKLu0WnOjLQtHmHvxeYuTtP9DCZ biH4oANR/uodL/W/sbKbM8InEdjJJwgbufOy/vCowc1oxYTlK+iQsLPsbxH2M+9hUj4x 23XCDhNq3ubfrg3ajPHcR3oroo2S6dEKTlHMNij63bER842Uc3uRx/hIBv+KWPa+or9c UTQw== X-Gm-Message-State: AOUpUlGZ8ILXTkOSp0c+H0GsMFX09j2P4MlGOob0CD8tapAQmnc2l+te W4qa4RJBDVuUoVpBASA357RiAaRV X-Google-Smtp-Source: AAOMgpe8uSvLm7vSKyCwEMyGTiad/cpcO9A/v1JB5QQNTCK1l50pEbaL8puWOX2TE50fn6PcLQkHyw== X-Received: by 2002:a63:704f:: with SMTP id a15-v6mr6985720pgn.443.1531504533322; Fri, 13 Jul 2018 10:55:33 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:43 +0530 Message-Id: <1531504509-7930-6-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.39]); Fri, 13 Jul 2018 17:55:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 13 Jul 2018 17:55:34 +0000 (UTC) for IP:'209.85.215.181' DOMAIN:'mail-pg1-f181.google.com' HELO:'mail-pg1-f181.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.215.181 mail-pg1-f181.google.com 209.85.215.181 mail-pg1-f181.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 05/31] util: command: remove redundant include directive 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 13 Jul 2018 17:56:07 +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" viralloc.h is pulled in by vircommand.h Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/vircommand.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 6dab105..8681e7b 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -44,7 +44,6 @@ =20 #define __VIR_COMMAND_PRIV_H_ALLOW__ #include "vircommandpriv.h" -#include "viralloc.h" #include "virerror.h" #include "virutil.h" #include "virlog.h" --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504577934176.91998750951598; Fri, 13 Jul 2018 10:56:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 54FB036A5DC; Fri, 13 Jul 2018 17:56:15 +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 17AC5C6A3B; Fri, 13 Jul 2018 17:56:15 +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 A6517239; Fri, 13 Jul 2018 17:56:14 +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 w6DHtoXD008406 for ; Fri, 13 Jul 2018 13:55:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id C6C25C6A37; Fri, 13 Jul 2018 17:55:50 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BF784BEDEB for ; Fri, 13 Jul 2018 17:55:47 +0000 (UTC) Received: from mail-pf0-f177.google.com (mail-pf0-f177.google.com [209.85.192.177]) (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 027D080F94 for ; Fri, 13 Jul 2018 17:55:36 +0000 (UTC) Received: by mail-pf0-f177.google.com with SMTP id b17-v6so23044263pfi.0 for ; Fri, 13 Jul 2018 10:55:35 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:34 -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=hM9uYfHjM62FsCCW/JxHbsTPrbD80F2iJr2v4NDBzhg=; b=UDpZgPVIibNSd8BkKc0EhBvRnL6jIbjF3aVRQJY6PYrAZXo8MsuabLIco5OAreFzWd JDWj3XpTPlBJ47EZiDUkzeyPmUowyOw6G99nJnIM4vSkGqv8nPp+0NVjR5Z5HzmmGx2u goFgFOez0X/50XfpIwQwNrUzomrTKvBfm51d2vvM+w4F/JK8vi4PEeqU2CCSLMf68akH J3+EyC8A6tAOgQq5iw/y7SQ3wIYbk2eRnmVZnoHSW8tv5H+7SWfGHJj5RVZ3iXGIdUZA Tmv5sCvCc5vQI5cPkZeaic4F4twt/UCjY0Z5AprS9IWJsS5J4NhSDM3Z5i1yGYhpPsOI /N9w== 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=hM9uYfHjM62FsCCW/JxHbsTPrbD80F2iJr2v4NDBzhg=; b=t9F3MIlJK7hRiIdL7Ku+fXexESu9FcOYYCoVdPgnxpjssPnvsr7XUiXcg2uIo76dWU UkEnjmmDdaRutjjzHsRp3bCYWQOl7vhyvjif492sYRy2MeGtQqzFB1w9QIS8EPKB3fBj 2km3yK9U6P7U6xu91Rbej7dmc/9XtwSLBX78lWzn2uZDBenK1qbuKDJOUnm9elTRN2ur KmjeS+WGta/zfc/TYGb4roZMKbbFM3gGXCXyobyKO9byU5gjfIdDnWw0d0SNk9Oii/z0 oa8iKsbA9WONMrVLJdfZZrOZtyOlQb6pxQuAP8Y3GWwyErIKv7LN/MrmElZEe1e1lUiw Ug3A== X-Gm-Message-State: AOUpUlHNp24INTuzaVtXRxp/L0MxkG9EkAqhDa044TiUfINsBv9eDImx vxqdF3RZIYmveDiQdmLB3p5JE8Qe X-Google-Smtp-Source: AAOMgpcBpkGS3aUScmZbuSWnLC1dR5fSU7A4WahwyU8dzCi7XAaQUBppjxS4f3/gk/KqMKah838r4w== X-Received: by 2002:a63:943:: with SMTP id 64-v6mr6861545pgj.368.1531504535208; Fri, 13 Jul 2018 10:55:35 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:44 +0530 Message-Id: <1531504509-7930-7-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.27]); Fri, 13 Jul 2018 17:55:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 13 Jul 2018 17:55:36 +0000 (UTC) for IP:'209.85.192.177' DOMAIN:'mail-pf0-f177.google.com' HELO:'mail-pf0-f177.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.177 mail-pf0-f177.google.com 209.85.192.177 mail-pf0-f177.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 06/31] util: command: 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 13 Jul 2018 17:56:17 +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 Reviewed-by: Erik Skultety --- src/util/vircommand.c | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 8681e7b..d328431 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -507,11 +507,11 @@ virExec(virCommandPtr cmd) int childout =3D -1; int childerr =3D -1; int tmpfd; - char *binarystr =3D NULL; + VIR_AUTOFREE(char *) binarystr =3D NULL; const char *binary =3D NULL; int ret; struct sigaction waxon, waxoff; - gid_t *groups =3D NULL; + VIR_AUTOFREE(gid_t *) groups =3D NULL; int ngroups; =20 if (cmd->args[0][0] !=3D '/') { @@ -604,9 +604,6 @@ virExec(virCommandPtr cmd) =20 cmd->pid =3D pid; =20 - VIR_FREE(groups); - VIR_FREE(binarystr); - return 0; } =20 @@ -796,9 +793,6 @@ virExec(virCommandPtr cmd) /* This is cleanup of parent process only - child should never jump here on error */ =20 - VIR_FREE(binarystr); - VIR_FREE(groups); - /* NB we don't virReportError() on any failures here because the code which jumped here already raised an error condition which we must not overwrite */ @@ -2386,7 +2380,7 @@ int virCommandRunAsync(virCommandPtr cmd, pid_t *pid) { int ret =3D -1; - char *str =3D NULL; + VIR_AUTOFREE(char *) str =3D NULL; size_t i; bool synchronous =3D false; int infd[2] =3D {-1, -1}; @@ -2511,7 +2505,6 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid) VIR_FORCE_CLOSE(cmd->infd); VIR_FORCE_CLOSE(cmd->inpipe); } - VIR_FREE(str); return ret; } =20 @@ -2588,8 +2581,8 @@ virCommandWait(virCommandPtr cmd, int *exitstatus) if (exitstatus && (cmd->rawStatus || WIFEXITED(status))) { *exitstatus =3D cmd->rawStatus ? status : WEXITSTATUS(status); } else if (status) { - char *str =3D virCommandToString(cmd); - char *st =3D virProcessTranslateStatus(status); + VIR_AUTOFREE(char *) str =3D virCommandToString(cmd); + VIR_AUTOFREE(char *) st =3D virProcessTranslateStatus(status); bool haveErrMsg =3D cmd->errbuf && *cmd->errbuf && (*cmd->errb= uf)[0]; =20 virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2597,8 +2590,6 @@ virCommandWait(virCommandPtr cmd, int *exitstatus) str ? str : cmd->args[0], NULLSTR(st), haveErrMsg ? ": " : "", haveErrMsg ? *cmd->errbuf : ""); - VIR_FREE(str); - VIR_FREE(st); return -1; } } @@ -2718,7 +2709,7 @@ int virCommandHandshakeWait(virCommandPtr cmd) return -1; } if (c !=3D '1') { - char *msg; + VIR_AUTOFREE(char *) msg =3D NULL; ssize_t len; if (VIR_ALLOC_N(msg, 1024) < 0) { VIR_FORCE_CLOSE(cmd->handshakeWait[0]); @@ -2731,7 +2722,6 @@ int virCommandHandshakeWait(virCommandPtr cmd) =20 if ((len =3D saferead(cmd->handshakeWait[0], msg, 1024)) < 0) { VIR_FORCE_CLOSE(cmd->handshakeWait[0]); - VIR_FREE(msg); virReportSystemError(errno, "%s", _("No error message from child failure")); return -1; @@ -2739,7 +2729,6 @@ int virCommandHandshakeWait(virCommandPtr cmd) VIR_FORCE_CLOSE(cmd->handshakeWait[0]); msg[len-1] =3D '\0'; virReportError(VIR_ERR_INTERNAL_ERROR, "%s", msg); - VIR_FREE(msg); return -1; } VIR_FORCE_CLOSE(cmd->handshakeWait[0]); @@ -2853,8 +2842,8 @@ virCommandFree(virCommandPtr cmd) * This requests asynchronous string IO on @cmd. It is useful in * combination with virCommandRunAsync(): * - * virCommandPtr cmd =3D virCommandNew*(...); - * char *buf =3D NULL; + * VIR_AUTOPTR(virCommand) cmd =3D virCommandNew*(...); + * VIR_AUTOFREE(char *) buf =3D NULL; * * ... * @@ -2862,21 +2851,18 @@ virCommandFree(virCommandPtr cmd) * virCommandDoAsyncIO(cmd); * * if (virCommandRunAsync(cmd, NULL) < 0) - * goto cleanup; + * return; * * ... * * if (virCommandWait(cmd, NULL) < 0) - * goto cleanup; + * return; * * // @buf now contains @cmd's stdout * VIR_DEBUG("STDOUT: %s", NULLSTR(buf)); * * ... * - * cleanup: - * VIR_FREE(buf); - * virCommandFree(cmd); * * The libvirt's event loop is used for handling stdios of @cmd. * Since current implementation uses strlen to determine length @@ -2969,11 +2955,11 @@ virCommandRunRegex(virCommandPtr cmd, { int err; regex_t *reg; - regmatch_t *vars =3D NULL; + VIR_AUTOFREE(regmatch_t *) vars =3D NULL; size_t i, j, k; int totgroups =3D 0, ngroup =3D 0, maxvars =3D 0; char **groups; - char *outbuf =3D NULL; + VIR_AUTOFREE(char *) outbuf =3D NULL; char **lines =3D NULL; int ret =3D -1; =20 @@ -3054,13 +3040,11 @@ virCommandRunRegex(virCommandPtr cmd, ret =3D 0; cleanup: virStringListFree(lines); - VIR_FREE(outbuf); if (groups) { for (j =3D 0; j < totgroups; j++) VIR_FREE(groups[j]); VIR_FREE(groups); } - VIR_FREE(vars); =20 for (i =3D 0; i < nregex; i++) regfree(®[i]); --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504573940380.21764611143715; Fri, 13 Jul 2018 10:56:13 -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 04CD05D5F8; Fri, 13 Jul 2018 17:56:11 +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 B8E5E308BDB2; Fri, 13 Jul 2018 17:56:10 +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 43E7D18037F9; Fri, 13 Jul 2018 17:56:10 +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 w6DHtoww008405 for ; Fri, 13 Jul 2018 13:55:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id C75FAC6A3B; Fri, 13 Jul 2018 17:55:50 +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 C0110C6A35 for ; Fri, 13 Jul 2018 17:55:48 +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 D4AB3C057F84 for ; Fri, 13 Jul 2018 17:55:37 +0000 (UTC) Received: by mail-pf0-f176.google.com with SMTP id a26-v6so961636pfo.4 for ; Fri, 13 Jul 2018 10:55:37 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:36 -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=5xwCaT7yGGl9dzr12oxYf35r6k9URm2OR1R/iugGqj4=; b=jW9adCknWzihUhi/fWqw6SlLAvnp48oc4Vg/7ZIqpSjgHtgLaobRqTW3zwOm57OH/q HXJTPzoJlfUcByETC0etXD8GV+ciW0eXcaTORWmm5R1vaSCIaBXmYOdRBz6RDaDsM5nq PzusfIEgcQsWOa5FK5NxTM/UGHwQd89Li815kJd8nVTLpp9wowLyCP9Sv0ZQkXv4+nIQ CdTk1ROdjUlH2mW1hR73LO5CfZ3U7lO66PDm45nK+0gFUr8ZoZx2aQ6FQ/vFr7UGR/9G HJmYm3RG2ixv9zY8sK/0ubxxj+ESC8b7l6M7/z3EXGtNyVmcXHMFP1ILH26ns0sKjO1A a/Zw== 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=5xwCaT7yGGl9dzr12oxYf35r6k9URm2OR1R/iugGqj4=; b=pUKGCuXHOUHN7dqs1qAscdfjXzs0HNPaxJTZxGBO5THo5tIRSV1FoLZFxNgDKIXse8 rea5t11qj9UxRhEjxIHsrXFkUjiAW2bMjuB2RUfL7d9Sk0Ag2mj/M5M+tUDzGHrsZHSd vePzWxDR1RS8LJIMRW8pnnV4tp4THVsy4p3NpUuwoJcGsLhiYqtsOdNe/fM0Eab0An23 cYUwYsuSEfT55ZFHOSvj46xBtVzSMSBtPGJN3o+QfhuJQWp06T8mHidFxy+ZBuyehV59 SXQzms0g/IDSRgzO8lAgNHRJDZ4HO3Kl6m8dq0B/yzf6yDT3gT+Jp9InyAEuah8TNWhS pxSw== X-Gm-Message-State: AOUpUlEYi6Rv9ib9siBDrqn4mSiPeN6MPXE4tu7mNlen9PH+5qh1dXhO CBHvnjjf0Th+ETtq3X9+VCYDQjHU X-Google-Smtp-Source: AAOMgpfp5Gx2Caxep4KSACNRBDMjs+7z8hk6Tz+BRuPEykw3l6eXFm5EULEGWcVScXSpfTi9oM4j1Q== X-Received: by 2002:a63:c742:: with SMTP id v2-v6mr6969767pgg.331.1531504537143; Fri, 13 Jul 2018 10:55:37 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:45 +0530 Message-Id: <1531504509-7930-8-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.32]); Fri, 13 Jul 2018 17:55:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 13 Jul 2018 17:55:37 +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.32 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 07/31] util: command: 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.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 13 Jul 2018 17:56:12 +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/vircommand.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index d328431..8ba9c35 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -822,12 +822,9 @@ virExec(virCommandPtr cmd) int virRun(const char *const*argv, int *status) { - int ret; - virCommandPtr cmd =3D virCommandNewArgs(argv); + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgs(argv); =20 - ret =3D virCommandRun(cmd, status); - virCommandFree(cmd); - return ret; + return virCommandRun(cmd, status); } =20 #else /* WIN32 */ @@ -2960,7 +2957,7 @@ virCommandRunRegex(virCommandPtr cmd, int totgroups =3D 0, ngroup =3D 0, maxvars =3D 0; char **groups; VIR_AUTOFREE(char *) outbuf =3D NULL; - char **lines =3D NULL; + VIR_AUTOPTR(virString) lines =3D NULL; int ret =3D -1; =20 /* Compile all regular expressions */ @@ -3039,7 +3036,6 @@ virCommandRunRegex(virCommandPtr cmd, =20 ret =3D 0; cleanup: - virStringListFree(lines); if (groups) { for (j =3D 0; j < totgroups; j++) VIR_FREE(groups[j]); --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504578527692.9205859870953; Fri, 13 Jul 2018 10:56:18 -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 759973E2D2; Fri, 13 Jul 2018 17:56:15 +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 3D395600D1; Fri, 13 Jul 2018 17:56:15 +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 CA5EA18037F4; Fri, 13 Jul 2018 17:56:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHtrbr008425 for ; Fri, 13 Jul 2018 13:55:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id A1F8210694FC; Fri, 13 Jul 2018 17:55:53 +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 905AF10694F0 for ; Fri, 13 Jul 2018 17:55:50 +0000 (UTC) Received: from mail-pf0-f169.google.com (mail-pf0-f169.google.com [209.85.192.169]) (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 B03BAC057FA2 for ; Fri, 13 Jul 2018 17:55:39 +0000 (UTC) Received: by mail-pf0-f169.google.com with SMTP id v15-v6so3038254pff.5 for ; Fri, 13 Jul 2018 10:55:39 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:38 -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=JA8bASW1446UoTQoWaSIaC659blRbC3JFcx7HpN5lC0=; b=jhSOyeNvO9gff2KpDGhNGYWvW4+pkkSt2/dIewz4KBCrxyxHxL8T8WHMhfcUPMYgdo rMr4IoBAAVoezLB4HazRUJXUHq3bIInfD/9J18TISfV2fEo8m+TtsIUyc+f7DviLC3Ss voMy2xn/DU1pEP0w4B6MeW//GTl4uNrs7+GFsp1HvCyyrzornelV0NavizFSYIpveX48 vsMpU1A5xqJkKTtTEhihDI17JsudEtdX73DMwiFpG3A4beHyAE/uionKv8j1B5jV1JMS qTedGY3dKJYtAXkjAGwmMb0cmxhNyalQETVB/4Sq08KuBF7nyZumsgzsg5KPfunarsyM zveg== 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=JA8bASW1446UoTQoWaSIaC659blRbC3JFcx7HpN5lC0=; b=L33gvk5fmkbWj6oIvoR0a/egPQQyAWh94Dtl9ZD4HoOD2JTD2dK4HbZEa6so05JTcX 2CaU4a2/dJykDS/kbaOMAAjdgeS40Zc1d3OJI3eySYP8z7yHaLhTQ4BP8Qg3HuVLmG6g 8b462bHEYFu4dF8vPnuv4pHIo8MFFZfx3orzAL45jBUAmqLZj4ZnXwDQchreAoYYQeFZ 3MCyGTN8vmNHFUmysMwNXjBlk6UoLq2B8R0iWlycVcXg3MKJldEdY7Yi2LN6T7yVOD4S IubVBULOZ/Wghw09AHQDud37Payw/2bmqSl2gCm5WIEaueKCuuAkElcZgiXql405IR+T 7lRw== X-Gm-Message-State: AOUpUlEaFfncfQ/JccJYUZifeCXduXnEkK1LtXZy1pNrIHN0Mm3wl3S6 3rfcLjo/CwHZ5Vh0JchfCcdlDFSw X-Google-Smtp-Source: AAOMgpdcrvrYCad/Z3SFSCMafELhtk3qMptEhnmhRDPoTB252OqKiZM8xkfui7Zx19ocQ33n+8N1rA== X-Received: by 2002:a62:3b89:: with SMTP id w9-v6mr8138081pfj.80.1531504539001; Fri, 13 Jul 2018 10:55:39 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:46 +0530 Message-Id: <1531504509-7930-9-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.32]); Fri, 13 Jul 2018 17:55:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 13 Jul 2018 17:55:39 +0000 (UTC) for IP:'209.85.192.169' DOMAIN:'mail-pf0-f169.google.com' HELO:'mail-pf0-f169.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.192.169 mail-pf0-f169.google.com 209.85.192.169 mail-pf0-f169.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 08/31] util: file: 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.30]); Fri, 13 Jul 2018 17:56:17 +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. When a variable of type virFileWrapperFdPtr is declared using VIR_AUTOPTR, the function virFileWrapperFdFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virfile.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/util/virfile.h b/src/util/virfile.h index 6f1e802..b30a1d3 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -32,6 +32,7 @@ # include "internal.h" # include "virbitmap.h" # include "virstoragefile.h" +# include "viralloc.h" =20 typedef enum { VIR_FILE_CLOSE_PRESERVE_ERRNO =3D 1 << 0, @@ -367,4 +368,6 @@ int virFileInData(int fd, int *inData, long long *length); =20 +VIR_DEFINE_AUTOPTR_FUNC(virFileWrapperFd, virFileWrapperFdFree) + #endif /* __VIR_FILE_H */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504583077862.3167413854709; Fri, 13 Jul 2018 10:56:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A85EC804E2; Fri, 13 Jul 2018 17:56:21 +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 6768319490; Fri, 13 Jul 2018 17:56:21 +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 EDBCA1800FD9; Fri, 13 Jul 2018 17:56:20 +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 w6DHtuw2008441 for ; Fri, 13 Jul 2018 13:55:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id C35505C72D; Fri, 13 Jul 2018 17:55:56 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AFA355C689 for ; Fri, 13 Jul 2018 17:55:52 +0000 (UTC) Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 69B23308A956 for ; Fri, 13 Jul 2018 17:55:41 +0000 (UTC) Received: by mail-pg1-f169.google.com with SMTP id k3-v6so5223238pgq.5 for ; Fri, 13 Jul 2018 10:55:41 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:40 -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=DeM6OHQWkqXnRsRhSEJp/XWkkciSzdzlUWxajIz1+m8=; b=hTXD6L756B8nFFPTiREsFqjPZ0AGo/VmMw5AVeHjyuOFNwB+C4NlU9wsaDX/9VNqWh MXStRIw6XfapJobRbPb6Y1Zv6M6hJ7DvgwxqCyZ28HpLt6h5nUyhpF/FOgunVkhu26Vl GNzh0HDMxgSo/paInitMcAJPJh0Pe3l1j5BrrrKDzRgLjiuLMr8wcy34kn4Pu2GqkExk aLaHnjri0A0snxcqJuakyhGveMBOcrdVcufu8oHYeYHMs5aGKXsqbadj7Rf1SBQJUGkC +gD6HyBELQ0hd5NK1fkXysSKJAe66kKGZRjprNsxpqAMpLq95kkjhA14YxmEomWfMi31 14UQ== 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=DeM6OHQWkqXnRsRhSEJp/XWkkciSzdzlUWxajIz1+m8=; b=UvKBe015s3wPwjL81DhKwmC/07Q9Dc6ydkNoIFvh39uqwyW9OVUcWyoI+3ASmjpaM0 B6zC22fL0UQoh4QuJLX4lJ078JzBMeJ5qHrmxpkTWXjfRpbhi/suE/7ORIPiWlpkjdq8 +6KXY19jU+vcd6kg3PA13jBKMz4nGjHT6qCswSul23hppJBtv+5pFQLh0rarlsgmQ5KA CsFdUKyj0dTITXnE3s1ySVs18pbf1Aqmlp4a3zVdfgAWN6DRd4R3MBRnO5FPCfhq+e7k Pmn3OIuz5p2lYGJhZWSXnjt2IS3qeXQ9s+SnvSnzndqSopd6/3ahEx2bXPsz2eWkplpG yVBA== X-Gm-Message-State: AOUpUlF+VhLL1mpATHhCloV/ZqNA4iU90WHUft6PiuIbwKyZNo4cWZKe y+4/yY1OhI8+32h9tNqdxf0eIZ20 X-Google-Smtp-Source: AAOMgpfjDdJ3iRUR59XcjnzIJvp7B6dK5iy5RF7PGO8B4hVcQfXHrVj/memrN0g1tnAb3LtYnpgopA== X-Received: by 2002:a63:c252:: with SMTP id l18-v6mr6989120pgg.76.1531504540725; Fri, 13 Jul 2018 10:55:40 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:47 +0530 Message-Id: <1531504509-7930-10-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.41]); Fri, 13 Jul 2018 17:55:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 13 Jul 2018 17:55:41 +0000 (UTC) for IP:'209.85.215.169' DOMAIN:'mail-pg1-f169.google.com' HELO:'mail-pg1-f169.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.215.169 mail-pg1-f169.google.com 209.85.215.169 mail-pg1-f169.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 09/31] util: file: remove redundant include directive 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 13 Jul 2018 17:56:22 +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" viralloc.h is pulled in by virfile.h Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virfile.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 378d03e..2690e2d 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -67,7 +67,6 @@ =20 #include "configmake.h" #include "intprops.h" -#include "viralloc.h" #include "vircommand.h" #include "virerror.h" #include "virfile.h" --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504587672499.532784279382; Fri, 13 Jul 2018 10:56:27 -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 5D30B32B66D; Fri, 13 Jul 2018 17:56:26 +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 1BF1C2010D58; Fri, 13 Jul 2018 17:56:26 +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 926D93D3C9; Fri, 13 Jul 2018 17:56:25 +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 w6DHtuH6008440 for ; Fri, 13 Jul 2018 13:55:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id C33E75C70F; Fri, 13 Jul 2018 17:55:56 +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 B36DD5C72C for ; Fri, 13 Jul 2018 17:55:55 +0000 (UTC) Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) (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 AB293307D84B for ; Fri, 13 Jul 2018 17:55:43 +0000 (UTC) Received: by mail-pf0-f195.google.com with SMTP id b17-v6so23044448pfi.0 for ; Fri, 13 Jul 2018 10:55:43 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:42 -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=n71Sfe2+m1X+8p/AoErnSAS6/lJk5Aa4QzYAO0G1QTg=; b=rUQodYLrj3DbCPKNXZs0f2KPtHako0Xk25eVx0hgRxCJ2TkY+c+X3mZOTmUnKp915j YlHgnTs1kbTRayndn86VkCCC1qe8fgGXHTzGYvdNZ+Rdoi0f5WcSAnY+14KWh/ngwM8c 9DXN/WLkMlkbujzTFea3e/NybHUF7xjplkwAnBb8c5z61lF52nde++bu+PHTWl69EywY Dlyi/49P6MPhK0n+A8M+fSD+Ggafu1FN2deKZ8pcQfvTmfgmJr1BfP56m1XdY1WjJSr0 8mqM5gOFRTaToCVhN3HLs4+OBK+2G0GNurE9lTrRH/sUgSfQDj1gYVfmgatS86JprEDp zZ5w== 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=n71Sfe2+m1X+8p/AoErnSAS6/lJk5Aa4QzYAO0G1QTg=; b=MdiOecUULjvuP5MTcvSjFK5rN4Ob3iLZBylvucmL+PCFOvIf4EfigwT1PeiPL+Qf7p aMesv75sFkQ3SE1eGrIKCn/MaLw9KBBlVRtOoDld+O/BZeG6S/AaQmTOaAdsWpxHpSRm yWSp/qkB5DiKaFPoocvc/oDpH/Y+0+OTvJZNpZ2SoR5RqqZkqZlLIo4HiBbK4xUMP/px 0epikQoQrfCF3RadEnBKy69OL/eGf/B8L66aVdMaH+UJ93Ft+cMtegy5MeYzsT6GQ5OU rv/kwfqK6/kxIFXpkABfeULuGC0nM6Jr0uOujMiqFIGA/Du80SOBd8VhiYfcFWWl4de7 /WFA== X-Gm-Message-State: AOUpUlGax56Bdxrar/eOSRhq9C4sj8qmZ0w2NvKifGGGdWe1cHsOpcAo mHUG6xlONRSFV2PfZuwoRQEuyZ/1 X-Google-Smtp-Source: AAOMgpcOr5dwtLjEkzHLnMv7KsSi3vKJeV4aY1Ow77ZIMiVcO4J1ymGLE+qlVi6AXNSPVxDZ1TGh8g== X-Received: by 2002:aa7:850b:: with SMTP id v11-v6mr7964787pfn.165.1531504542755; Fri, 13 Jul 2018 10:55:42 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:48 +0530 Message-Id: <1531504509-7930-11-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.48]); Fri, 13 Jul 2018 17:55:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 13 Jul 2018 17:55:43 +0000 (UTC) for IP:'209.85.192.195' DOMAIN:'mail-pf0-f195.google.com' HELO:'mail-pf0-f195.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.192.195 mail-pf0-f195.google.com 209.85.192.195 mail-pf0-f195.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 10/31] util: file: 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.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 13 Jul 2018 17:56:27 +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 Reviewed-by: Erik Skultety --- src/util/virfile.c | 310 ++++++++++++++++++-------------------------------= ---- 1 file changed, 102 insertions(+), 208 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 2690e2d..3a7445f 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -211,7 +211,7 @@ virFileWrapperFdNew(int *fd, const char *name, unsigned= int flags) bool output =3D false; int pipefd[2] =3D { -1, -1 }; int mode =3D -1; - char *iohelper_path =3D NULL; + VIR_AUTOFREE(char *) iohelper_path =3D NULL; =20 if (!flags) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -262,8 +262,6 @@ virFileWrapperFdNew(int *fd, const char *name, unsigned= int flags) =20 ret->cmd =3D virCommandNewArgList(iohelper_path, name, NULL); =20 - VIR_FREE(iohelper_path); - if (output) { virCommandSetInputFD(ret->cmd, pipefd[0]); virCommandSetOutputFD(ret->cmd, fd); @@ -294,7 +292,6 @@ virFileWrapperFdNew(int *fd, const char *name, unsigned= int flags) return ret; =20 error: - VIR_FREE(iohelper_path); VIR_FORCE_CLOSE(pipefd[0]); VIR_FORCE_CLOSE(pipefd[1]); virFileWrapperFdFree(ret); @@ -492,7 +489,7 @@ virFileRewrite(const char *path, virFileRewriteFunc rewrite, const void *opaque) { - char *newfile =3D NULL; + VIR_AUTOFREE(char *) newfile =3D NULL; int fd =3D -1; int ret =3D -1; =20 @@ -533,10 +530,8 @@ virFileRewrite(const char *path, =20 cleanup: VIR_FORCE_CLOSE(fd); - if (newfile) { + if (newfile) unlink(newfile); - VIR_FREE(newfile); - } return ret; } =20 @@ -763,7 +758,7 @@ int virFileLoopDeviceAssociate(const char *file, int lofd =3D -1; int fsfd =3D -1; struct loop_info64 lo; - char *loname =3D NULL; + VIR_AUTOFREE(char *) loname =3D NULL; int ret =3D -1; =20 if ((lofd =3D virFileLoopDeviceOpen(&loname)) < 0) @@ -801,7 +796,6 @@ int virFileLoopDeviceAssociate(const char *file, ret =3D 0; =20 cleanup: - VIR_FREE(loname); VIR_FORCE_CLOSE(fsfd); if (ret =3D=3D -1) VIR_FORCE_CLOSE(lofd); @@ -816,8 +810,7 @@ int virFileLoopDeviceAssociate(const char *file, static int virFileNBDDeviceIsBusy(const char *dev_name) { - char *path; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (virAsprintf(&path, SYSFS_BLOCK_DIR "/%s/pid", dev_name) < 0) @@ -825,18 +818,14 @@ virFileNBDDeviceIsBusy(const char *dev_name) =20 if (!virFileExists(path)) { if (errno =3D=3D ENOENT) - ret =3D 0; + return 0; else virReportSystemError(errno, _("Cannot check NBD device %s pid"), dev_name); - goto cleanup; + return -1; } - ret =3D 1; - - cleanup: - VIR_FREE(path); - return ret; + return 1; } =20 =20 @@ -881,15 +870,13 @@ virFileNBDLoadDriver(void) "administratively prohibited")); return false; } else { - char *errbuf =3D NULL; + VIR_AUTOFREE(char *) errbuf =3D NULL; =20 if ((errbuf =3D virKModLoad(NBD_DRIVER, true))) { - VIR_FREE(errbuf); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Failed to load nbd module")); return false; } - VIR_FREE(errbuf); } return true; } @@ -899,8 +886,8 @@ int virFileNBDDeviceAssociate(const char *file, bool readonly, char **dev) { - char *nbddev =3D NULL; - char *qemunbd =3D NULL; + VIR_AUTOFREE(char *) nbddev =3D NULL; + VIR_AUTOFREE(char *) qemunbd =3D NULL; virCommandPtr cmd =3D NULL; int ret =3D -1; const char *fmtstr =3D NULL; @@ -948,8 +935,6 @@ int virFileNBDDeviceAssociate(const char *file, ret =3D 0; =20 cleanup: - VIR_FREE(nbddev); - VIR_FREE(qemunbd); virCommandFree(cmd); return ret; } @@ -996,7 +981,6 @@ int virFileDeleteTree(const char *dir) { DIR *dh; struct dirent *de; - char *filepath =3D NULL; int ret =3D -1; int direrr; =20 @@ -1008,6 +992,7 @@ int virFileDeleteTree(const char *dir) return -1; =20 while ((direrr =3D virDirRead(dh, &de, dir)) > 0) { + VIR_AUTOFREE(char *) filepath =3D NULL; struct stat sb; =20 if (virAsprintf(&filepath, "%s/%s", @@ -1031,8 +1016,6 @@ int virFileDeleteTree(const char *dir) goto cleanup; } } - - VIR_FREE(filepath); } if (direrr < 0) goto cleanup; @@ -1047,7 +1030,6 @@ int virFileDeleteTree(const char *dir) ret =3D 0; =20 cleanup: - VIR_FREE(filepath); VIR_DIR_CLOSE(dh); return ret; } @@ -1205,7 +1187,7 @@ static int safezero_slow(int fd, off_t offset, off_t len) { int r; - char *buf; + VIR_AUTOFREE(char *) buf =3D NULL; unsigned long long remain, bytes; =20 if (lseek(fd, offset, SEEK_SET) < 0) @@ -1226,15 +1208,12 @@ safezero_slow(int fd, off_t offset, off_t len) bytes =3D remain; =20 r =3D safewrite(fd, buf, bytes); - if (r < 0) { - VIR_FREE(buf); + if (r < 0) return -1; - } =20 /* safewrite() guarantees all data will be written */ remain -=3D bytes; } - VIR_FREE(buf); return 0; } =20 @@ -1597,8 +1576,7 @@ virFileRelLinkPointsTo(const char *directory, const char *checkLink, const char *checkDest) { - char *candidate; - int ret; + VIR_AUTOFREE(char *) candidate =3D NULL; =20 if (*checkLink =3D=3D '/') return virFileLinkPointsTo(checkLink, checkDest); @@ -1610,9 +1588,7 @@ virFileRelLinkPointsTo(const char *directory, } if (virAsprintf(&candidate, "%s/%s", directory, checkLink) < 0) return -1; - ret =3D virFileLinkPointsTo(candidate, checkDest); - VIR_FREE(candidate); - return ret; + return virFileLinkPointsTo(candidate, checkDest); } =20 =20 @@ -1945,44 +1921,40 @@ virFileIsExecutable(const char *file) */ int virFileIsMountPoint(const char *file) { - char *parent =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) parent =3D NULL; + int ret; struct stat sb1, sb2; =20 if (!(parent =3D mdir_name(file))) { virReportOOMError(); - goto cleanup; + return -1; } =20 VIR_DEBUG("Comparing '%s' to '%s'", file, parent); =20 if (stat(file, &sb1) < 0) { if (errno =3D=3D ENOENT) - ret =3D 0; + return 0; else virReportSystemError(errno, _("Cannot stat '%s'"), file); - goto cleanup; + return -1; } =20 if (stat(parent, &sb2) < 0) { virReportSystemError(errno, _("Cannot stat '%s'"), parent); - goto cleanup; + return -1; } =20 - if (!S_ISDIR(sb1.st_mode)) { - ret =3D 0; - goto cleanup; - } + if (!S_ISDIR(sb1.st_mode)) + return 0; =20 ret =3D sb1.st_dev !=3D sb2.st_dev; VIR_DEBUG("Is mount %d", ret); =20 - cleanup: - VIR_FREE(parent); return ret; } =20 @@ -2165,7 +2137,7 @@ virFileAccessibleAs(const char *path, int mode, { pid_t pid =3D 0; int status, ret =3D 0; - gid_t *groups; + VIR_AUTOFREE(gid_t *) groups =3D NULL; int ngroups; =20 if (uid =3D=3D geteuid() && @@ -2178,13 +2150,10 @@ virFileAccessibleAs(const char *path, int mode, =20 pid =3D virFork(); =20 - if (pid < 0) { - VIR_FREE(groups); + if (pid < 0) return -1; - } =20 if (pid) { /* parent */ - VIR_FREE(groups); if (virProcessWait(pid, &status, false) < 0) { /* virProcessWait() already reported error */ errno =3D EINTR; @@ -2280,7 +2249,7 @@ virFileOpenForked(const char *path, int openflags, mo= de_t mode, int recvfd_errno =3D 0; int fd =3D -1; int pair[2] =3D { -1, -1 }; - gid_t *groups; + VIR_AUTOFREE(gid_t *) groups =3D NULL; int ngroups; bool created =3D false; =20 @@ -2298,16 +2267,12 @@ virFileOpenForked(const char *path, int openflags, = mode_t mode, virReportSystemError(errno, _("failed to create socket needed for '%s'"), path); - VIR_FREE(groups); return ret; } =20 pid =3D virFork(); - if (pid < 0) { - ret =3D -errno; - VIR_FREE(groups); - return ret; - } + if (pid < 0) + return -errno; =20 if (pid =3D=3D 0) { =20 @@ -2372,7 +2337,6 @@ virFileOpenForked(const char *path, int openflags, mo= de_t mode, =20 /* parent */ =20 - VIR_FREE(groups); VIR_FORCE_CLOSE(pair[1]); =20 do { @@ -2573,7 +2537,7 @@ virFileRemove(const char *path, { pid_t pid; int status =3D 0, ret =3D 0; - gid_t *groups; + VIR_AUTOFREE(gid_t *) groups =3D NULL; int ngroups; =20 if (!virFileRemoveNeedsSetuid(path, uid, gid)) { @@ -2598,15 +2562,11 @@ virFileRemove(const char *path, =20 pid =3D virFork(); =20 - if (pid < 0) { - ret =3D -errno; - VIR_FREE(groups); - return ret; - } + if (pid < 0) + return -errno; =20 if (pid) { /* parent */ /* wait for child to complete, and retrieve its exit code */ - VIR_FREE(groups); =20 if (virProcessWait(pid, &status, 0) < 0) { /* virProcessWait() reports errno on waitpid failure, so we'll= just @@ -2738,7 +2698,7 @@ virDirCreate(const char *path, struct stat st; pid_t pid; int status =3D 0, ret =3D 0; - gid_t *groups; + VIR_AUTOFREE(gid_t *) groups =3D NULL; int ngroups; bool created =3D false; =20 @@ -2774,15 +2734,11 @@ virDirCreate(const char *path, =20 pid =3D virFork(); =20 - if (pid < 0) { - ret =3D -errno; - VIR_FREE(groups); - return ret; - } + if (pid < 0) + return -errno; =20 if (pid) { /* parent */ /* wait for child to complete, and retrieve its exit code */ - VIR_FREE(groups); =20 if (virProcessWait(pid, &status, 0) < 0) { /* virProcessWait() reports errno on waitpid failure, so we'll= just @@ -3047,13 +3003,13 @@ int virFileChownFiles(const char *name, int ret =3D -1; int direrr; DIR *dir; - char *path =3D NULL; =20 if (virDirOpen(&dir, name) < 0) return -1; =20 while ((direrr =3D virDirRead(dir, &ent, name)) > 0) { - VIR_FREE(path); + VIR_AUTOFREE(char *) path =3D NULL; + if (virAsprintf(&path, "%s/%s", name, ent->d_name) < 0) goto cleanup; =20 @@ -3075,8 +3031,6 @@ int virFileChownFiles(const char *name, ret =3D 0; =20 cleanup: - VIR_FREE(path); - virDirClose(&dir); =20 return ret; @@ -3138,19 +3092,14 @@ int virFileMakePathWithMode(const char *path, mode_t mode) { - int ret =3D -1; - char *tmp; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 if (VIR_STRDUP(tmp, path) < 0) { errno =3D ENOMEM; - goto cleanup; + return -1; } =20 - ret =3D virFileMakePathHelper(tmp, mode); - - cleanup: - VIR_FREE(tmp); - return ret; + return virFileMakePathHelper(tmp, mode); } =20 =20 @@ -3158,8 +3107,7 @@ int virFileMakeParentPath(const char *path) { char *p; - char *tmp; - int ret =3D -1; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 VIR_DEBUG("path=3D%s", path); =20 @@ -3170,15 +3118,11 @@ virFileMakeParentPath(const char *path) =20 if ((p =3D strrchr(tmp, '/')) =3D=3D NULL) { errno =3D EINVAL; - goto cleanup; + return -1; } *p =3D '\0'; =20 - ret =3D virFileMakePathHelper(tmp, 0777); - - cleanup: - VIR_FREE(tmp); - return ret; + return virFileMakePathHelper(tmp, 0777); } =20 =20 @@ -3212,7 +3156,7 @@ virFileOpenTty(int *ttymaster, char **ttyName, int ra= wmode) * doesn't have to worry about that mess? */ int ret =3D -1; int slave =3D -1; - char *name =3D NULL; + VIR_AUTOFREE(char *) name =3D NULL; =20 /* Unfortunately, we can't use the name argument of openpty, since * there is no guarantee on how large the buffer has to be. @@ -3273,7 +3217,6 @@ virFileOpenTty(int *ttymaster, char **ttyName, int ra= wmode) if (ret !=3D 0) VIR_FORCE_CLOSE(*ttymaster); VIR_FORCE_CLOSE(slave); - VIR_FREE(name); =20 return ret; } @@ -3373,21 +3316,17 @@ virFileSkipRoot(const char *path) int virFileAbsPath(const char *path, char **abspath) { - char *buf; - if (path[0] =3D=3D '/') { if (VIR_STRDUP(*abspath, path) < 0) return -1; } else { - buf =3D getcwd(NULL, 0); + VIR_AUTOFREE(char *) buf =3D getcwd(NULL, 0); + if (buf =3D=3D NULL) return -1; =20 - if (virAsprintf(abspath, "%s/%s", buf, path) < 0) { - VIR_FREE(buf); + if (virAsprintf(abspath, "%s/%s", buf, path) < 0) return -1; - } - VIR_FREE(buf); } =20 return 0; @@ -3487,7 +3426,7 @@ virFileRemoveLastComponent(char *path) int virFilePrintf(FILE *fp, const char *msg, ...) { va_list vargs; - char *str; + VIR_AUTOFREE(char *) str =3D NULL; int ret; =20 va_start(vargs, msg); @@ -3501,8 +3440,6 @@ int virFilePrintf(FILE *fp, const char *msg, ...) ret =3D -1; } =20 - VIR_FREE(str); - cleanup: va_end(vargs); =20 @@ -3538,7 +3475,8 @@ int virFileIsSharedFSType(const char *path, int fstypes) { - char *dirpath, *p; + VIR_AUTOFREE(char *) dirpath =3D NULL; + char *p; struct statfs sb; int statfs_ret; =20 @@ -3558,7 +3496,6 @@ virFileIsSharedFSType(const char *path, if ((p =3D strrchr(dirpath, '/')) =3D=3D NULL) { virReportSystemError(EINVAL, _("Invalid relative path '%s'"), path); - VIR_FREE(dirpath); return -1; } =20 @@ -3571,8 +3508,6 @@ virFileIsSharedFSType(const char *path, =20 } while ((statfs_ret < 0) && (p !=3D dirpath)); =20 - VIR_FREE(dirpath); - if (statfs_ret < 0) { virReportSystemError(errno, _("cannot determine filesystem for '%s'"), @@ -3639,18 +3574,20 @@ virFileGetHugepageSize(const char *path, static int virFileGetDefaultHugepageSize(unsigned long long *size) { - int ret =3D -1; - char *meminfo, *c, *n, *unit; + VIR_AUTOFREE(char *) meminfo =3D NULL; + char *c; + char *n; + char *unit; =20 if (virFileReadAll(PROC_MEMINFO, 4096, &meminfo) < 0) - goto cleanup; + return -1; =20 if (!(c =3D strstr(meminfo, HUGEPAGESIZE_STR))) { virReportError(VIR_ERR_NO_SUPPORT, _("%s not found in %s"), HUGEPAGESIZE_STR, PROC_MEMINFO); - goto cleanup; + return -1; } c +=3D strlen(HUGEPAGESIZE_STR); =20 @@ -3663,13 +3600,10 @@ virFileGetDefaultHugepageSize(unsigned long long *s= ize) virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse %s %s"), HUGEPAGESIZE_STR, c); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(meminfo); - return ret; + return 0; } =20 # define PROC_MOUNTS "/proc/mounts" @@ -3963,10 +3897,8 @@ virFileCopyACLs(const char *src, int virFileComparePaths(const char *p1, const char *p2) { - int ret =3D -1; - char *res1, *res2; - - res1 =3D res2 =3D NULL; + VIR_AUTOFREE(char *) res1 =3D NULL; + VIR_AUTOFREE(char *) res2 =3D NULL; =20 /* Assume p1 and p2 are symlinks, so try to resolve and canonicalize t= hem. * Canonicalization fails for example on file systems names like 'proc= ' or @@ -3975,19 +3907,13 @@ virFileComparePaths(const char *p1, const char *p2) */ ignore_value(virFileResolveLink(p1, &res1)); if (!res1 && VIR_STRDUP(res1, p1) < 0) - goto cleanup; + return -1; =20 ignore_value(virFileResolveLink(p2, &res2)); if (!res2 && VIR_STRDUP(res2, p2) < 0) - goto cleanup; + return -1; =20 - ret =3D STREQ_NULLABLE(res1, res2); - - cleanup: - VIR_FREE(res1); - VIR_FREE(res2); - - return ret; + return STREQ_NULLABLE(res1, res2); } =20 =20 @@ -4131,25 +4057,22 @@ virFileInData(int fd ATTRIBUTE_UNUSED, int virFileReadValueInt(int *value, const char *format, ...) { - int ret =3D -1; - char *str =3D NULL; - char *path =3D NULL; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; va_list ap; =20 va_start(ap, format); if (virVasprintf(&path, format, ap) < 0) { va_end(ap); - goto cleanup; + return -1; } va_end(ap); =20 - if (!virFileExists(path)) { - ret =3D -2; - goto cleanup; - } + if (!virFileExists(path)) + return -2; =20 if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) - goto cleanup; + return -1; =20 virStringTrimOptionalNewline(str); =20 @@ -4157,14 +4080,10 @@ virFileReadValueInt(int *value, const char *format,= ...) virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid integer value '%s' in file '%s'"), str, path); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(str); - return ret; + return 0; } =20 =20 @@ -4181,25 +4100,22 @@ virFileReadValueInt(int *value, const char *format,= ...) int virFileReadValueUint(unsigned int *value, const char *format, ...) { - int ret =3D -1; - char *str =3D NULL; - char *path =3D NULL; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; va_list ap; =20 va_start(ap, format); if (virVasprintf(&path, format, ap) < 0) { va_end(ap); - goto cleanup; + return -1; } va_end(ap); =20 - if (!virFileExists(path)) { - ret =3D -2; - goto cleanup; - } + if (!virFileExists(path)) + return -2; =20 if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) - goto cleanup; + return -1; =20 virStringTrimOptionalNewline(str); =20 @@ -4207,14 +4123,10 @@ virFileReadValueUint(unsigned int *value, const cha= r *format, ...) virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid unsigned integer value '%s' in file '%s'= "), str, path); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(str); - return ret; + return 0; } =20 =20 @@ -4231,26 +4143,23 @@ virFileReadValueUint(unsigned int *value, const cha= r *format, ...) int virFileReadValueScaledInt(unsigned long long *value, const char *format, .= ..) { - int ret =3D -1; - char *str =3D NULL; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; char *endp =3D NULL; - char *path =3D NULL; va_list ap; =20 va_start(ap, format); if (virVasprintf(&path, format, ap) < 0) { va_end(ap); - goto cleanup; + return -1; } va_end(ap); =20 - if (!virFileExists(path)) { - ret =3D -2; - goto cleanup; - } + if (!virFileExists(path)) + return -2; =20 if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) - goto cleanup; + return -1; =20 virStringTrimOptionalNewline(str); =20 @@ -4258,14 +4167,10 @@ virFileReadValueScaledInt(unsigned long long *value= , const char *format, ...) virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid unsigned scaled integer value '%s' in fi= le '%s'"), str, path); - goto cleanup; + return -1; } =20 - ret =3D virScaleInteger(value, endp, 1024, ULLONG_MAX); - cleanup: - VIR_FREE(path); - VIR_FREE(str); - return ret; + return virScaleInteger(value, endp, 1024, ULLONG_MAX); } =20 /* Arbitrarily sized number, feel free to change, but the function should = be @@ -4285,37 +4190,30 @@ virFileReadValueScaledInt(unsigned long long *value= , const char *format, ...) int virFileReadValueBitmap(virBitmapPtr *value, const char *format, ...) { - int ret =3D -1; - char *str =3D NULL; - char *path =3D NULL; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; va_list ap; =20 va_start(ap, format); if (virVasprintf(&path, format, ap) < 0) { va_end(ap); - goto cleanup; + return -1; } va_end(ap); =20 - if (!virFileExists(path)) { - ret =3D -2; - goto cleanup; - } + if (!virFileExists(path)) + return -2; =20 if (virFileReadAll(path, VIR_FILE_READ_VALUE_STRING_MAX, &str) < 0) - goto cleanup; + return -1; =20 virStringTrimOptionalNewline(str); =20 *value =3D virBitmapParseUnlimited(str); if (!*value) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(str); - return ret; + return 0; } =20 /** @@ -4333,30 +4231,26 @@ virFileReadValueBitmap(virBitmapPtr *value, const c= har *format, ...) int virFileReadValueString(char **value, const char *format, ...) { - int ret =3D -1; - char *str =3D NULL; - char *path =3D NULL; + int ret; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; va_list ap; =20 va_start(ap, format); if (virVasprintf(&path, format, ap) < 0) { va_end(ap); - goto cleanup; + return -1; } va_end(ap); =20 - if (!virFileExists(path)) { - ret =3D -2; - goto cleanup; - } + if (!virFileExists(path)) + return -2; =20 ret =3D virFileReadAll(path, VIR_FILE_READ_VALUE_STRING_MAX, value); =20 if (*value) virStringTrimOptionalNewline(*value); - cleanup: - VIR_FREE(path); - VIR_FREE(str); + return ret; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504595839349.1740977551656; Fri, 13 Jul 2018 10:56:35 -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 68AE5308A945; Fri, 13 Jul 2018 17:56:32 +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 0F5FB2010D5B; Fri, 13 Jul 2018 17:56:32 +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 917F3264D3; Fri, 13 Jul 2018 17:56:31 +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 w6DHtxhI008466 for ; Fri, 13 Jul 2018 13:55:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2A6D12010CC6; Fri, 13 Jul 2018 17:55:59 +0000 (UTC) Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 189AE2010CCE for ; Fri, 13 Jul 2018 17:55:56 +0000 (UTC) Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 42E20308FBB3 for ; Fri, 13 Jul 2018 17:55:45 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id g2-v6so384994pgs.6 for ; Fri, 13 Jul 2018 10:55:45 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:44 -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=T+H8SFa+LmTwyrUZ9ocje81gauVgyt7pcnyPdoNw8O0=; b=u3K1xgDVl+BzgfnEH/xEM98hT90mSIuZSyT/dAOyRXzACBPAkaN65p/QcZnXCyGh2R y2S4q6wrDwH0nBnI1+pfrKGpqQJzdLo+9OAtKrLk9WFnAGmkxsRoo6mUS3OtvMbUvVo5 jd1MPkORsRIHUL3+k1VmxVx4Gy4IeqJm30ByAgsS5lb9TW/i9YSfuyKdTlBJiAjyNlYf K/IoNxcgq3KVTa5oeIrW/y8Bd8cv6U7VuObxGtai3CKVU9e/28DMVrPnVOP9RrchdoKY zoNSirtDGST0e81xEKyJpEajugyZg6fPoi8G0Dm3aSOoHcHTwRx4MpS9DD3f8g2NUKv5 +r0A== 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=T+H8SFa+LmTwyrUZ9ocje81gauVgyt7pcnyPdoNw8O0=; b=fw6WmkcdkiC4duW0D13nlHL4G1EYT9PnY639qS4Hi0L15iZrpQEpt6Mk8KlSawGCz6 wcy0wUcqFZb4kLLgS3GTnZOoB1tMfyKFZNU8boqvvroImBm8OfA0CJadnkcr5GlrA/y2 2M2knPon9FEbjLewV7YI5uw/grGKcs1Eyv3wbtbF3uwuPlPmiTRPcG+theGoYjcIBTiD NC/U9QtI6S+5mQMnd0tn+OXGGxKRqcj0R6gZpqcmtaDcXysCFRyM8U4Hf1tmRhj/s8fl r/hRRkVj/Xq1HD2Bfcy5VRDJ3QhcKkC6UyGkl+c9cAQ6l3YjN+8n7lk+89nQGe+E/ppg p3CA== X-Gm-Message-State: AOUpUlGwHMJsBn8fp1Kbi4zmtSNhlrqxxWGo+XBQwIo4ApAoOLTnYB+C XhogfUIXcGe2MPmlsXy4yJ6Ca+wD X-Google-Smtp-Source: AAOMgpepWmeSW/ig0jE6HQJGOdUGKP2RDsKyaINm+sJFB2/AfCDnpcDqJVuy0u0OgP8dCsMQoAuQKw== X-Received: by 2002:a62:e18:: with SMTP id w24-v6mr8128425pfi.145.1531504544506; Fri, 13 Jul 2018 10:55:44 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:49 +0530 Message-Id: <1531504509-7930-12-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.43]); Fri, 13 Jul 2018 17:55:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 13 Jul 2018 17:55:45 +0000 (UTC) for IP:'209.85.215.174' DOMAIN:'mail-pg1-f174.google.com' HELO:'mail-pg1-f174.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.215.174 mail-pg1-f174.google.com 209.85.215.174 mail-pg1-f174.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.43 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 11/31] util: file: 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.41]); Fri, 13 Jul 2018 17:56:35 +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/virfile.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 3a7445f..6b94885 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -888,20 +888,19 @@ int virFileNBDDeviceAssociate(const char *file, { VIR_AUTOFREE(char *) nbddev =3D NULL; VIR_AUTOFREE(char *) qemunbd =3D NULL; - virCommandPtr cmd =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virCommand) cmd =3D NULL; const char *fmtstr =3D NULL; =20 if (!virFileNBDLoadDriver()) - goto cleanup; + return -1; =20 if (!(nbddev =3D virFileNBDDeviceFindUnused())) - goto cleanup; + return -1; =20 if (!(qemunbd =3D virFindFileInPath("qemu-nbd"))) { virReportSystemError(ENOENT, "%s", _("Unable to find 'qemu-nbd' binary in $PATH"= )); - goto cleanup; + return -1; } =20 if (fmt > 0) @@ -926,17 +925,14 @@ int virFileNBDDeviceAssociate(const char *file, /* qemu-nbd will daemonize itself */ =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Associated NBD device %s with file %s and format %s", nbddev, file, fmtstr); *dev =3D nbddev; nbddev =3D NULL; - ret =3D 0; =20 - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 #else /* __linux__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504572972471.75925631755797; Fri, 13 Jul 2018 10:56:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EBEA93084054; Fri, 13 Jul 2018 17:56:10 +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 A5D9660BE5; Fri, 13 Jul 2018 17:56:10 +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 3876E18037F8; Fri, 13 Jul 2018 17:56:10 +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 w6DHtvGp008450 for ; Fri, 13 Jul 2018 13:55:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id CE3CCC6A35; Fri, 13 Jul 2018 17:55:57 +0000 (UTC) Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C6BD4BEDEB for ; Fri, 13 Jul 2018 17:55:57 +0000 (UTC) Received: from mail-pl0-f65.google.com (mail-pl0-f65.google.com [209.85.160.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 2235F3082A51 for ; Fri, 13 Jul 2018 17:55:47 +0000 (UTC) Received: by mail-pl0-f65.google.com with SMTP id p23-v6so1245179plo.6 for ; Fri, 13 Jul 2018 10:55:47 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:45 -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=dzDn0vhvf2KID8B6UFIcengK+BIop5A9oQdtjXZ1WVM=; b=F8uFgIyANB2apAj6BQsY7lwzfJbW+QfuJLe1W1WsATMELYZnejYEiPQRPvkBQrpo4s M+DeTbrcX2aBM0rKnzd6dIcRQdzE87IcBIcLd+dkC9yLKQo1KahoA4iXYbBvZ0jBo3ne +REnjILqeQXsFqHfFPwEu2poWduN/nt3wLlcSI43/+RKiY/41V9R8+D50aR7zZFsiIwd FeTmvOuYu/5j4iMN18VKW0YUERpiaTVOwliJEXkolXKHBsIIlkG/7ukQ43RIQ1EwL1yf LqJWSX/9vB7LtEmp1YukM2TBTjsatmrR3ohDh3t1iRFCzHL7Q8JB+lsgUGUZ5kAaTLsC vCww== 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=dzDn0vhvf2KID8B6UFIcengK+BIop5A9oQdtjXZ1WVM=; b=WPJgl0CEu8gLO8mCPJgtLgfTxOP+WSC9QfoYiclbsbvY4p9kK9hDVzRRuiVya1Z6nL cbxtgBvRdAPRqxwhR2HgrY2nxgidTPJBr14Iye95VXbVJ5BfqFKjVNppCzZI18ZI+7Df ALWhr1Zhn4U+cx9oZTNexlIH1psugSUKac8cwOgRBI0ndC8/A+dp4I710EeJ81V+xpGX gf8MfEssnT5tCjs6e4nLFVOSvPh6xls3Mh6OZgkii4Bqeuq79yaPmwthDpwW4EezN4qW +2jiKHw+cjiuDaIVpF9BLETdZpZAEPr5vlDKsRRxa5S5MoE1C2oQjEjKCxAR8TczctJY xiFA== X-Gm-Message-State: AOUpUlGMBhBi0ccUD8UYHACwUbthp67OyDKeXDhCQ129fATNky6Wb/6A ILWhiGmYY/7hKxXtlZwXdhqHRwNy X-Google-Smtp-Source: AAOMgpelNDSnmn/tINbvsZ+GmRMPt7cg8Y0yI2p9m9ASzOXCtrAdGp2aqv0qCfFmVy9axlYtxEjLlg== X-Received: by 2002:a17:902:8306:: with SMTP id bd6-v6mr7421171plb.120.1531504546411; Fri, 13 Jul 2018 10:55:46 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:50 +0530 Message-Id: <1531504509-7930-13-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.45]); Fri, 13 Jul 2018 17:55:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 13 Jul 2018 17:55:47 +0000 (UTC) for IP:'209.85.160.65' DOMAIN:'mail-pl0-f65.google.com' HELO:'mail-pl0-f65.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (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) 209.85.160.65 mail-pl0-f65.google.com 209.85.160.65 mail-pl0-f65.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 12/31] util: authconfig: 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 13 Jul 2018 17:56:11 +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. When a variable of type virAuthConfigPtr is declared using VIR_AUTOPTR, the function virAuthConfigFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virauthconfig.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/util/virauthconfig.h b/src/util/virauthconfig.h index ac0ceeb..d8a3849 100644 --- a/src/util/virauthconfig.h +++ b/src/util/virauthconfig.h @@ -24,6 +24,7 @@ # define __VIR_AUTHCONFIG_H__ =20 # include "internal.h" +# include "viralloc.h" =20 typedef struct _virAuthConfig virAuthConfig; typedef virAuthConfig *virAuthConfigPtr; @@ -42,4 +43,6 @@ int virAuthConfigLookup(virAuthConfigPtr auth, const char *credname, const char **value); =20 +VIR_DEFINE_AUTOPTR_FUNC(virAuthConfig, virAuthConfigFree) + #endif /* __VIR_AUTHCONFIG_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 15315045827381001.6089355039859; Fri, 13 Jul 2018 10:56:22 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 02B4113AB2; Fri, 13 Jul 2018 17:56:21 +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 A70C75FCA8; Fri, 13 Jul 2018 17:56: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 516BE1800541; Fri, 13 Jul 2018 17:56:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHu7kh008509 for ; Fri, 13 Jul 2018 13:56:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9CC5F30012C2; Fri, 13 Jul 2018 17:56:07 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 857FD3083329 for ; Fri, 13 Jul 2018 17:56:00 +0000 (UTC) Received: from mail-pl0-f54.google.com (mail-pl0-f54.google.com [209.85.160.54]) (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 0FF365F758 for ; Fri, 13 Jul 2018 17:55:49 +0000 (UTC) Received: by mail-pl0-f54.google.com with SMTP id f4-v6so8310124plb.9 for ; Fri, 13 Jul 2018 10:55:49 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:47 -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=P7Lb2tptf5xhPcZpEmAhydYmBydN2nMRncTSA2rpKhY=; b=Zfp3Hojg2E65bRusfC2vnp9FNmUovElwhUMvx4wkjn+xwjvX2Y+YhNd6Fy+5mA8axW nEZgKSJV9VnKrFNL8VC/DHxb+HDY/vKtFpfqa4Y/KK4l1it1PN3aWZw7j88mJ9MxIa9s 8GJU8Sm9YJa0zsLea9ogxQRzUkPHY6RQ+F9oNFbAkC0LekVR/pzNSxYxrPAIc0sXeRgI V8Sj/q5rfpYWuoWzZvxwKxQ+anYvAvlLJtXaJk/o7OimSN4zlRrIc48a+IgFrDlwcBKK E8UQRzCK61mN4/55Rq3lGw2IfX2d/nWzFDitX3rKtEfVmcFKGodBU3vIVlHIpm4r1xcn DfOg== 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=P7Lb2tptf5xhPcZpEmAhydYmBydN2nMRncTSA2rpKhY=; b=ec3o7kaWnk7UW4g/fE3J1yH3eCmbj6YyUwl+xMfXsc9nHgVPz6/TC8H9xFU1tdrN7d YJzvcrsoJ2WtGrZIE3f8iJEZt0EgwkVPqfxHgrg8gfNVWTvhxD5NBP/AX36lzEuSPJr7 XvSQXi87XUotxXM2Wy9DjmZZzcl4FPdP7qqZjT2DiF3lEBpe+cjI2sezQZt/mK9ICzRz cljv6h1bLeUOIDYwAf+dT4cQR3/5WrzsuHZiQ5UJaPAFd3PcLIGjkknymdiOWt8/wWUw C5Qfo7IvICPUj6YiV/jWRG1irz27BAhHH6bpnf+tEBvYdGsCsN1V6FHUQw8q/KRWvBZD DlOg== X-Gm-Message-State: AOUpUlErJpFo8UW+3CrC8HR6QRmwqe7rThxiOgu2YIHN4bXi5pJmEmW7 pTV1O0JlZFVtYvDsxL08B5zfDuM7 X-Google-Smtp-Source: AAOMgpcUHMdfkxiDWiZO3PIcdRcI/u+WgkTw2+vJ3o1BE2/YhZDy0CmvUAAxQKl6hqCk5IMfRtiERg== X-Received: by 2002:a17:902:b717:: with SMTP id d23-v6mr7353727pls.105.1531504548185; Fri, 13 Jul 2018 10:55:48 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:51 +0530 Message-Id: <1531504509-7930-14-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.39]); Fri, 13 Jul 2018 17:55:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 13 Jul 2018 17:55:49 +0000 (UTC) for IP:'209.85.160.54' DOMAIN:'mail-pl0-f54.google.com' HELO:'mail-pl0-f54.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.160.54 mail-pl0-f54.google.com 209.85.160.54 mail-pl0-f54.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 13/31] util: authconfig: remove redundant include directive 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 13 Jul 2018 17:56:22 +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" viralloc.h is pulled in by virauthconfig.h Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virauthconfig.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c index 91c9c0c..3487cc2 100644 --- a/src/util/virauthconfig.c +++ b/src/util/virauthconfig.c @@ -25,7 +25,6 @@ #include "virauthconfig.h" =20 #include "virkeyfile.h" -#include "viralloc.h" #include "virlog.h" #include "virerror.h" #include "virstring.h" --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504577816939.9749534858925; Fri, 13 Jul 2018 10:56:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 48E6C3E2D1; Fri, 13 Jul 2018 17:56:16 +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 0AA3819489; Fri, 13 Jul 2018 17:56:16 +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 9ABC63FCC1; Fri, 13 Jul 2018 17:56:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHu3Eh008489 for ; Fri, 13 Jul 2018 13:56:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id BAD9E3001A55; Fri, 13 Jul 2018 17:56:03 +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 B45B330012C2 for ; Fri, 13 Jul 2018 17:56:01 +0000 (UTC) Received: from mail-pl0-f49.google.com (mail-pl0-f49.google.com [209.85.160.49]) (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 C67A7308212A for ; Fri, 13 Jul 2018 17:55:50 +0000 (UTC) Received: by mail-pl0-f49.google.com with SMTP id 30-v6so12500845pld.13 for ; Fri, 13 Jul 2018 10:55:50 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:49 -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=LEDiP2AJsHYedYtV7+w0+drJZu9pqfEmlvox/BaUu7s=; b=Zg288JHDNHGZJ0l+oYOBquMsUyLDAf0j9SafzhtFaQEbr0UdUQpNQe3ZER0dSggPGS s7uEariZSfLH6WEbaMcCBhIRgK4vd9dFk84y/NyKWaiBg1x3WLt6ztxjmMhrNk3dz/o+ QGleTmAC5duXc4ZdLfaVi+hQoxxrOGIvFVWY1dWhuMvYsO+uBAqawGmoM7CEJm3Odvtb Z2vAGBhrPm/i2xm6lp6tXTz8dyzMK4SdV/GEjYBz+THzNSFoxYX+wf00fWOiSPicNepe yQSORvz1XqdEZ3RUWFHjVrctM+NSP9DtWLWXytFOlcsPHwIp8PQJn/wanHfxlBoGIGVY Sq+w== 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=LEDiP2AJsHYedYtV7+w0+drJZu9pqfEmlvox/BaUu7s=; b=tpVvVXcTMV5ddp5fePZ/5CXt9oWu4nykyQBc/GBs73cxeNYPD2aDx34qa7lcKgGIWr 1pMYq+4fBkTqtDnBe1Q0r0JoXDFU+HMfvlI8u0zZQy43V7G4DpDZe/2NXjBOHnzoGpls 69Ns8xprtTiBGYwPnjkV660Mtjt8HyvOleaiivv8VEBx/HH2Lq+lmedm/kFDP0O1D1CI 1GPr+QucFkD7GW8FRGt4d+aKp3V3uVPs6FXTihxnuhIy0+U4WTevtW+Gzqx2En1VUsnw L08kYRnN6w3N02V7kh79CmY+F1FGZA3o8Q8V0vUTxWJVAebFx+igPjCom29pUG5IGB7Y 44lg== X-Gm-Message-State: AOUpUlH/FhdWqqzG7vR2u7BVppyBm3yRzS9ds3R8y1c7UBthCktUc+X0 m0OtpIDn8rqU1IkdtkoQq4VXP+La X-Google-Smtp-Source: AAOMgpf2ZVret1nIbA439Xktzc5+ekZ8yYIqLfYrJxnQRJn+mTTzbrhib1map8YSH7Qv6VvKVKOebw== X-Received: by 2002:a17:902:bc8c:: with SMTP id bb12-v6mr7429489plb.84.1531504550075; Fri, 13 Jul 2018 10:55:50 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:52 +0530 Message-Id: <1531504509-7930-15-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.42]); Fri, 13 Jul 2018 17:55:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 13 Jul 2018 17:55:50 +0000 (UTC) for IP:'209.85.160.49' DOMAIN:'mail-pl0-f49.google.com' HELO:'mail-pl0-f49.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.160.49 mail-pl0-f49.google.com 209.85.160.49 mail-pl0-f49.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.42 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 14/31] util: authconfig: 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 13 Jul 2018 17:56:17 +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 Reviewed-by: Erik Skultety --- src/util/virauthconfig.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c index 3487cc2..4acdf1d 100644 --- a/src/util/virauthconfig.c +++ b/src/util/virauthconfig.c @@ -105,10 +105,9 @@ int virAuthConfigLookup(virAuthConfigPtr auth, const char *credname, const char **value) { - char *authgroup =3D NULL; - char *credgroup =3D NULL; + VIR_AUTOFREE(char *) authgroup =3D NULL; + VIR_AUTOFREE(char *) credgroup =3D NULL; const char *authcred; - int ret =3D -1; =20 *value =3D NULL; =20 @@ -118,47 +117,38 @@ int virAuthConfigLookup(virAuthConfigPtr auth, hostname =3D "localhost"; =20 if (virAsprintf(&authgroup, "auth-%s-%s", service, hostname) < 0) - goto cleanup; + return -1; =20 if (!virKeyFileHasGroup(auth->keyfile, authgroup)) { VIR_FREE(authgroup); if (virAsprintf(&authgroup, "auth-%s-%s", service, "default") < 0) - goto cleanup; + return -1; } =20 - if (!virKeyFileHasGroup(auth->keyfile, authgroup)) { - ret =3D 0; - goto cleanup; - } + if (!virKeyFileHasGroup(auth->keyfile, authgroup)) + return 0; =20 if (!(authcred =3D virKeyFileGetValueString(auth->keyfile, authgroup, = "credentials"))) { virReportError(VIR_ERR_CONF_SYNTAX, _("Missing item 'credentials' in group '%s' in '%s'= "), authgroup, auth->path); - goto cleanup; + return -1; } =20 if (virAsprintf(&credgroup, "credentials-%s", authcred) < 0) - goto cleanup; + return -1; =20 if (!virKeyFileHasGroup(auth->keyfile, credgroup)) { virReportError(VIR_ERR_CONF_SYNTAX, _("Missing group 'credentials-%s' referenced from g= roup '%s' in '%s'"), authcred, authgroup, auth->path); - goto cleanup; + return -1; } =20 - if (!virKeyFileHasValue(auth->keyfile, credgroup, credname)) { - ret =3D 0; - goto cleanup; - } + if (!virKeyFileHasValue(auth->keyfile, credgroup, credname)) + return 0; =20 *value =3D virKeyFileGetValueString(auth->keyfile, credgroup, credname= ); =20 - ret =3D 0; - - cleanup: - VIR_FREE(authgroup); - VIR_FREE(credgroup); - return ret; + return 0; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504601018888.8029029839971; Fri, 13 Jul 2018 10:56:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51DBE3001532; Fri, 13 Jul 2018 17:56:39 +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 076245DA2A; Fri, 13 Jul 2018 17:56:39 +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 5EC0024F67; Fri, 13 Jul 2018 17:56:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHu5UI008495 for ; Fri, 13 Jul 2018 13:56:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4930160F86; Fri, 13 Jul 2018 17:56:05 +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 4082F60BE5 for ; Fri, 13 Jul 2018 17:56:03 +0000 (UTC) Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 809C6C057F84 for ; Fri, 13 Jul 2018 17:55:52 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id x5-v6so5229222pgp.7 for ; Fri, 13 Jul 2018 10:55:52 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:51 -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=CrrUERYpADUP4E1r8eaUMajzC5/moHvnvVtEm06Tmb8=; b=OV3/merDnOoZgF8+lTsb+wnwEyXa3izWiwBhFgps+Crb59KPmJ53oFzSBSvR49e813 qH6orXDGYdNTCa20T12sZVUBHPP0Al9Eqc5mc1gw4nlJUI6I+TX8Kw/PEaeIGpdxb0Yl A3MJ35YlaavCe9ZihpaGbspC6f6BfyC1BVRIqzws+RbcP8j1FTT/+kDcFGsa8UiBQsKj mh3HuV/vC4Gs8PWAtCBVAOGNhYXzbxp+9jgaic4JgRKqspwnIMQ0u5SWAgf94B0MPK12 j+5b9JKTHS8XTV4F2k6yfWDpWZTmCic8SSRZw3lBpuqoxgXu2kdzxDE81XEb/QhCfqBV 1LYQ== 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=CrrUERYpADUP4E1r8eaUMajzC5/moHvnvVtEm06Tmb8=; b=q5rMmf9iBKPYULA+amourNO+ZBuhMn4zkQvqf/u7AaCS7XQtT1gkbQK/hY3BrKftDa obD/SZx/pzlsxIutm4OD3ghQ2hJgNw0wnTnhvVQP+ecHtiNZifvsoTRuoWJFS3kvDkmB 5JFOkT4EH5OXRD+00185ZCp3ZQXpm5I3upx13A117RspZNBMWOzIX+knJu6S0MK01IWe m2UJRn6aTQARK/vInvpY4ti8Dvt8wolktPe0aM8KRmP8zDkb2LlxNYiXaiiWB5e8p7ya oRLuwmfAQWWLK35+uzTnj/YC79nRVGMVHRLckt7FbQ2sizyn+BTw/Hq421AiOtrs6DJJ HEZw== X-Gm-Message-State: AOUpUlFD9aSkVqQzCQ6tptvEF5oHxo1H189XwceIb5XTn4in3YWa85/P a98HOBtAeekn/Pw0UW2voo7wrdQE X-Google-Smtp-Source: AAOMgpd1Z5qWlpPCXsi4uoq2d+tlbMHWO+Nna0SUnzuk5lMxfdeRg05UEkptjIxP8YUY0g5jaNBAZg== X-Received: by 2002:a62:591a:: with SMTP id n26-v6mr8158322pfb.94.1531504551799; Fri, 13 Jul 2018 10:55:51 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:53 +0530 Message-Id: <1531504509-7930-16-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.32]); Fri, 13 Jul 2018 17:55:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 13 Jul 2018 17:55:52 +0000 (UTC) for IP:'209.85.215.170' DOMAIN:'mail-pg1-f170.google.com' HELO:'mail-pg1-f170.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.215.170 mail-pg1-f170.google.com 209.85.215.170 mail-pg1-f170.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 15/31] util: auth: remove redundant include directive 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 13 Jul 2018 17:56:40 +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" viralloc.h is pulled in by virauthconfig.h Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virauth.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util/virauth.c b/src/util/virauth.c index adb093e..c6a2ce7 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -26,7 +26,6 @@ =20 #include "virauth.h" #include "virutil.h" -#include "viralloc.h" #include "virlog.h" #include "datatypes.h" #include "virerror.h" --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504595244884.5705959359022; Fri, 13 Jul 2018 10:56:35 -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 C40BB307CF32; Fri, 13 Jul 2018 17:56: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 7FFBA2010CD0; Fri, 13 Jul 2018 17:56: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 0DD7824F63; Fri, 13 Jul 2018 17:56:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHuD6U008547 for ; Fri, 13 Jul 2018 13:56:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id CFA62608F8; Fri, 13 Jul 2018 17:56:13 +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 C5219608F7 for ; Fri, 13 Jul 2018 17:56:05 +0000 (UTC) Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) (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 8958D87645 for ; Fri, 13 Jul 2018 17:55:54 +0000 (UTC) Received: by mail-pf0-f195.google.com with SMTP id c21-v6so18430453pfn.8 for ; Fri, 13 Jul 2018 10:55:54 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:53 -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=IKs1SopZWc1FzU32Yw+Pjxpogk7AQzOm9Q8BKZrgh2c=; b=K40sb5df/5VOt+MU8LSpYIqFEduKMP+vxCNESyLQruKIsOCQXdsqs6Rkf+y2orfXzU /B9bfpOHqWqpzeb3rqBh01BQQQuThJj+gjsx1n4k9Hhe2dqriLK7+TjLHaU6+78RZ30O NQrMgvXwOXmrHR31Kh8ssn9G30hkg2E0SPoS4/KAkiV9rCWOpTfxADrO4AtKgNyaF5ke 5z1sr4d9vDKnm7f+66nwoUXPX+gLYPr3EgRwygs5dTSIHpK/QRXWBfp6+a+8sGmnBh/N zBG0wJHxrNJt3U7lLGnviSsSTreekqGOkZHVYvlAUKQGNYI4GX67W742L48oionqMM8w Zo2Q== 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=IKs1SopZWc1FzU32Yw+Pjxpogk7AQzOm9Q8BKZrgh2c=; b=okR5tqns5+TtzNYfwMR2ArCkKeniRGhlBUaTUf7jGl6Gf51vVZgMM+mpbrmuMa9tnw Mr3Z5ZBKP15TSwf8T5BcbLlI4ZoA48J6YSdw8W1BoRGiA2+Wl+jwdwzXde5UmbgfThQk nCynB3yFyqq63pHrfO4Tvngcq11vw8lXBl60WJGNjiHctoACxLSsyHjoIkZYsRNBIIRr ZziEBj/P/jzchd8K1gz8dwiPQPA6f+7ANaDK4gF1XCnwttdxNX545j8+WV5xDJFaEpSM OH66MBHWA1Ic3v7RqCZrmBA5mIX0WkWoEwiglMvBAJkym4TgznvZaM4zZL7Jxa+dEzBV BdiA== X-Gm-Message-State: AOUpUlHPLEV7mWVK9cUGEZYafwfhbQUSuiqcPHjIGp4W8oO+bfNh2xcW LbjeC0bnuQEDE0v3DA6gCU7Sfkdm X-Google-Smtp-Source: AAOMgpdfCNag/OU4y/ZZLLsp9l1xPzLBGLEF13CGIPdzjFoeDdb3FDyf567v1G6+MBxzhQmDU5WEfQ== X-Received: by 2002:a63:571d:: with SMTP id l29-v6mr6770959pgb.296.1531504553776; Fri, 13 Jul 2018 10:55:53 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:54 +0530 Message-Id: <1531504509-7930-17-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:55:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 13 Jul 2018 17:55:54 +0000 (UTC) for IP:'209.85.192.195' DOMAIN:'mail-pf0-f195.google.com' HELO:'mail-pf0-f195.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.192.195 mail-pf0-f195.google.com 209.85.192.195 mail-pf0-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 16/31] util: auth: 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.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 13 Jul 2018 17:56: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" 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 Reviewed-by: Erik Skultety --- src/util/virauth.c | 45 +++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/src/util/virauth.c b/src/util/virauth.c index c6a2ce7..d3a5cc7 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -41,10 +41,9 @@ int virAuthGetConfigFilePathURI(virURIPtr uri, char **path) { - int ret =3D -1; size_t i; const char *authenv =3D virGetEnvBlockSUID("LIBVIRT_AUTH_FILE"); - char *userdir =3D NULL; + VIR_AUTOFREE(char *) userdir =3D NULL; =20 *path =3D NULL; =20 @@ -53,7 +52,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri, if (authenv) { VIR_DEBUG("Using path from env '%s'", authenv); if (VIR_STRDUP(*path, authenv) < 0) - goto cleanup; + return -1; return 0; } =20 @@ -63,17 +62,17 @@ virAuthGetConfigFilePathURI(virURIPtr uri, uri->params[i].value) { VIR_DEBUG("Using path from URI '%s'", uri->params[i].value= ); if (VIR_STRDUP(*path, uri->params[i].value) < 0) - goto cleanup; + return -1; return 0; } } } =20 if (!(userdir =3D virGetUserConfigDirectory())) - goto cleanup; + return -1; =20 if (virAsprintf(path, "%s/auth.conf", userdir) < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Checking for readability of '%s'", *path); if (access(*path, R_OK) =3D=3D 0) @@ -82,7 +81,7 @@ virAuthGetConfigFilePathURI(virURIPtr uri, VIR_FREE(*path); =20 if (VIR_STRDUP(*path, SYSCONFDIR "/libvirt/auth.conf") < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Checking for readability of '%s'", *path); if (access(*path, R_OK) =3D=3D 0) @@ -91,13 +90,9 @@ virAuthGetConfigFilePathURI(virURIPtr uri, VIR_FREE(*path); =20 done: - ret =3D 0; - VIR_DEBUG("Using auth file '%s'", NULLSTR(*path)); - cleanup: - VIR_FREE(userdir); =20 - return ret; + return 0; } =20 =20 @@ -155,7 +150,7 @@ virAuthGetUsernamePath(const char *path, { unsigned int ncred; virConnectCredential cred; - char *prompt; + VIR_AUTOFREE(char *) prompt =3D NULL; char *ret =3D NULL; =20 if (virAuthGetCredential(servicename, hostname, "username", path, &ret= ) < 0) @@ -192,8 +187,6 @@ virAuthGetUsernamePath(const char *path, break; } =20 - VIR_FREE(prompt); - return cred.result; } =20 @@ -205,18 +198,13 @@ virAuthGetUsername(virConnectPtr conn, const char *defaultUsername, const char *hostname) { - char *ret; - char *path; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (virAuthGetConfigFilePath(conn, &path) < 0) return NULL; =20 - ret =3D virAuthGetUsernamePath(path, auth, servicename, + return virAuthGetUsernamePath(path, auth, servicename, defaultUsername, hostname); - - VIR_FREE(path); - - return ret; } =20 =20 @@ -229,7 +217,7 @@ virAuthGetPasswordPath(const char *path, { unsigned int ncred; virConnectCredential cred; - char *prompt; + VIR_AUTOFREE(char *) prompt =3D NULL; char *ret =3D NULL; =20 if (virAuthGetCredential(servicename, hostname, "password", path, &ret= ) < 0) @@ -263,8 +251,6 @@ virAuthGetPasswordPath(const char *path, break; } =20 - VIR_FREE(prompt); - return cred.result; } =20 @@ -276,15 +262,10 @@ virAuthGetPassword(virConnectPtr conn, const char *username, const char *hostname) { - char *ret; - char *path; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (virAuthGetConfigFilePath(conn, &path) < 0) return NULL; =20 - ret =3D virAuthGetPasswordPath(path, auth, servicename, username, host= name); - - VIR_FREE(path); - - return ret; + return virAuthGetPasswordPath(path, auth, servicename, username, hostn= ame); } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504588061805.6862896019821; Fri, 13 Jul 2018 10:56:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9B7D0804E3; Fri, 13 Jul 2018 17:56:26 +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 6028D5D962; Fri, 13 Jul 2018 17:56:26 +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 F14A81800CAE; Fri, 13 Jul 2018 17:56:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHu79x008514 for ; Fri, 13 Jul 2018 13:56:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id B5BB510694FC; Fri, 13 Jul 2018 17:56:07 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC6EA10694F0 for ; Fri, 13 Jul 2018 17:56:07 +0000 (UTC) Received: from mail-pf0-f175.google.com (mail-pf0-f175.google.com [209.85.192.175]) (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 71AA431676B1 for ; Fri, 13 Jul 2018 17:55:56 +0000 (UTC) Received: by mail-pf0-f175.google.com with SMTP id l9-v6so11409056pff.9 for ; Fri, 13 Jul 2018 10:55:56 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:55 -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=OO5Cnc1cHphWz0a2wgWnwMfIRQB3XqcPdqWWex2AGd4=; b=ucxlZBfJSZi4RvWgaPAUfL32K9e+YPlLk3tm+Z0JI4ZaET0Ww2E2qQGgF9/+ZZl5RI r4V4fspH+0db2VrkDVLgIa6EsnVSrvOMG+wFV6WZbgMcgt77rYQaUks0xeZ92b0Dj+L4 sEiLoVcXK1gCMU98pV1hAXeTKiVpSMOL5DOuBJcaDosmCwt54xR5Rv2h1RTBi9iO8JxT L5jwWlz7O2hpetPIYbXHNgcaAJywpko9rnzyuISty7RnW8UwOsPC2ktMvrMsBcmsbeyT toLMa9gyS5lW0pbt8ELiJ8dEilVVcbeWh1gdEVVXM6GGIYy+kkiGK7YpkarEJfYxU59e fLKA== 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=OO5Cnc1cHphWz0a2wgWnwMfIRQB3XqcPdqWWex2AGd4=; b=e78pQJ1mvZ4qkbmdw7MJ3/Jioc/mVIxPIMjJue+1tyNeJOo7hRZNGNeCHxa4jEKMGU do1ciwZO3d//YuN1qc6H86tn3/zjZuVLTtHzviFqwIDGoZTHB9K88fQntz0zGjlK4hh8 CKArQ/shjUnL7DlCk+leE/QhUi8NGcVFA52I7eQ7EcoqDNPGC9XcnwHZj07hFvsbPq36 Rd6wTMeazniX6g/U4dgJIDHlAPmyI0s7pfR2bouxiFt9+xnL92f7f3UyJax4hT5KDRbT cEA6HefzFX3DqJBboSUA8TND6UdEuyfg6RUqdKUP9PanE5yPF/ooAEIGulJsczNrTvdu 7MYg== X-Gm-Message-State: AOUpUlGOMK+Oi416qPT6QIt5jSd+yfiWA+hu4XiE4AZwoLYw+3v/kSx9 +LBYG5MKOzQ1kUGZhxCRQ+9vPDZ3 X-Google-Smtp-Source: AAOMgpf0i+G/hGPfLNo5KlHVd+c6Z8D0nXyVdKlc424M3nE5ZCG/6B2R7mw9hzrB+OdDSPSrJdJBDg== X-Received: by 2002:a65:5b08:: with SMTP id y8-v6mr6805166pgq.297.1531504555538; Fri, 13 Jul 2018 10:55:55 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:55 +0530 Message-Id: <1531504509-7930-18-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.41]); Fri, 13 Jul 2018 17:55:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 13 Jul 2018 17:55:56 +0000 (UTC) for IP:'209.85.192.175' DOMAIN:'mail-pf0-f175.google.com' HELO:'mail-pf0-f175.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.175 mail-pf0-f175.google.com 209.85.192.175 mail-pf0-f175.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 17/31] util: auth: 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 13 Jul 2018 17:56:27 +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/virauth.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/util/virauth.c b/src/util/virauth.c index d3a5cc7..8c450b6 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -111,8 +111,7 @@ virAuthGetCredential(const char *servicename, const char *path, char **value) { - int ret =3D -1; - virAuthConfigPtr config =3D NULL; + VIR_AUTOPTR(virAuthConfig) config =3D NULL; const char *tmp; =20 *value =3D NULL; @@ -121,23 +120,19 @@ virAuthGetCredential(const char *servicename, return 0; =20 if (!(config =3D virAuthConfigNew(path))) - goto cleanup; + return -1; =20 if (virAuthConfigLookup(config, servicename, hostname, credname, &tmp) < 0) - goto cleanup; + return -1; =20 if (VIR_STRDUP(*value, tmp) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - virAuthConfigFree(config); - 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 From nobody Mon May 13 08:39:18 2024 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 153150460652299.2037214264401; Fri, 13 Jul 2018 10:56:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CB0593086259; Fri, 13 Jul 2018 17:56:44 +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 8259C60BE5; Fri, 13 Jul 2018 17:56:44 +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 2138224F5B; Fri, 13 Jul 2018 17:56:44 +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 w6DHu9I3008524 for ; Fri, 13 Jul 2018 13:56:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5098E2010CF5; Fri, 13 Jul 2018 17:56:09 +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 453572010CF4 for ; Fri, 13 Jul 2018 17:56:09 +0000 (UTC) Received: from mail-pl0-f52.google.com (mail-pl0-f52.google.com [209.85.160.52]) (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 2042EC057F93 for ; Fri, 13 Jul 2018 17:55:58 +0000 (UTC) Received: by mail-pl0-f52.google.com with SMTP id k1-v6so12503398plt.2 for ; Fri, 13 Jul 2018 10:55:58 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55:56 -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=UZ1/2q7R4axLjLxkRLRryB4KWTzlXrFs+o04HcRivEc=; b=S+QB9iMwL2/sdTOudmOIiRO1sTT9ACVKfPVHiTJ9trtU5wR4Fm106/H8DaHAbSVtOf qRRUz04t3IBNmptKj+NHi77WJUgVWIUVnlLBrMvoVnXErpi8nSkvqaRGAf6ywn929f0N xb/U5jMU7UIlR+Z0MV2rvQLjcbEEvmnzYwV5uj8z6vXeWa3sBLAmt4IBCLtjOXiZvpnK pp/1GSBlAtysovxP/RhRJ2Fi1imwA3nMXO0/gpPgykXalS3Oep3EF7fPOuHz/dSNzBp2 2MKeU/gpIrwuyo6YAQUtcehfkKlmsQP+chsEBAQXZBcg9aEdZ8IwUyg0wmEdQ5pZC2UV qNYA== 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=UZ1/2q7R4axLjLxkRLRryB4KWTzlXrFs+o04HcRivEc=; b=ezQN7F4p0FMt6CaiTQhYMh1wv7TPtUgO11BEbotX+xaq8Th8/lBOqcqpRSoIrgcpJG 6wCYOtXkFud4uIXW3+1Xv37FMKVGiqGo7o3Z5rDoibD7AD3bln9CqvoAWW7F1R0Ye40y snJmXKldsCYOU5B2fkdtb6bjclJ8Nc89k0/g30ZiwJiEXruuGGywXCtzy7b452rTcyBu QbL3bK8lvpjBeFT6fYIbRRv0We1WHfH6/r1ZVKA3uxpN6PNpBJ/7O3BqCY1t7SB3KqaZ aMOakXKFWKxaCccqEsaVtzSdxoyfHM/vAZOZ4LYMNUU4qqb/pPKKTH4eFSSJCUxBqGrr 5FJg== X-Gm-Message-State: AOUpUlHxQ6PduX6OpKSq2cI+TO3Ca9kz+KRzh6gDPh1RKGjsHYQgBvru 2bKjk7l0/yoeG7PWprz8pFE9rp5N X-Google-Smtp-Source: AAOMgpcItGPBJRgdebDvPHzifRl3d5bheSakGJA08d+LOx5DhyJwSGbVhcqAM6oPmo/xNwQDk/zBMA== X-Received: by 2002:a17:902:28e4:: with SMTP id f91-v6mr3677381plb.70.1531504557387; Fri, 13 Jul 2018 10:55:57 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:56 +0530 Message-Id: <1531504509-7930-19-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.32]); Fri, 13 Jul 2018 17:55:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 13 Jul 2018 17:55:58 +0000 (UTC) for IP:'209.85.160.52' DOMAIN:'mail-pl0-f52.google.com' HELO:'mail-pl0-f52.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.160.52 mail-pl0-f52.google.com 209.85.160.52 mail-pl0-f52.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 18/31] util: json: 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 13 Jul 2018 17:56:45 +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. When a variable of type virJSONValuePtr is declared using VIR_AUTOPTR, the function virJSONValueFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virjson.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/util/virjson.h b/src/util/virjson.h index e4a82bd..75f7f17 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -26,6 +26,7 @@ =20 # include "internal.h" # include "virbitmap.h" +# include "viralloc.h" =20 # include =20 @@ -156,4 +157,6 @@ char *virJSONStringReformat(const char *jsonstr, bool p= retty); =20 virJSONValuePtr virJSONValueObjectDeflatten(virJSONValuePtr json); =20 +VIR_DEFINE_AUTOPTR_FUNC(virJSONValue, virJSONValueFree) + #endif /* __VIR_JSON_H_ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 153150462107999.0093245425569; Fri, 13 Jul 2018 10:57:01 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B01E0308404C; Fri, 13 Jul 2018 17:56:57 +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 6542F1812A; Fri, 13 Jul 2018 17:56:57 +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 E61E51800B81; Fri, 13 Jul 2018 17:56:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHuFSR008565 for ; Fri, 13 Jul 2018 13:56:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2A9EA6016F; Fri, 13 Jul 2018 17:56:15 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1D2B7600D1 for ; Fri, 13 Jul 2018 17:56:10 +0000 (UTC) Received: from mail-pl0-f49.google.com (mail-pl0-f49.google.com [209.85.160.49]) (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 044BB3084027 for ; Fri, 13 Jul 2018 17:56:00 +0000 (UTC) Received: by mail-pl0-f49.google.com with SMTP id m16-v6so12510751pls.11 for ; Fri, 13 Jul 2018 10:55:59 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:55: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=doKmHtcLCuiAU6oVcrJCEzflo+/Gtd1bD/FGT1gtCnA=; b=Ic1RfKjTpfBlUwdUnDMUbwaKyzFTz36uUiVDBIKrfSs2k0lZax5YIRkfnT/4WhWurb MJ3DMQbI1Ryh5QgU/JGoPToaydXDtDP+mmojjvqq8rSXuVcyZI4ClW/vgMoc+t0DuEHl PntzNJ9HYYFk1k1iEbrXDSfCZ5rYsSnOuLLSpyuynhq8nBwOHBbHAfyjcIAWAz1XuiBV hjR3tCSSr6E55rEq+2n3qkZVYxcakcTlHUWrD+ZOgeE3UiyH2KRpBDPeRvOnVBLpfnrx +jy7chTjQ0tPgA0ge45IwmG03x2Jb8AU3p8YbN6rq4nDZbTWSK0+MLtdn4z8xv+jxlvP QBUQ== 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=doKmHtcLCuiAU6oVcrJCEzflo+/Gtd1bD/FGT1gtCnA=; b=oSI8D6Eo/oWpsWBoaDIfUubo+QRPyLCGIH/CvVaGg6Oe7IpGSRLYFvSoSDLxmtwP8E pOc/sl4HLiRh4uwr7xfPLbE3YqgCoCbTqxQoaq4uFVIzV8FH8RteVOu/T3lHtVcMxTmO YHo/0FwtrOEymMyCObhVbRsYu9v5WhTZJ/8ycVjVhY8Vw/AcZvMK13FcsDa07oDJT/Rk SfyOCBMhZG5XvGFzPhwgzvEBoI662RLSG9apMyXbzwU7fzGaje/LoQZnjqS/jDEG2isN rMbnOrsu9YcBdS4rd6FrIRZRXJOsZBF749Jg++UybdK5YWVxbGRUCLyupDMFkx54/Rjn 7oTg== X-Gm-Message-State: AOUpUlEG4nDyYi9JNZenAcM7im5jXrydsabQupTIbOkFmWV6k7DyFmNe PqAeVZzlvtotMIlDs1XP6VPQ7VPb X-Google-Smtp-Source: AAOMgpe6q2c96M6IaxphgC+qUKpnw0Zt12sZ4sAAJahKJcGb5rQ+eJjp3kssBcc77r5MqY4zgt2Y7A== X-Received: by 2002:a17:902:24e:: with SMTP id 72-v6mr7331687plc.87.1531504559290; Fri, 13 Jul 2018 10:55:59 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:57 +0530 Message-Id: <1531504509-7930-20-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.40]); Fri, 13 Jul 2018 17:56:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 13 Jul 2018 17:56:00 +0000 (UTC) for IP:'209.85.160.49' DOMAIN:'mail-pl0-f49.google.com' HELO:'mail-pl0-f49.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.160.49 mail-pl0-f49.google.com 209.85.160.49 mail-pl0-f49.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 19/31] util: json: remove redundant include directive 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 13 Jul 2018 17:57:00 +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" viralloc.h is pulled in by virjson.h Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virjson.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 0559d40..92f3994 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -24,7 +24,6 @@ #include =20 #include "virjson.h" -#include "viralloc.h" #include "virerror.h" #include "virlog.h" #include "virstring.h" --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504612686439.2201655821058; Fri, 13 Jul 2018 10:56:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3D0AA804F5; Fri, 13 Jul 2018 17:56:51 +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 E88D860BE5; Fri, 13 Jul 2018 17:56:50 +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 933BF1800B7D; Fri, 13 Jul 2018 17:56:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHuDkq008541 for ; Fri, 13 Jul 2018 13:56:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 514B160F86; Fri, 13 Jul 2018 17:56:13 +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 47B7B5FCA8 for ; Fri, 13 Jul 2018 17:56:13 +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 D9E993082153 for ; Fri, 13 Jul 2018 17:56:01 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id m16-v6so12510777pls.11 for ; Fri, 13 Jul 2018 10:56:01 -0700 (PDT) Received: from centos.localdomain ([42.106.1.21]) by smtp.gmail.com with ESMTPSA id n5-v6sm26866817pgr.24.2018.07.13.10.55.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:56:00 -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=0ukjV0PyJ9bxthUAOGnYGDipxKdYOqhl1NpqvmoSe7g=; b=tQAIyhhSro/UWlRZ5/kwK10RY+VN5H3tmEkKvwqj8WhRL+HAxMqAGhL0tQBq3Eg4hR s80EvMRcLIcJNAGhyGC+wihdgl/Ru8WcEUe7eRFgVJLwXz9pwKJuEA0R/Pw0bCuqJ822 oiKKgUvKaba501mndtpX9ZT2oXXv9qMOOIZIK14Kbsts7sd0iinNY+9j2ByIHVK8KhYJ JqCxYi1M9dK+k2dJhpU3DdH8aqr6k1gbJGiddkd33Y7uhfbJmtYFVdDciczbBXU2lDta PkxOe7AeG0bZv+9Fr/zgtTk3FU/4h5UMVLE+mgl61IgiiohNZBdx83aD644AjdIWpP9K hFiQ== 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=0ukjV0PyJ9bxthUAOGnYGDipxKdYOqhl1NpqvmoSe7g=; b=HvKTQFzaHiEAg5BqE2816Epd8tS43pRYhahbDLn8qNjqObt35x/D1MFNuzSpWjTKZ5 fyIqhbSkbmiMp9fPsMoYZiqD0b+3bTTRqqHh7sy5BmCNggzNJ8HPkCrQlxGOMnvTxO7r 82pdKo4YQiNR3jexy2xKqGHzasNaU35zUynmmaKRlpOsoa8kbzXg7HfoJl31LqNFwhNx 6Bdqne3uAaKcnvS2qFJNNxeYSZHgVH7VAC4qimodLxqtokQZlR/8zL5bCvAfq8PblB2v zEnk+x64nZWZnw6HDUwlTSJgSZVtqz0WRTkSK8T1fLD+u9S6TPidqUpFlPC+ReNh0Fcx 7NbA== X-Gm-Message-State: AOUpUlGw+0zZyjnSEDHWyWa+r1TjeFotmIy8EIADmXxuTSU1VNbNT/Np v4zhe3OsEJZ0T5Z8KTGOjMNWsFgI X-Google-Smtp-Source: AAOMgpfKGXl1rWylOTUgJfvpV5xvibcodc/xKPJ4bgwmHi0Z5K0YUzPIbB3bdYMxIXVkuQjJhRAtGA== X-Received: by 2002:a17:902:1025:: with SMTP id b34-v6mr7264885pla.112.1531504561108; Fri, 13 Jul 2018 10:56:01 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:24:58 +0530 Message-Id: <1531504509-7930-21-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.42]); Fri, 13 Jul 2018 17:56:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 13 Jul 2018 17:56:02 +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.281 * (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) 209.85.160.68 mail-pl0-f68.google.com 209.85.160.68 mail-pl0-f68.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.42 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 20/31] 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 13 Jul 2018 17:56:52 +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 Reviewed-by: Erik Skultety --- 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 From nobody Mon May 13 08:39:18 2024 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 From nobody Mon May 13 08:39:18 2024 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 1531504584542410.6459162575459; Fri, 13 Jul 2018 10:56:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC55630832EE; Fri, 13 Jul 2018 17:56:21 +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 B6305C6A3A; Fri, 13 Jul 2018 17:56:21 +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 529833F7CC; Fri, 13 Jul 2018 17:56:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHuJ6F008898 for ; Fri, 13 Jul 2018 13:56:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 457B05DA2A; Fri, 13 Jul 2018 17:56:19 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3CC965D968 for ; Fri, 13 Jul 2018 17:56:16 +0000 (UTC) Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) (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 A5E3D32B675 for ; Fri, 13 Jul 2018 17:56:05 +0000 (UTC) Received: by mail-pf0-f195.google.com with SMTP id i26-v6so11625781pfo.12 for ; Fri, 13 Jul 2018 10:56:05 -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.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:56:04 -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=M36UNoRu6Q0TXlQLCg6APbBIy3D1NI7MRZNJpioEbtw=; b=H0EwYwrGRR02X0fwF0iwwAd9oJBp4IJPhdQGkQ2icstBIYihVMcj3cKPbhJ1cUFzaI E6Dbwt7H4CCS+LSn71Q7s5ljumrpJpWTOV81KsSp/gAqKrXJD5HCsSAOayUOquncv7MP I8zHsdRVr8iZQB+7C0CDzRRKUUVoG7vCsb+Z3wFQXnu+8NfOMfD3aoHzr2TvneIfcMfr xnP7HD6VK+OA3/9NHJOwKceFFK/rVxFzbQC4QO+QB/9b5bT5RsKCQ0pHCvGxsSUphax7 ixvj2irE2bWYHaTqp00QzbP4hm/etxVT4fky9CdANvASvMPBxqVTCzQcRwUzizsqFKsM Rzvg== 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=M36UNoRu6Q0TXlQLCg6APbBIy3D1NI7MRZNJpioEbtw=; b=KTFI9LoIwuQyIm/77tONopegNY6a/kFMjAkGA1F4RdvmqRpLRyyiPf8EnLjitNUCPL ZEQ8rA9LWHOtAv1z1XSQH+HPlTeOoQ5JsA5DSk51SgBWNcaV6WK8tCiiYx/XvxxNJkum zsyVchUmOOQOt8X39lUPHcV2IY3clZLLFfYHwLtNVzniZUhMSzSfo3R7ZVc69g7wNseF PB8vWyeaLoiT5yY5e/PBNeBaFWR/yFkXgz0r1lOlK71ev40TDdbXqyLxhmr2R5Uqr+yo m5YuY3bb0fT5hfiDecFuT3lzDiLCDt2Mlvq10X0hc0tP1aXVqXD6eIBbD9Qbbnc9N+EM 53MQ== X-Gm-Message-State: AOUpUlHvkRTIadTdJFD96Zu9pL8we+PuvongfdLNio4hAfNbR7dC5i5Q 6W9dASL0Gpo+pavBdHU4CgbpUA6z X-Google-Smtp-Source: AAOMgpdhObfEvHpbKYvBsLFiwxnU/SNbqaARwdSt8KUs3wZz0DcoHlgtEjIJTmMy3vDlvOhmtBSpiw== X-Received: by 2002:a62:4808:: with SMTP id v8-v6mr8137956pfa.89.1531504564947; Fri, 13 Jul 2018 10:56:04 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:25:00 +0530 Message-Id: <1531504509-7930-23-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.38]); Fri, 13 Jul 2018 17:56:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 13 Jul 2018 17:56:05 +0000 (UTC) for IP:'209.85.192.195' DOMAIN:'mail-pf0-f195.google.com' HELO:'mail-pf0-f195.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.192.195 mail-pf0-f195.google.com 209.85.192.195 mail-pf0-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 22/31] util: bitmap: 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.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 13 Jul 2018 17:56: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" 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. When a variable of type virBitmapPtr is declared using VIR_AUTOPTR, the function virBitmapFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virbitmap.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h index 2464814..312e7e2 100644 --- a/src/util/virbitmap.h +++ b/src/util/virbitmap.h @@ -25,6 +25,7 @@ # define __BITMAP_H__ =20 # include "internal.h" +# include "viralloc.h" =20 # include =20 @@ -155,4 +156,6 @@ void virBitmapSubtract(virBitmapPtr a, virBitmapPtr b) =20 void virBitmapShrink(virBitmapPtr map, size_t b); =20 +VIR_DEFINE_AUTOPTR_FUNC(virBitmap, virBitmapFree) + #endif --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504627586990.0986529042939; Fri, 13 Jul 2018 10:57:07 -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 B9B7FC056807; Fri, 13 Jul 2018 17:57:03 +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 687655B696; Fri, 13 Jul 2018 17:57:03 +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 E5F6124B76; Fri, 13 Jul 2018 17:57:02 +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 w6DHuKPD008931 for ; Fri, 13 Jul 2018 13:56:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9F8B46148; 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 9761A19489 for ; Fri, 13 Jul 2018 17:56:18 +0000 (UTC) Received: from mail-pf0-f175.google.com (mail-pf0-f175.google.com [209.85.192.175]) (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 88D16883AB for ; Fri, 13 Jul 2018 17:56:07 +0000 (UTC) Received: by mail-pf0-f175.google.com with SMTP id v15-v6so3038938pff.5 for ; Fri, 13 Jul 2018 10:56:07 -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.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:56:06 -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=EeJQCx59vcN9k5TA7zAIp9XVSrj/Z3FxFnzqgChEhlY=; b=uNAEqxm0J2IzvsHSnpkcGZ1fqP1/9heyrwQTJOZJsy2ZgOy7UbyEI0h2QyMRA2gFui biqGXzFov2qCvvK9BKSAWK4EAbt/s2NCLgTQpsSRzuPl/knKcBohAJ9BniPR0ZiDZzRV xJqVu6BLY+JfwPyD+FkU1Fu5a+CEVZeslR7nr9wnhCeROccP2/0xImgccTJWMaZP72Bw WYN7nYvwss49vqz9QMfsRqHWNyx7a7TD6Gi4aNxCySsQijsijfgpidq31e+dEO+XpNPy XsrUUgTat3Id5I7Iuf+y002AfnYTQ+3kJ1nmTpVS9e7XJutVop4g+I1H4gF4Jgv3rWOn LlqA== 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=EeJQCx59vcN9k5TA7zAIp9XVSrj/Z3FxFnzqgChEhlY=; b=AaL+x1iKnhhsyY4DP5Z7V2zNkkPrFenHoWUaAh59cAuj/AepYVqcI97EpZV8WN86Qc kvOhTxIXVoR59+nDlD1gyDgNgVpIjg1uLQwUS3kbYWsBCP5Uu1IZsirAt5sTadvdwi8C cGJYJqwyjU2fTHYIJ/ssW5RE1XOOuSuockaZKQUEsUPBFERhmGj93FqczAJ4pUsOYncu u7JKFMw3RfvhVvqSnctvlxCXTMsRkzogBaCWW9OsfvSg4ALphlyPizAkyTKGMjmMgW0S msFoxuvDyl05j18O7ihI2vhvjY1bKUKZQ/d8APM5pHEJybmieLMWMRzULNQzCGzRNr+E UPAg== X-Gm-Message-State: AOUpUlHMblNMoEd0FHK3E+i+tTi8FYQgHy5aHpUrovwj9EGpKyOKVRir XCTTA+NH1Urjw0mPo9f2KoSmSfUc X-Google-Smtp-Source: AAOMgpe6B0Ns7qp3PhBRrzwjAz2d/1GByXsN6IE4l55vkJzp4ggpLLnT9VMG4/t9YOoaT0Kh4MUwGA== X-Received: by 2002:a63:3d41:: with SMTP id k62-v6mr7054890pga.254.1531504566711; Fri, 13 Jul 2018 10:56:06 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:25:01 +0530 Message-Id: <1531504509-7930-24-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:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 13 Jul 2018 17:56:07 +0000 (UTC) for IP:'209.85.192.175' DOMAIN:'mail-pf0-f175.google.com' HELO:'mail-pf0-f175.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.175 mail-pf0-f175.google.com 209.85.192.175 mail-pf0-f175.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 23/31] util: bitmap: remove redundant include directive 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]); Fri, 13 Jul 2018 17:57:06 +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" viralloc.h is pulled in by virbitmap.h Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virbitmap.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 0cc5292..ef18dad 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -31,7 +31,6 @@ #include =20 #include "virbitmap.h" -#include "viralloc.h" #include "virbuffer.h" #include "c-ctype.h" #include "count-one-bits.h" --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 153150463978596.51355044717616; Fri, 13 Jul 2018 10:57:19 -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 6456A30E265F; Fri, 13 Jul 2018 17:57:18 +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 11B04300190D; Fri, 13 Jul 2018 17:57:15 +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 4203D2478B; Fri, 13 Jul 2018 17:57:15 +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 w6DHuNR9008963 for ; Fri, 13 Jul 2018 13:56:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 808EC2010CC6; Fri, 13 Jul 2018 17:56:23 +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 726122010CCE for ; Fri, 13 Jul 2018 17:56:20 +0000 (UTC) Received: from mail-pf0-f179.google.com (mail-pf0-f179.google.com [209.85.192.179]) (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 53A1B308214F for ; Fri, 13 Jul 2018 17:56:09 +0000 (UTC) Received: by mail-pf0-f179.google.com with SMTP id e10-v6so23052263pfn.1 for ; Fri, 13 Jul 2018 10:56:09 -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.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:56:08 -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=d4fgqMDHKHm08LqJYv/LKUjzCqd7g8xpsO56u7uQ59g=; b=opWl+NEe7RXCiY5P21wKGJ7R4YrqzhKoFaeYFScP9K/Av7baUdyvNxIpwpv4sQKfwb 5eLlQEHYVx300wn+PrWJaqemEP2CEWBSh8HB9B/oxeXJgpRAKtRNAXyUzWHWKW5Pw4/N PaP3bgglViFE0Aqt8rYhc66MrzrXqSywffHqdacQ4hxaZIjlTOnpoCHNsW5vo5SZG4kt BtS8HpPVhiIkfFm3mczuPqw2+bQpVWn/P1M4u0iX/WeOOrLSFI3t+rEyrpcHmtniZ71S zFFIBbREkJCtcgpakr+8aF2nKWSsmWsFfdDaPb5dlWz0Kmtvchyl0VB0LjT1vD8nlEXM qSJg== 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=d4fgqMDHKHm08LqJYv/LKUjzCqd7g8xpsO56u7uQ59g=; b=EDuPASsMYjz7wwVvcBRZKS/Gi9OjWa8Qs7btCPQOXr4CFP1qHXMKHZ/GPD2VnwniVz 26537yNUIaVVGmWdrUZArI2I0YIyNejZHMOyFT6a+14+H5AEn+MRgZk3+5jl3VklntJq alQNHiYqlmkXWBgCAwKE79l0Bn5dj8yI/jJLPjdzpAUTdBICsOzobEbiGIZjMIHjVyTg ERK8A87oD8RKohM6aG4Iuwa0YHxnaKiKhlotgt1Alric6C8EWfoVgeVQuSyJNzvtwa59 oybV5FyulVIch3wrCFK2n07hFxF3cBNyqBRZdjGB4Iaw1S8p9FuipL7pdYQIgZ+9W5e1 5UMw== X-Gm-Message-State: AOUpUlG5Rh0sN16rgU9n+LAEFgKwj6ojQLb3zXOLdMebyQ2bWfp545L9 bro8lk+2iUf0w4oXwyfmdF+faLA8 X-Google-Smtp-Source: AAOMgpeGY4vweG+Zg71HuiZLSJBVMNjK73N/w3Ie+sU8L8VS++W7L9Rel5aqAaCJpr18jvIYNjTdiQ== X-Received: by 2002:a62:e00a:: with SMTP id f10-v6mr8177546pfh.208.1531504568605; Fri, 13 Jul 2018 10:56:08 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:25:02 +0530 Message-Id: <1531504509-7930-25-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.42]); Fri, 13 Jul 2018 17:56:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 13 Jul 2018 17:56:09 +0000 (UTC) for IP:'209.85.192.179' DOMAIN:'mail-pf0-f179.google.com' HELO:'mail-pf0-f179.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.179 mail-pf0-f179.google.com 209.85.192.179 mail-pf0-f179.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.42 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 24/31] util: bitmap: 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.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 13 Jul 2018 17:57:19 +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/virbitmap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index ef18dad..5b6e55f 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -1202,15 +1202,12 @@ char * virBitmapDataFormat(const void *data, int len) { - virBitmapPtr map =3D NULL; - char *ret =3D NULL; + VIR_AUTOPTR(virBitmap) map =3D NULL; =20 if (!(map =3D virBitmapNewData(data, len))) return NULL; =20 - ret =3D virBitmapFormat(map); - virBitmapFree(map); - return ret; + return virBitmapFormat(map); } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504633975162.2614623668677; Fri, 13 Jul 2018 10:57:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 54321307C70E; Fri, 13 Jul 2018 17:57:09 +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 202913001B84; Fri, 13 Jul 2018 17:57:09 +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 B190F1800B84; Fri, 13 Jul 2018 17:57:08 +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 w6DHuMxW008956 for ; Fri, 13 Jul 2018 13:56:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1B0E95C545; Fri, 13 Jul 2018 17:56:22 +0000 (UTC) Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.43]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0CFF05C72C for ; Fri, 13 Jul 2018 17:56:21 +0000 (UTC) Received: from mail-pf0-f194.google.com (mail-pf0-f194.google.com [209.85.192.194]) (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 1F5A230E4E82 for ; Fri, 13 Jul 2018 17:56:11 +0000 (UTC) Received: by mail-pf0-f194.google.com with SMTP id l123-v6so23031115pfl.13 for ; Fri, 13 Jul 2018 10:56:11 -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.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:56:09 -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=NLdXWdon241mh1bL8DmW93pgy/o9jsEHW7trYZmr6dg=; b=OB7aYIS6mGazsVrocnPrHeNBSIxtbd1eMM2eiz86eyL5lwVyg5l/8okW4T/FZ0Wq9L JSUSzhlPjXdzL6nGtXf01k2exyu2aCTq+ba5t2juiOGV3L2omPml9CNyqi29Zv6tXvfh oWFHAsSPBLlABHnjJQP07lhKJcQI3EmjvZv4Yoz6WpHaQ224b+hlhnTYYrmc+/9Po3PG HNdWzv7XUWlM4bgdSV2SqmR8Q5pN2Hhoc+6IiFObowwTTw7kJHQVKuDEnrkcKJsR9uXK jczg+lPg3AC9p3GfTelqatM46ZR5Xj1vJXIULCPF+bvlFPuDPG3oI+AOMbAl/tWNqiNI 0RNA== 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=NLdXWdon241mh1bL8DmW93pgy/o9jsEHW7trYZmr6dg=; b=ONBz57ZAYZymqzO5L4EqOMz0X58Z16/qB2uUuSYWco/hJegpnGrUSaLcQwj2Pgwk+s swp/AKphuZmXEO/Lbx1gRWPKeZqgJDGx7m5Sb4YQ997bSCT128CIF6gc45i1uep344DH rL/b5d7NAzqxDq0sMd8xC3q3cL4ARLsTtScN9nqqNRuVoc2THrfcNV02vETurSzkyRpy tGf7NboJqcpRt4X10E68w0g6dARgqEMKASCXNx6RUnVn6nIiKAmYI9yyfUGPRWuCV6ct cz4YevR6dYLbXhebqctGBN3w2txUQEtZyVtVyJCHkk2k6ZY6m6aroez2U1fJPWtcyEmD MQ+A== X-Gm-Message-State: AOUpUlE0LEGgKZiOVdlquBt98BM3SamG3nKkMkq+PnUl+7yBZMS1LGHV 4wJtwP1k/AE3NZvzeU+b7Bf0QXfF X-Google-Smtp-Source: AAOMgpesRa/uZMnIArX6Vi0bv1t8JMFdDQ46KbGqCxiApk6in74c4OUnL/VQx+3KzyhyTO93197D8g== X-Received: by 2002:a63:dd09:: with SMTP id t9-v6mr7013225pgg.370.1531504570349; Fri, 13 Jul 2018 10:56:10 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:25:03 +0530 Message-Id: <1531504509-7930-26-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.43]); Fri, 13 Jul 2018 17:56:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 13 Jul 2018 17:56:11 +0000 (UTC) for IP:'209.85.192.194' DOMAIN:'mail-pf0-f194.google.com' HELO:'mail-pf0-f194.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.192.194 mail-pf0-f194.google.com 209.85.192.194 mail-pf0-f194.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.43 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 25/31] util: iohelper: 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.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 13 Jul 2018 17:57:13 +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 Reviewed-by: Erik Skultety --- src/util/iohelper.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/util/iohelper.c b/src/util/iohelper.c index bb8a8dd..f7794dc 100644 --- a/src/util/iohelper.c +++ b/src/util/iohelper.c @@ -46,7 +46,7 @@ static int runIO(const char *path, int fd, int oflags) { - void *base =3D NULL; /* Location to be freed */ + VIR_AUTOFREE(void *) base =3D NULL; /* Location to be freed */ char *buf =3D NULL; /* Aligned location within base */ size_t buflen =3D 1024*1024; intptr_t alignMask =3D 64*1024 - 1; @@ -174,8 +174,6 @@ runIO(const char *path, int fd, int oflags) virReportSystemError(errno, _("Unable to close %s"), path); ret =3D -1; } - - VIR_FREE(base); return ret; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504609131863.4504216813884; Fri, 13 Jul 2018 10:56:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 967D581E00; Fri, 13 Jul 2018 17:56:47 +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 5445B5D962; Fri, 13 Jul 2018 17:56:47 +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 ACCEF1800B77; Fri, 13 Jul 2018 17:56:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHuRiI009000 for ; Fri, 13 Jul 2018 13:56:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id AC41F10694FC; Fri, 13 Jul 2018 17:56:27 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A0E6F1073031 for ; Fri, 13 Jul 2018 17:56:23 +0000 (UTC) Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (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 DA0E381DE2 for ; Fri, 13 Jul 2018 17:56:12 +0000 (UTC) Received: by mail-pg1-f175.google.com with SMTP id k3-v6so5223604pgq.5 for ; Fri, 13 Jul 2018 10:56:12 -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.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:56:11 -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=JdTsPh6RHYz8gUdMpv3iYgvSb76GIcoGHrSThPKdWmo=; b=fz3+IkA62ppH865VbkxEum1fRDvQ+nOt3iniYw5pYdOimj0EUp5DmIUxQHYCSwskRY JGlNFdsaCgFban2aIh0E8OnU0FEaNDUzTTij5fKPfuPyjJoSH8HwsgtxnIBd7rn2gfhS PKfefuRcclMEC9Gy0km9c2drEJV06BPQ5093uYPfQyOdzstMsBTAYMmL2S0SQIPW6vtd +uScuQl6C7zfkv+ZuZlYyWAM2kxi9j/pNwNcLt1Y2wcNpE+/1hEDPb4ziTD0eI0ORpVf d24wVYQ3EmaY0ZuaqcV00gSUswzJr2hIyfxhF9R5KCQ5p1ojQc8+XYs9HXia3T36yElL n5vg== 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=JdTsPh6RHYz8gUdMpv3iYgvSb76GIcoGHrSThPKdWmo=; b=oGAW31d7QebiMoxUG5gkgCaTMNCIkkqEAizZVoU4o4N8RIbyPxhGAllKIHMiPkyhnt 0e0QOFLha6lb9KXZKn2cn3mH1L1T8QIi1BhiBdGpK8OvbKY2fes45rtevmmHS/j4EJuO J5Lz+0eFI6uZvQPa2Iq0cbTTkTLx90A945v9FlR9NoSok41/UhH/TkELr56JYOJfJNuj VzxfT32RGvvfY0/8sBhNMwe/HrZhIx4nA5tHxwprPEy4ycKaHlc1tFLYV0Z11exYq5W1 WR4SKhm/UsNsMLGWlErTZa9OcHnx4B6Q+4YBmNuyea73ZsPgpWeurebDr3H6cFF6B0Lw /MBw== X-Gm-Message-State: AOUpUlFtDkbgsadIV1KYQ8MQx1c9iaS5qv9AlTQ3HUzrKGwhUM/rYrgA D21Ccd8K4VLIzT8nuzWrgt059qI7 X-Google-Smtp-Source: AAOMgpeGd76lvIZ1EXP7mTY1D5Ij1PHyddB4VAySJ6AslDkbPnDGc9jOWnvsoV8/2a+x0nH5hVW8HQ== X-Received: by 2002:a63:7d7:: with SMTP id 206-v6mr6957875pgh.137.1531504572155; Fri, 13 Jul 2018 10:56:12 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:25:04 +0530 Message-Id: <1531504509-7930-27-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.25]); Fri, 13 Jul 2018 17:56:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 13 Jul 2018 17:56:12 +0000 (UTC) for IP:'209.85.215.175' DOMAIN:'mail-pg1-f175.google.com' HELO:'mail-pg1-f175.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.215.175 mail-pg1-f175.google.com 209.85.215.175 mail-pg1-f175.google.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 26/31] util: arptable: 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 13 Jul 2018 17:56:48 +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 Reviewed-by: Erik Skultety --- src/util/virarptable.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/util/virarptable.c b/src/util/virarptable.c index c0e90dc..04a6f35 100644 --- a/src/util/virarptable.c +++ b/src/util/virarptable.c @@ -71,9 +71,8 @@ virArpTableGet(void) { int num =3D 0; int msglen; - void *nlData =3D NULL; + VIR_AUTOFREE(void *) nlData =3D NULL; virArpTablePtr table =3D NULL; - char *ipstr =3D NULL; struct nlmsghdr* nh; struct rtattr * tb[NDA_MAX+1]; =20 @@ -108,7 +107,7 @@ virArpTableGet(void) continue; =20 if (nh->nlmsg_type =3D=3D NLMSG_DONE) - goto end_of_netlink_messages; + return table; =20 VIR_WARNINGS_NO_CAST_ALIGN parse_rtattr(tb, NDA_MAX, NDA_RTA(r), @@ -119,6 +118,7 @@ virArpTableGet(void) continue; =20 if (tb[NDA_DST]) { + VIR_AUTOFREE(char *) ipstr =3D NULL; virSocketAddr virAddr; if (VIR_REALLOC_N(table->t, num + 1) < 0) goto cleanup; @@ -134,8 +134,6 @@ virArpTableGet(void) =20 if (VIR_STRDUP(table->t[num].ipaddr, ipstr) < 0) goto cleanup; - - VIR_FREE(ipstr); } =20 if (tb[NDA_LLADDR]) { @@ -154,14 +152,8 @@ virArpTableGet(void) } } =20 - end_of_netlink_messages: - VIR_FREE(nlData); - return table; - cleanup: virArpTableFree(table); - VIR_FREE(ipstr); - VIR_FREE(nlData); return NULL; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504605161527.5213341138887; Fri, 13 Jul 2018 10:56:45 -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 EA106308404F; Fri, 13 Jul 2018 17:56:41 +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 A46C92010CF4; Fri, 13 Jul 2018 17:56:41 +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 4548E1800B73; Fri, 13 Jul 2018 17:56:41 +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 w6DHuPhh008980 for ; Fri, 13 Jul 2018 13:56:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id AD34B2010D5D; Fri, 13 Jul 2018 17:56:25 +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 A322A2010D5C for ; Fri, 13 Jul 2018 17:56:25 +0000 (UTC) Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 E57453082154 for ; Fri, 13 Jul 2018 17:56:14 +0000 (UTC) Received: by mail-pg1-f169.google.com with SMTP id e6-v6so5227131pgv.2 for ; Fri, 13 Jul 2018 10:56:14 -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.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:56:13 -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=fb0KVdu+Dnddp0jKiAU1W9VNqBcz/ZrcUPCYA0aDbHM=; b=OBhLfiWp0g3WgZNdxrCuuVrwm1rhX4aW5Z5BAIQvXgP2vu6UzYvAXcKU61OqbgpvEN Wvm7qmivbESwTKOrdP+tBLPIXV84YwtQXNzwBemgld5lMZtymiV5x0ggXCOmibKZ2hlX 6zsNI1e6vN87rShDDyeZHY3ODKNmhS3bVareFOsTAVRBuXI5dg/7CwAR2OBzHDKntVvB DCBinsbP/KkpLAGIo/4yyWN+6khZyMYcJeH7rni4v6tdLuFxu59wT8QSzGxZupCDwqLN mN30LWi3jO41bCGy1D0FKjEJRpXuLLlSTdGhzumIu7O2X2Xk+XKhce0kCvd4IbMW56Jw HxgQ== 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=fb0KVdu+Dnddp0jKiAU1W9VNqBcz/ZrcUPCYA0aDbHM=; b=CggEjoSEECmP/e27hFOpv0S9InsvL7tw+zmfmbuqsHyRFKUu+mVIJvzFSMUhrANhf7 iwfFLXdKzmE9SjdVOf5EsLXwAFeoq0fcIppvpLRWP6OuZRpu/vh/JY9e6uSVs8HQOF91 3eMpOyW/wVR/20o5TyOeHXe7Sux2CezdCTgOoceRhfY9GsrTnJW/rPlo1E6ImM0WiYRq uNajKbJjVWMBLnyBNfdY6rz5Fw7YnYeXzFL13Fj9PovbL5FgHpDH58u8Vk55iXsQ4SGY 9XlAqSCO8RDuPKZg2eV5iUDFA0ZeurrHNRpqlb+PNbwpPHKIU1T5kchcNTddq5WVsYbO Ei4g== X-Gm-Message-State: AOUpUlE4sJ2dHtV2RXoZBl4CBt56Ezv4Qql1cJHt5ET0g8QViKsDXc6L elP9ELublpMdfiWAygBMCOgtt9gF X-Google-Smtp-Source: AAOMgpcESssY5PDu3rsz93F8Za7C1DznDRNqQuMrBgshOKU8dfkNHhiFuWHpQ2KF5og9rmJ00a4pvQ== X-Received: by 2002:a63:1315:: with SMTP id i21-v6mr7036465pgl.147.1531504574100; Fri, 13 Jul 2018 10:56:14 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:25:05 +0530 Message-Id: <1531504509-7930-28-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.42]); Fri, 13 Jul 2018 17:56:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 13 Jul 2018 17:56:15 +0000 (UTC) for IP:'209.85.215.169' DOMAIN:'mail-pg1-f169.google.com' HELO:'mail-pg1-f169.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.215.169 mail-pg1-f169.google.com 209.85.215.169 mail-pg1-f169.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.42 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 27/31] util: audit: 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.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 13 Jul 2018 17:56:44 +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 Reviewed-by: Erik Skultety --- src/util/viraudit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/util/viraudit.c b/src/util/viraudit.c index 0085dc3..a49d458 100644 --- a/src/util/viraudit.c +++ b/src/util/viraudit.c @@ -97,7 +97,7 @@ void virAuditSend(virLogSourcePtr source, virAuditRecordType type ATTRIBUTE_UNUSED, bool success, const char *fmt, ...) { - char *str =3D NULL; + VIR_AUTOFREE(char *) str =3D NULL; va_list args; =20 /* Duplicate later checks, to short circuit & avoid printf overhead @@ -144,7 +144,6 @@ void virAuditSend(virLogSourcePtr source, } } #endif - VIR_FREE(str); } =20 void virAuditClose(void) --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504617053891.1880061102836; Fri, 13 Jul 2018 10:56:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B331230820E3; Fri, 13 Jul 2018 17:56:53 +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 5897F1073033; Fri, 13 Jul 2018 17:56:53 +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 F0F0924F12; Fri, 13 Jul 2018 17:56:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHuUkd009027 for ; Fri, 13 Jul 2018 13:56:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 27D8E17BBF; Fri, 13 Jul 2018 17:56:30 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1BD0160BE5 for ; Fri, 13 Jul 2018 17:56:27 +0000 (UTC) Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 C3DF63E2D4 for ; Fri, 13 Jul 2018 17:56:16 +0000 (UTC) Received: by mail-pg1-f169.google.com with SMTP id r5-v6so5184275pgv.0 for ; Fri, 13 Jul 2018 10:56:16 -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.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:56:15 -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=eE5kj7rTY+m161eHKV29sBCOk+vyqMwzi44Xgyx9u6M=; b=nHsf9+7H1/upeoHuNIsvH2yARpUXw+lBdtxO47mQeKWvaffAbNRYXACVHZzZjD8CdS 44OuQ52O/YcS17yTSzDSTptKxQQ8zaMA4H3VSTKmvDJK2u66aAZO2H9dSDCFrcfCS7GX //5SBmfYqefYlh6In0WAH3ZUNujNCGNlFYEcZQeC0Br/X6DANsIoHbxi47YrTPyKNYvr sndttu9Eklx5fQPOX4E68RzlEWnYz/AC+UHd95pS0Nb7OTWyHwTXLv6xUIEXfqUWX0LX RcNYPJMsirn70kHSOBkCh3G+qgn8j206R6l0LMrhfMHsJXuMbr9UZIXFkAWpiTxqAs8a TbNQ== 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=eE5kj7rTY+m161eHKV29sBCOk+vyqMwzi44Xgyx9u6M=; b=oLgRplsLojgY7otLFsp34Ris2eZx6p8VflvOxKu7a+Pq2pdQcrfHxf2ItXKmFuBrxi FgxSJCUrH1vlhdcLRfHcEbSKbOzBI/4eynLgiDXxoSydK4MZozWbnYY6GK490U2WS2sm cpWMJbRiF+jxaJNMqkjorBXRxOyu/amgxKl7uLNnsiLmWyGXrspj6AuoiCyH3slaO13j U1Ej6yatJqYDkBFozkABP2ohSNaYmeyvf4pa5cwV7BAfb6YO8IDABqqz8FYTVD1zZcF5 bVFvzzXnyh1JR/OvU6sFK+kMHA0eeJGqKIQ54pEZRroIN3h73Fglb3IkUpy4RDAoq1ZT /O9w== X-Gm-Message-State: AOUpUlGL78s/PPr3rIXDswzYmW6gq+8/WE3Wn4ysAvR8wxXg+mW6hOAm 1Z9kzsAW/n5OVI49SpcTCOgauJvV X-Google-Smtp-Source: AAOMgpdknCnfFZS5N9CL99kPLTXcg1C/NY2YRndbEbybqOfImWIqTmMpvMepUHp9yJQeeTrIYZwYFg== X-Received: by 2002:a63:5025:: with SMTP id e37-v6mr7065824pgb.341.1531504576067; Fri, 13 Jul 2018 10:56:16 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:25:06 +0530 Message-Id: <1531504509-7930-29-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.30]); Fri, 13 Jul 2018 17:56:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 13 Jul 2018 17:56:16 +0000 (UTC) for IP:'209.85.215.169' DOMAIN:'mail-pg1-f169.google.com' HELO:'mail-pg1-f169.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.215.169 mail-pg1-f169.google.com 209.85.215.169 mail-pg1-f169.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 28/31] util: fcp: 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 13 Jul 2018 17:56:56 +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 Reviewed-by: Erik Skultety --- src/util/virfcp.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/util/virfcp.c b/src/util/virfcp.c index 7660ba7..b703744 100644 --- a/src/util/virfcp.c +++ b/src/util/virfcp.c @@ -40,16 +40,12 @@ bool virFCIsCapableRport(const char *rport) { - bool ret =3D false; - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (virBuildPath(&path, SYSFS_FC_RPORT_PATH, rport) < 0) return false; =20 - ret =3D virFileExists(path); - VIR_FREE(path); - - return ret; + return virFileExists(path); } =20 int @@ -57,8 +53,8 @@ virFCReadRportValue(const char *rport, const char *entry, char **result) { - int ret =3D -1; - char *buf =3D NULL, *p =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; + char *p =3D NULL; =20 if (virFileReadValueString(&buf, "%s/%s/%s", SYSFS_FC_RPORT_PATH, rport, entry) < 0) { @@ -69,13 +65,9 @@ virFCReadRportValue(const char *rport, *p =3D '\0'; =20 if (VIR_STRDUP(*result, buf) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - VIR_FREE(buf); - return ret; + return 0; } =20 #else --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504609530925.3137317511427; Fri, 13 Jul 2018 10:56:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2E3BD3E2D4; Fri, 13 Jul 2018 17:56:48 +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 CAE3A5C72C; Fri, 13 Jul 2018 17:56:47 +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 655C824F56; Fri, 13 Jul 2018 17:56:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DHucB0009097 for ; Fri, 13 Jul 2018 13:56:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5BEE73083326; Fri, 13 Jul 2018 17:56:38 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 52A303001A5C for ; Fri, 13 Jul 2018 17:56:29 +0000 (UTC) Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 07CAF307CF23 for ; Fri, 13 Jul 2018 17:56:19 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id g2-v6so385431pgs.6 for ; Fri, 13 Jul 2018 10:56:19 -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.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:56:17 -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=wiKA+BFxfDqLyda7Nx4X2HzAk0MoSA85laoZC1/b9k0=; b=UfIElVOO+xJ/3vxQhWBZ2BI1o9IMfbP9ZY+ziihBmbQ5ALTw/+n7w9Tv/52ftJGOJ4 zE9+063reZurZyjXMul6Aj6y8psu8qFxBYaLz2dj8GCQaES3cnMnUAo9LkwDAeTDwzuN d8wTVHiGyUQZt/PXagWcys2JqDiz9Y1JQfmOoz+qYF9yfcTN4sUFxJkdUttpxo5seRxM FbRTb60ELRdiPUwWqxkozuLs2s4C0KfYJrwAH5uCPJD0GE+ClYgJ9yRvbo7okuC0E6+C jwStnxZJWzp1aXYnT2SoD/TkokXkO2xDQG6YQK+68NRZSRXrHl8A7jE1aJeS5WTk3kit XG4Q== 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=wiKA+BFxfDqLyda7Nx4X2HzAk0MoSA85laoZC1/b9k0=; b=Uin25ASPGxF6cF59EM2RPLMERXWy+4qOZAQnAVa24tq/Ii2KXNj2APHV52AOluyNuG WRpatB5AvCW0PLPOecTMWmwIFFfsupjsqHyfsKaAHHFJTSmJFmDZr7klr36GJds2OMGP ETAD7DQg+8vcgE6DemxO+Gf6hlBaDSt3F1IVi9DwNjnFpBntEJRHbe8astCRCfcB+cNS EaBfjGphsd4GybpgOIORosM0co3LO6+8++bZX49lq+skO780VqNUTIGFfEXnq8rjytkc OcN6IjQVmQzK60YE4UQTkHPtwtyi0DIvJgfnar3v+f+PPGp8JChQenjHCW3rUfqDuPQW 9GeA== X-Gm-Message-State: AOUpUlFbyap+YecciQ+OL8JpUQePcvae5ngS+P7PNM6gC3WQZaxBRADe DubiI6/unEZw4gk10eFWPanGKtOP X-Google-Smtp-Source: AAOMgpfF55WEZWEzpdS5jJwiNtzsTcnV2W/8QxnaNRZG5gj30MxutO+EDg/Lr6YQjTmsPO5z8xfH6Q== X-Received: by 2002:a63:e914:: with SMTP id i20-v6mr7000094pgh.10.1531504578303; Fri, 13 Jul 2018 10:56:18 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:25:07 +0530 Message-Id: <1531504509-7930-30-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.44]); Fri, 13 Jul 2018 17:56:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 13 Jul 2018 17:56:19 +0000 (UTC) for IP:'209.85.215.170' DOMAIN:'mail-pg1-f170.google.com' HELO:'mail-pg1-f170.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.215.170 mail-pg1-f170.google.com 209.85.215.170 mail-pg1-f170.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 29/31] util: eventpoll: 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 13 Jul 2018 17:56:48 +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 Reviewed-by: Erik Skultety --- src/util/vireventpoll.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/util/vireventpoll.c b/src/util/vireventpoll.c index 81ecab4..13d278d 100644 --- a/src/util/vireventpoll.c +++ b/src/util/vireventpoll.c @@ -618,7 +618,7 @@ static void virEventPollCleanupHandles(void) */ int virEventPollRunOnce(void) { - struct pollfd *fds =3D NULL; + VIR_AUTOFREE(struct pollfd *) fds =3D NULL; int ret, timeout, nfds; =20 virMutexLock(&eventLoop.lock); @@ -645,7 +645,7 @@ int virEventPollRunOnce(void) goto retry; virReportSystemError(errno, "%s", _("Unable to poll on file handles")); - goto error_unlocked; + return -1; } EVENT_DEBUG("Poll got %d event(s)", ret); =20 @@ -662,13 +662,10 @@ int virEventPollRunOnce(void) =20 eventLoop.running =3D 0; virMutexUnlock(&eventLoop.lock); - VIR_FREE(fds); return 0; =20 error: virMutexUnlock(&eventLoop.lock); - error_unlocked: - VIR_FREE(fds); return -1; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504596183617.0560443527153; Fri, 13 Jul 2018 10:56:36 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 10EEB804E5; Fri, 13 Jul 2018 17:56:34 +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 AA9BEC6A35; Fri, 13 Jul 2018 17:56: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 3904E1800B6D; Fri, 13 Jul 2018 17:56:33 +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 w6DHuWtk009044 for ; Fri, 13 Jul 2018 13:56:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id F37852010D5C; Fri, 13 Jul 2018 17:56:31 +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 EA4EE2010D5B for ; Fri, 13 Jul 2018 17:56:31 +0000 (UTC) Received: from mail-pf0-f193.google.com (mail-pf0-f193.google.com [209.85.192.193]) (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 D341D859FF for ; Fri, 13 Jul 2018 17:56:20 +0000 (UTC) Received: by mail-pf0-f193.google.com with SMTP id s21-v6so23065966pfm.6 for ; Fri, 13 Jul 2018 10:56:20 -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.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:56:19 -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=lHbvp/ZiQyuZnIt0imUW6X8BQrcSvQ7Kkga3zR5TcTI=; b=c0XdPrFS4oFqOXD6OGPQw4QbSg4wjbJq7/rIxFoJzfIEWOV/m0o00bUHtmf0N5K7f8 kX4dfHiyXCovuucYpyGdpFBu3OuVgoyRoDL/LPoKPY2QHEsBnoPLlnf7VbUtPlIClwEl wRumvLgbLq8yvSdh+vogaPetgjzf6eyMS509UFoKYeyyHC4/g8eJiCFpXsT0N97QtUeD TSYyjkYcAAo4pUmEJXLphcNxbxCzceTo6g337yEa2g2/DTGOn/t26bRXH4+dL05xqK6N 8YuJ5dR0topYkMvMr7io0x0+Mp7fgfozKOI+J6ARBuATDmy63LvY/eCmcmcb309epQ1i yNuQ== 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=lHbvp/ZiQyuZnIt0imUW6X8BQrcSvQ7Kkga3zR5TcTI=; b=XgLbWyByzEZTdTXQxx7EaCEhGNqE3LOZzHrIz8CQtG09CGd0FQEjTeb4DRohKrMxgU huGh0mZe7ft9VHqUUUU+ZsZKdyLBwsqM7EzmFoh6sGjJo6Z3TV3qkFUxzijwGe02Ym35 dtDodu9cwjfGIGEsQgYYDJYDfnfWVK5K2xFf4iv9eRybHyiTwmADaBmZyrrEueOxURiw dF+Va7Av+XyHGRSaMHC6IXiBtrpDhV9JKXVnRv2+OD0rhuqJ/9GshJ9neiG5q0NATByT PVHDeCGmP9KnRuJt4K+ZEdLvwfWDT8mo4ql7qO+i7NJ4wj+7gOvK6jyVOY1/OhMcBWmX CSLQ== X-Gm-Message-State: AOUpUlFhBGkH5ipolUZnXoPr69ZaAd7LXB3yfVOK6hpXCh1YubbWNZC2 CU/RvUCdvqhr/lo3JS7Vm3X+/oal X-Google-Smtp-Source: AAOMgpdIAs+GJo1oyFsZhCM2VZuZUU91WlxMIAwcyO7R3kKMbhLFvTv4KBUwU++9xA1Kozak3eWSvA== X-Received: by 2002:a65:520d:: with SMTP id o13-v6mr6923200pgp.282.1531504580096; Fri, 13 Jul 2018 10:56:20 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:25:08 +0530 Message-Id: <1531504509-7930-31-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:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 13 Jul 2018 17:56:20 +0000 (UTC) for IP:'209.85.192.193' DOMAIN:'mail-pf0-f193.google.com' HELO:'mail-pf0-f193.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.192.193 mail-pf0-f193.google.com 209.85.192.193 mail-pf0-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 30/31] util: filecache: 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 13 Jul 2018 17:56:35 +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 Reviewed-by: Erik Skultety --- src/util/virfilecache.c | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/src/util/virfilecache.c b/src/util/virfilecache.c index 96ae96d..2927c68 100644 --- a/src/util/virfilecache.c +++ b/src/util/virfilecache.c @@ -100,18 +100,17 @@ static char * virFileCacheGetFileName(virFileCachePtr cache, const char *name) { - char *file =3D NULL; - char *namehash =3D NULL; + VIR_AUTOFREE(char *) namehash =3D NULL; virBuffer buf =3D VIR_BUFFER_INITIALIZER; =20 if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, name, &namehash) < 0) - goto cleanup; + return NULL; =20 if (virFileMakePath(cache->dir) < 0) { virReportSystemError(errno, _("Unable to create directory '%s'"), cache->dir); - goto cleanup; + return NULL; } =20 virBufferAsprintf(&buf, "%s/%s", cache->dir, namehash); @@ -120,13 +119,9 @@ virFileCacheGetFileName(virFileCachePtr cache, virBufferAsprintf(&buf, ".%s", cache->suffix); =20 if (virBufferCheckError(&buf) < 0) - goto cleanup; + return NULL; =20 - file =3D virBufferContentAndReset(&buf); - - cleanup: - VIR_FREE(namehash); - return file; + return virBufferContentAndReset(&buf); } =20 =20 @@ -135,7 +130,7 @@ virFileCacheLoad(virFileCachePtr cache, const char *name, void **data) { - char *file =3D NULL; + VIR_AUTOFREE(char *) file =3D NULL; int ret =3D -1; void *loadData =3D NULL; =20 @@ -178,7 +173,6 @@ virFileCacheLoad(virFileCachePtr cache, =20 cleanup: virObjectUnref(loadData); - VIR_FREE(file); return ret; } =20 @@ -188,20 +182,15 @@ virFileCacheSave(virFileCachePtr cache, const char *name, void *data) { - char *file =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) file =3D NULL; =20 if (!(file =3D virFileCacheGetFileName(cache, name))) - return ret; + return -1; =20 if (cache->handlers.saveFile(data, file, cache->priv) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - VIR_FREE(file); - return ret; + return 0; } =20 =20 @@ -346,7 +335,7 @@ virFileCacheLookupByFunc(virFileCachePtr cache, const void *iterData) { void *data =3D NULL; - char *name =3D NULL; + VIR_AUTOFREE(char *) name =3D NULL; =20 virObjectLock(cache); =20 @@ -356,8 +345,6 @@ virFileCacheLookupByFunc(virFileCachePtr cache, virObjectRef(data); virObjectUnlock(cache); =20 - VIR_FREE(name); - return data; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon May 13 08:39:18 2024 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 1531504603354967.0768353607257; Fri, 13 Jul 2018 10:56:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D5EA0C057FA2; Fri, 13 Jul 2018 17:56:41 +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 961CBC6A3D; Fri, 13 Jul 2018 17:56:41 +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 1D36D24F58; Fri, 13 Jul 2018 17:56:41 +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 w6DHuY15009060 for ; Fri, 13 Jul 2018 13:56:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 145D716C1E; Fri, 13 Jul 2018 17:56:34 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0B95226DC8 for ; Fri, 13 Jul 2018 17:56:34 +0000 (UTC) Received: from mail-pl0-f47.google.com (mail-pl0-f47.google.com [209.85.160.47]) (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 D158331500A9 for ; Fri, 13 Jul 2018 17:56:22 +0000 (UTC) Received: by mail-pl0-f47.google.com with SMTP id a7-v6so12505494plp.3 for ; Fri, 13 Jul 2018 10:56:22 -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.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 10:56:21 -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=8Ev1mxJ5FdRed49kDgDws+DUrdJvdV8vCWB00JFA8u8=; b=seCAOQ1Z0zqp0mQSjt7dqVRVxgOWc6c7MRZQsdA6zZCL+Z1Rx3MaIY1V/vewvpm5dS WcQxcBAGB61wzkCfIl97pcyo0Bhy+mPnvg8aG+h5ohs5t9cJDtq9lQMjEUY7P/mEIL1K 12K2jcn1Da29J4YAYakeFxsrM2uEGH3vX+56vUeFLP21QGu7KJoh+WIqwN1fQdt0Y3uo vLe9e7PubE7t1a8HnSMnLe9qrNQ2XKbDAKjXc/pZ3iqjzILwHRRYtl+9ClsB13Zh6aPN grmx5Nhyd9rcoyC+nRustLMDssIEg+VibpsWxbVzzxOeXUvaiZwazZet8HLWLcbBErVw bz0w== 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=8Ev1mxJ5FdRed49kDgDws+DUrdJvdV8vCWB00JFA8u8=; b=uYqB5ABhcozgh6cjQfBieMROHnGUBzsMaIGnO6i5ue7BNJrA6B4VE+aWslfnj235Tu TCyiTyN91SmNR5w5L4EwsQIbWahEEIF+At3pP3DOw2R0o2ZNqMnO2qDEhwRaG//0lH+2 lusqeoFjI8aiJMlSPCRiK8WFIsnsEDyDxejQ1E+hgGhFMPpyZMLAfbhvYa62EtLdU8lL m4rmUn8HhEYJKXz5GMcHFE7ClnkazkZXUTrd9oybwFRcNy6fh4T5viRnxj4HVtwDC3Gu 4cHeCSfHuZlON8XFLJXtF3g1LunEOKba2KrMZGrFMgN1ZTOTzEGvM4g0TVKyqGIqvtkx wnNg== X-Gm-Message-State: AOUpUlFjO9c2aHEtz/wjU+/bush4LNK+EMSHgF1Kgq1seI2dmY9ZBMG2 X2E5iX4dx8z4XdWW3egOZWTFVEfM X-Google-Smtp-Source: AAOMgpc4XvUi2krl5bRmTUip9XAW58c9K/gtGPedB8kHdG/u4Rx5PTsoaRxDkCSbMpGsoPRJ1tNcnA== X-Received: by 2002:a17:902:8306:: with SMTP id bd6-v6mr7422809plb.120.1531504581940; Fri, 13 Jul 2018 10:56:21 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 23:25:09 +0530 Message-Id: <1531504509-7930-32-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.41]); Fri, 13 Jul 2018 17:56:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 13 Jul 2018 17:56:23 +0000 (UTC) for IP:'209.85.160.47' DOMAIN:'mail-pl0-f47.google.com' HELO:'mail-pl0-f47.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.160.47 mail-pl0-f47.google.com 209.85.160.47 mail-pl0-f47.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 31/31] util: identity: 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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 13 Jul 2018 17:56:42 +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 Reviewed-by: Erik Skultety --- src/util/viridentity.c | 52 +++++++++++++++++++++-------------------------= ---- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/src/util/viridentity.c b/src/util/viridentity.c index 2f4307b..c621444 100644 --- a/src/util/viridentity.c +++ b/src/util/viridentity.c @@ -133,8 +133,8 @@ int virIdentitySetCurrent(virIdentityPtr ident) */ virIdentityPtr virIdentityGetSystem(void) { - char *username =3D NULL; - char *groupname =3D NULL; + VIR_AUTOFREE(char *) username =3D NULL; + VIR_AUTOFREE(char *) groupname =3D NULL; unsigned long long startTime; virIdentityPtr ret =3D NULL; #if WITH_SELINUX @@ -154,14 +154,14 @@ virIdentityPtr virIdentityGetSystem(void) goto error; =20 if (!(username =3D virGetUserName(geteuid()))) - goto cleanup; + return ret; if (virIdentitySetUNIXUserName(ret, username) < 0) goto error; if (virIdentitySetUNIXUserID(ret, getuid()) < 0) goto error; =20 if (!(groupname =3D virGetGroupName(getegid()))) - goto cleanup; + return ret; if (virIdentitySetUNIXGroupName(ret, groupname) < 0) goto error; if (virIdentitySetUNIXGroupID(ret, getgid()) < 0) @@ -172,7 +172,7 @@ virIdentityPtr virIdentityGetSystem(void) if (getcon(&con) < 0) { virReportSystemError(errno, "%s", _("Unable to lookup SELinux process conte= xt")); - goto cleanup; + return ret; } if (virIdentitySetSELinuxContext(ret, con) < 0) { freecon(con); @@ -182,15 +182,11 @@ virIdentityPtr virIdentityGetSystem(void) } #endif =20 - cleanup: - VIR_FREE(username); - VIR_FREE(groupname); return ret; =20 error: virObjectUnref(ret); - ret =3D NULL; - goto cleanup; + return NULL; } =20 =20 @@ -461,15 +457,14 @@ int virIdentitySetUNIXUserName(virIdentityPtr ident, int virIdentitySetUNIXUserID(virIdentityPtr ident, uid_t uid) { - char *val; - int ret; + VIR_AUTOFREE(char *) val =3D NULL; + if (virAsprintf(&val, "%d", (int)uid) < 0) return -1; - ret =3D virIdentitySetAttr(ident, + + return virIdentitySetAttr(ident, VIR_IDENTITY_ATTR_UNIX_USER_ID, val); - VIR_FREE(val); - return ret; } =20 =20 @@ -485,45 +480,42 @@ int virIdentitySetUNIXGroupName(virIdentityPtr ident, int virIdentitySetUNIXGroupID(virIdentityPtr ident, gid_t gid) { - char *val; - int ret; + VIR_AUTOFREE(char *) val =3D NULL; + if (virAsprintf(&val, "%d", (int)gid) < 0) return -1; - ret =3D virIdentitySetAttr(ident, + + return virIdentitySetAttr(ident, VIR_IDENTITY_ATTR_UNIX_GROUP_ID, val); - VIR_FREE(val); - return ret; } =20 =20 int virIdentitySetUNIXProcessID(virIdentityPtr ident, pid_t pid) { - char *val; - int ret; + VIR_AUTOFREE(char *) val =3D NULL; + if (virAsprintf(&val, "%lld", (long long) pid) < 0) return -1; - ret =3D virIdentitySetAttr(ident, + + return virIdentitySetAttr(ident, VIR_IDENTITY_ATTR_UNIX_PROCESS_ID, val); - VIR_FREE(val); - return ret; } =20 =20 int virIdentitySetUNIXProcessTime(virIdentityPtr ident, unsigned long long timestamp) { - char *val; - int ret; + VIR_AUTOFREE(char *) val =3D NULL; + if (virAsprintf(&val, "%llu", timestamp) < 0) return -1; - ret =3D virIdentitySetAttr(ident, + + return virIdentitySetAttr(ident, VIR_IDENTITY_ATTR_UNIX_PROCESS_TIME, val); - VIR_FREE(val); - return ret; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list