From nobody Sun Apr 28 22:23:08 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 1527627641538616.6091789496231; Tue, 29 May 2018 14:00:41 -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 253CDC0E724E; Tue, 29 May 2018 21:00:39 +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 DA6032010CE6; Tue, 29 May 2018 21:00:38 +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 1D7271800C9C; Tue, 29 May 2018 21:00:38 +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 w4TL0ZDq023405 for ; Tue, 29 May 2018 17:00:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id D8C39308BDA2; Tue, 29 May 2018 21:00:35 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D14FA308BDA1 for ; Tue, 29 May 2018 21:00:35 +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 A17133CBA3C for ; Tue, 29 May 2018 21:00:24 +0000 (UTC) Received: by mail-pf0-f195.google.com with SMTP id a14-v6so7868034pfi.1 for ; Tue, 29 May 2018 14:00:24 -0700 (PDT) Received: from centos.localdomain ([49.32.89.162]) by smtp.gmail.com with ESMTPSA id v6-v6sm52176763pfm.120.2018.05.29.14.00.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 May 2018 14:00:23 -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=H2fnOrC9YwXdM8JadFS3aQszpXsD4XpV+485xvaCiOw=; b=gurzvVDeCkX+u/npuXweRLfE00LgKT26nRZthmEnT/3s8Ef1GPwkaeYel0sRtcqTL1 7W0DkvnzRKrMDSaWDVe8kKQL3vu1CWD4T8FatF0O45TtNL/IDcs70D0bZE7U6675Dy+V goDLiA7o8Xo8TMWZw1KI346rT14Amm20QSrf/e9TGTv6/jPEgI/ggU8o8T6LTeZL975C Mk0OoQp6TcKHAlvWhflH87c7Mhh5HEFB8hySeniq4rn92X2mSwPOYAGirBjKIG2UsYYA cedPWpnqpEV4bnD+ZsxgkCNYWwSutqLbc4vv8UoIAu0uoPmcrhsBn6mbnbBJp1+uLGDC YBAA== 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=H2fnOrC9YwXdM8JadFS3aQszpXsD4XpV+485xvaCiOw=; b=sx71TWXsSkr/xs6r3KMOYIlaNhsy6kw5R9gEUSTx3QI5oKx9Jl+3NegTA+F0lDn3JB 2hgf13ECrgs7qedBBycGyXLLvV5BuiIMToRuEESlUooMTqNlwMGmISSRsVpg28Hf4auZ HPTmekL95H0u83imsp8A3dvcAl6cDU0N6NGUDLv82EGkVUbhD3bvQBV+Jyyot4lmQGLU 3OPHFiCT2nOpQGGZRIrSq93JQiajamdj8DFoF0UndSCjjzT6gYqho/XD7ddU5EPJlF1d EP9mt82apmeGxwkaRy0UG7qRC1OB3CB4lkqFvRwjCPa3uIHuTCL6NrQGZGQueuyXrCQV eWyQ== X-Gm-Message-State: ALKqPwcOdF5sHsiIvUf7qMyd9qTg9Sdhzk9qDXfja8zLE0NrJL5z79E1 eYPlgfd7PTG7rzes3QzSAwavbAsP X-Google-Smtp-Source: ADUXVKLQUaMd5qc/AB4LLMy2siM5zwJu02BcbyWCasddRCckI4Xk7KKgYlKUmNrb/ZEuWGyiUVb3+w== X-Received: by 2002:a63:6501:: with SMTP id z1-v6mr9096pgb.452.1527627623914; Tue, 29 May 2018 14:00:23 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Wed, 30 May 2018 02:30:04 +0530 Message-Id: <1527627607-15698-2-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1527627607-15698-1-git-send-email-skrtbhtngr@gmail.com> References: <1527627607-15698-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.29]); Tue, 29 May 2018 21:00:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 29 May 2018 21:00:24 +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: -0.396 (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.29 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC 1/4] 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.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 29 May 2018 21:00: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" New macros are added to src/util/viralloc.h which help in adding cleanup attribute to variable declarations. Signed-off-by: Sukrit Bhatnagar --- src/util/viralloc.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 69 insertions(+) diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 69d0f90..e1c31c3 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -596,4 +596,73 @@ 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) virAutoPtr##type +# define VIR_AUTOCLEAR_FUNC_NAME(type) virAutoClear##type + +/** + * VIR_DEFINE_AUTOPTR_FUNC: + * @type: type of the variables(s) to free automatically + * @func: cleanup function to be automatically called + * + * Thos macro defines a function for automatically freeing + * resources allocated to a variable of type @type. The newly + * defined function calls the corresponding pre-defined + * function @func. + */ +# define VIR_DEFINE_AUTOPTR_FUNC(type, func) \ + static inline void VIR_AUTOPTR_FUNC_NAME(type)(type *_ptr) \ + { \ + (func)(*_ptr); \ + } \ + +/** + * VIR_DEFINE_AUTOCLEAR_FUNC: + * @type: type of the variables(s) to free automatically + * @func: cleanup function to be automatically called + * + * This macro defines a function for automatically clearing + * a variable of type @type. The newly deifined function calls + * the corresponding pre-defined function @func. + */ +# define VIR_DEFINE_AUTOCLEAR_FUNC(type, func) \ + static inline void VIR_AUTOCLEAR_FUNC_NAME(type)(type *_ptr) \ + { \ + (func)(_ptr); \ + } \ + +/** + * VIR_AUTOFREE: + * @type: type of the variables(s) to free automatically + * + * Macro to automatically free the memory allocated to + * the variable(s) 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 variables(s) to free automatically + * + * Macro to automatically free the memory allocated to + * the variable(s) 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 + +/** + * VIR_AUTOCLEAR: + * @type: type of the variables(s) to free automatically + * + * Macro to automatically clear the variable(s) declared + * with it by calling the function defined by + * VIR_DEFINE_AUTOCLEAR_FUNC when the variabl* goes out + * of scope. + */ +# define VIR_AUTOCLEAR(type) \ + __attribute__((cleanup(VIR_AUTOCLEAR_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 Sun Apr 28 22:23:08 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 1527627652411911.4484053224897; Tue, 29 May 2018 14:00:52 -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 C4C9030CE670; Tue, 29 May 2018 21:00:49 +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 78771174BD; Tue, 29 May 2018 21:00:49 +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 1A6204CA84; Tue, 29 May 2018 21:00:49 +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 w4TL0cUP023416 for ; Tue, 29 May 2018 17:00:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9C95397399; Tue, 29 May 2018 21:00:38 +0000 (UTC) Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 93250977D8 for ; Tue, 29 May 2018 21:00:38 +0000 (UTC) Received: from mail-pg0-f48.google.com (mail-pg0-f48.google.com [74.125.83.48]) (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 ACEA430B9090 for ; Tue, 29 May 2018 21:00:27 +0000 (UTC) Received: by mail-pg0-f48.google.com with SMTP id z1-v6so182136pgv.12 for ; Tue, 29 May 2018 14:00:27 -0700 (PDT) Received: from centos.localdomain ([49.32.89.162]) by smtp.gmail.com with ESMTPSA id v6-v6sm52176763pfm.120.2018.05.29.14.00.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 May 2018 14:00:26 -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=fGd1VkabJB4Eq3ASDJMhI5jqRQWH42tCX8wUWPvduDg=; b=PyetUlRv5nes9kRuwRcAVbiiaKh2DSEeupjD7EP9xl69i+uPdoivj9A5tFHCeW3Uui mp9pUay+Y7MzkNqQa2/wVyiwgJ6ZGfDEPY8kWBwuK8jiIxz3Prmuk5Auo2gp7tex0THb dCWG6qzmrF2eHe5Gy9nQ1XTkR5EgedDUWI9jzv0twzigQ2excigoi14kzmLhQjYDrbli RlVc5KHd2m6t0TKE9n5oEz8xUB8p9ghcdaE1Avw2JMkZytmzIzMQpFdQbnEBYd5MwvBg YTXLCgx9sO37jWpY4gmAm2qlt4S2y95ALBLtvVi9ueqNBN5nayY5p3yFI7MQfHjpefY3 6hOQ== 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=fGd1VkabJB4Eq3ASDJMhI5jqRQWH42tCX8wUWPvduDg=; b=RzqJw/JnA14rOOa2WBXS3JLzfHQwVL+98z5br5x+hUTlUgd5BNeeiCJuK58FLTNW5n kzh0c/yIeTKZ08XSIASx5VEzRLrRtTe/7dfWVWDR+/N8yBD/ldnOK9LOvGGfXN1BiYJG mopV7eJrCco/0PWXNZxhl0leh59UOT6LUU0JD2mGkSJJ3L7Tw2+3ceX/OGnFveN3N0L2 s/+P+qbkhzGex6fZ0gC/2tSMzxrnPKMPnoMuDNJJu8f1Y/KbwIYRW9PlBmPc/ngPama3 h9AkTOPTiqm2pgNAfXYR53BtodiCN3DPqy20doU4didiYDmv2gYcxj/X+oCa11hZ4/UN olAw== X-Gm-Message-State: ALKqPwfyhBqi3DL9vf8C1qKA8CgPIF90Jmv+Meuz0zOXdtDdRvieqIUq 1toY3MqrsnzWK0FEQ2eAWg/5LjUz X-Google-Smtp-Source: ADUXVKJQhk/IOzhyof1RufMqeqkejx63vlL9zqfERz4pdJmA91zTkJDYtjX0nROg8FDRVtj/ZEjA7A== X-Received: by 2002:a63:7d43:: with SMTP id m3-v6mr3525pgn.117.1527627626929; Tue, 29 May 2018 14:00:26 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Wed, 30 May 2018 02:30:05 +0530 Message-Id: <1527627607-15698-3-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1527627607-15698-1-git-send-email-skrtbhtngr@gmail.com> References: <1527627607-15698-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.47]); Tue, 29 May 2018 21:00:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 29 May 2018 21:00:27 +0000 (UTC) for IP:'74.125.83.48' DOMAIN:'mail-pg0-f48.google.com' HELO:'mail-pg0-f48.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 74.125.83.48 mail-pg0-f48.google.com 74.125.83.48 mail-pg0-f48.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC 2/4] add automatic cleanup support in src/util/virarptable.c 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.42]); Tue, 29 May 2018 21:00:50 +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" Modifiy code to use cleanup macros where required. Signed-off-by: Sukrit Bhatnagar --- src/util/virarptable.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/util/virarptable.c b/src/util/virarptable.c index c0e90dc..f53a479 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 @@ -89,6 +88,7 @@ virArpTableGet(void) VIR_WARNINGS_NO_CAST_ALIGN for (; NLMSG_OK(nh, msglen); nh =3D NLMSG_NEXT(nh, msglen)) { VIR_WARNINGS_RESET + VIR_AUTOFREE(char *) ipstr =3D NULL; struct ndmsg *r =3D NLMSG_DATA(nh); int len =3D nh->nlmsg_len; void *addr; @@ -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]) { @@ -155,13 +153,10 @@ virArpTableGet(void) } =20 end_of_netlink_messages: - VIR_FREE(nlData); return table; =20 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 Sun Apr 28 22:23:08 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 15276276467581005.1565016838298; Tue, 29 May 2018 14:00:46 -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 F37AD3001ADE; Tue, 29 May 2018 21:00: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 B56885B684; Tue, 29 May 2018 21:00: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 572424CA81; Tue, 29 May 2018 21:00:44 +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 w4TL0gaX023426 for ; Tue, 29 May 2018 17:00:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 14FAF97394; Tue, 29 May 2018 21:00:42 +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 0DBE290CFA for ; Tue, 29 May 2018 21:00:42 +0000 (UTC) Received: from mail-pl0-f43.google.com (mail-pl0-f43.google.com [209.85.160.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F113D2BCD87 for ; Tue, 29 May 2018 21:00:30 +0000 (UTC) Received: by mail-pl0-f43.google.com with SMTP id i5-v6so9662895plt.2 for ; Tue, 29 May 2018 14:00:30 -0700 (PDT) Received: from centos.localdomain ([49.32.89.162]) by smtp.gmail.com with ESMTPSA id v6-v6sm52176763pfm.120.2018.05.29.14.00.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 May 2018 14:00:29 -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=jj9MVbyMp2LEOSSEmNymApLsbpS0+jP9UH2ORhI7zUY=; b=ooBApOBLs4wI+VZNEHupav4KeK9LvMPhDY5gE8qDKv+nba8dsiTLABn1Rpl3O3pshe rVPxlXqOqiHblQ4i3E8BsoPkweqMcSSJ4qWvGMqmPOZIAmc5HJEOWi9T6ICVE2f2gt6m vX7LLGwY9FqOPKRIKX5XH/YPZYrH665EWb2EHBzz5jhBsgP/h8+ny65K0YHLPKk1pfgp LHP1o0gdrQ7SHcJMLzFSSqDxGQ5kJI/Q95dz4S0D64v6Hwb5jChGtd2jHFN8sdz2h3J9 O2EZCJMl7Fqa7fBLn9+9njkV+DVK42M1sN4QNK+6ovKMgDD1Jj60JdNKitcRaoqNxJab xBQg== 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=jj9MVbyMp2LEOSSEmNymApLsbpS0+jP9UH2ORhI7zUY=; b=Cs+5L4MqaxJqBneZrDUZc6ok+OOn0WpLvDnvctAgQF8AMv5c/6JGq3AXSwf4uHFpXt kaLw3O7beikH96uNgh6IA3umUnppUmaVOpfziIlgap66pLL4i2mxVTF6HXPk7coG2d3y b2NKvLWPStTZa8ieui9a3jw3aTSezKPsGJIAb6j7kHYGADKAfavE52GLkffRnyhI/Stz /YCpkgpMhBFsdQi+cV0rzsqFqUz07dNCGmIERSp5AeMOHEYQo3k+w5stXKc007VVM+qn Lvfv+D+ANMb6/GFsja0ZOiF3DWMfEsw0xMGMkh3BUPjOV4U/nk/5rqKVXSV8ObFP4okX Er+Q== X-Gm-Message-State: ALKqPweq78vJ/fHknarzr6TJfDJvtQZDRuwmFgs4proSPbBwN/AGOE9a C8h+Alw82nuxxo8OxaOJErCPEL8o X-Google-Smtp-Source: ADUXVKJZ2BHr9CkkS9G9gfnhV/lf06H46yrtnTemNQn/LwlC8LrAhOby8mF6VkSxVoBuvs63gbjKiA== X-Received: by 2002:a17:902:4301:: with SMTP id i1-v6mr19375pld.280.1527627630259; Tue, 29 May 2018 14:00:30 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Wed, 30 May 2018 02:30:06 +0530 Message-Id: <1527627607-15698-4-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1527627607-15698-1-git-send-email-skrtbhtngr@gmail.com> References: <1527627607-15698-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]); Tue, 29 May 2018 21:00:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 29 May 2018 21:00:31 +0000 (UTC) for IP:'209.85.160.43' DOMAIN:'mail-pl0-f43.google.com' HELO:'mail-pl0-f43.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.396 (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.43 mail-pl0-f43.google.com 209.85.160.43 mail-pl0-f43.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC 3/4] add automatic cleanup support in src/util/virauthconfig.c 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.42]); Tue, 29 May 2018 21:00: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" Modifiy code to use cleanup macros where required. Signed-off-by: Sukrit Bhatnagar --- 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 91c9c0c..66f7f7e 100644 --- a/src/util/virauthconfig.c +++ b/src/util/virauthconfig.c @@ -106,10 +106,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 @@ -119,47 +118,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 Sun Apr 28 22:23:08 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 1527627652490130.42230856762671; Tue, 29 May 2018 14:00:52 -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 DEB9F30A56A3; Tue, 29 May 2018 21:00:49 +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 96FFB1001902; Tue, 29 May 2018 21:00:49 +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 283E71800C9D; Tue, 29 May 2018 21:00:49 +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 w4TL0kFq023439 for ; Tue, 29 May 2018 17:00:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4C9C95B686; Tue, 29 May 2018 21:00:46 +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 4292E5B684 for ; Tue, 29 May 2018 21:00:44 +0000 (UTC) Received: from mail-pg0-f50.google.com (mail-pg0-f50.google.com [74.125.83.50]) (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 D36AD8E6E6 for ; Tue, 29 May 2018 21:00:33 +0000 (UTC) Received: by mail-pg0-f50.google.com with SMTP id a13-v6so7103130pgu.4 for ; Tue, 29 May 2018 14:00:33 -0700 (PDT) Received: from centos.localdomain ([49.32.89.162]) by smtp.gmail.com with ESMTPSA id v6-v6sm52176763pfm.120.2018.05.29.14.00.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 May 2018 14:00: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=twYffM41VYaCqB2Tih6FquvehXlxQn7dEalJKjrgp5w=; b=WXXlhQfh84w9VrNNcAXTFtOhXCMuqdRjsnmetQypjP7bFM5Sz5nOd0et9nXwJbGdBf fmGT+mU85KnDGv5gBX/55l3CbwSeH9nVnRLD5mXsyDHKj00RLh7kPHF66fBfEDEDMn75 NNE/WLPt2Gbu+dCNR9RuC+pgbURsQmz4VVsIw9YQ4p+06rdU6HQbVslPchfPUqe7ds6Z DFieoGz1GPmwAnShqdV76senomoWPlvfnpaVjDahibC/SprCFz1zFPLpS23F7CxBkSzU YwQPdVeKtb6DeqLtlXdXnOnC8gYImQs73iS2039EYi3Z5rWgfOkTCj5FjSVCBGWiLIV8 MHHQ== 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=twYffM41VYaCqB2Tih6FquvehXlxQn7dEalJKjrgp5w=; b=G+1zn+RSpcn1dNNIqFqXwOv1ld0R/inmiILKZYhhiiroCPcsq3gtT6N81ypuOJ6DZu 1qPM7JBhvFvm8H2ahivKcvO4/oRJQcLFyMVayBjSYg8MHdaF6qtqBWWpqgWs1gUC1Mv+ LmVj+71sYfUKorM9ie6PHs9pzJkv7HsXI9HjcfjFtgMNZBq54mGRQ0EtR3+ByHLPMlDx 4GGxLUfuvg8rOWva18OVjMW3v8hVUdFzsP3+T3N2gqkb74TWrn1x3gQT67iVwtoogpuR jyGBSmY2+h2cJyVIUa57B2AgDK3l2iYzQ5vv3nWxxnWdBX75PcnfoVMpxAyPQ7HDXrNI NVSw== X-Gm-Message-State: ALKqPwfkHEuDB6n0mdw1bJGKBmHbjoM9pyK7ymldH3aAEye6jMtdxEyw TPQdG+cnIx6WHAmOW2n6Cwdn8b0h X-Google-Smtp-Source: AB8JxZrsCVWe38DrS7+KkcfYozQk678FWf+yQZ5ldDMi47BWjbXsnxjGP4gtqjJpDkFKJFg+cHXtlw== X-Received: by 2002:a62:9fca:: with SMTP id v71-v6mr18796098pfk.233.1527627633056; Tue, 29 May 2018 14:00:33 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Wed, 30 May 2018 02:30:07 +0530 Message-Id: <1527627607-15698-5-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1527627607-15698-1-git-send-email-skrtbhtngr@gmail.com> References: <1527627607-15698-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]); Tue, 29 May 2018 21:00:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 29 May 2018 21:00:33 +0000 (UTC) for IP:'74.125.83.50' DOMAIN:'mail-pg0-f50.google.com' HELO:'mail-pg0-f50.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) 74.125.83.50 mail-pg0-f50.google.com 74.125.83.50 mail-pg0-f50.google.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC 4/4] add automatic cleanup support in src/util/virauth.c 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]); Tue, 29 May 2018 21:00:51 +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" Define a new cleanup function for virAuthConfigPtr in src/util/virauthconfig.h. Modifiy code to use cleanup macros where required. Signed-off-by: Sukrit Bhatnagar --- src/util/virauth.c | 66 ++++++++++++++++++--------------------------= ---- src/util/virauthconfig.h | 3 +++ 2 files changed, 27 insertions(+), 42 deletions(-) diff --git a/src/util/virauth.c b/src/util/virauth.c index adb093e..aa7593c 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" @@ -42,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 @@ -54,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 @@ -64,41 +62,38 @@ 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) - goto done; + if (access(*path, R_OK) =3D=3D 0) { + VIR_DEBUG("Using auth file '%s'", NULLSTR(*path)); + return 0; + } =20 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) - goto done; + if (access(*path, R_OK) =3D=3D 0) { + VIR_DEBUG("Using auth file '%s'", NULLSTR(*path)); + return 0; + } =20 VIR_FREE(*path); =20 - done: - ret =3D 0; - - VIR_DEBUG("Using auth file '%s'", NULLSTR(*path)); - cleanup: - VIR_FREE(userdir); - - return ret; + return 0; } =20 =20 @@ -117,8 +112,7 @@ virAuthGetCredential(const char *servicename, const char *path, char **value) { - int ret =3D -1; - virAuthConfigPtr config =3D NULL; + VIR_AUTOPTR(virAuthConfigPtr) config =3D NULL; const char *tmp; =20 *value =3D NULL; @@ -127,23 +121,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 @@ -156,7 +146,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) @@ -193,8 +183,6 @@ virAuthGetUsernamePath(const char *path, break; } =20 - VIR_FREE(prompt); - return cred.result; } =20 @@ -207,7 +195,7 @@ virAuthGetUsername(virConnectPtr conn, const char *hostname) { char *ret; - char *path; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (virAuthGetConfigFilePath(conn, &path) < 0) return NULL; @@ -215,8 +203,6 @@ virAuthGetUsername(virConnectPtr conn, ret =3D virAuthGetUsernamePath(path, auth, servicename, defaultUsername, hostname); =20 - VIR_FREE(path); - return ret; } =20 @@ -230,7 +216,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) @@ -264,8 +250,6 @@ virAuthGetPasswordPath(const char *path, break; } =20 - VIR_FREE(prompt); - return cred.result; } =20 @@ -278,14 +262,12 @@ virAuthGetPassword(virConnectPtr conn, 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); =20 - VIR_FREE(path); - return ret; } diff --git a/src/util/virauthconfig.h b/src/util/virauthconfig.h index ac0ceeb..375ccad 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(virAuthConfigPtr, 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