From nobody Fri May 3 19:08:29 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 1528123913849329.69855492335785; Mon, 4 Jun 2018 07:51:53 -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 1C2D2B82D9; Mon, 4 Jun 2018 14:51:50 +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 64C375C1A1; Mon, 4 Jun 2018 14:51: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 0F87D4CA80; Mon, 4 Jun 2018 14:51:48 +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 w54EaY6K008029 for ; Mon, 4 Jun 2018 10:36:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 06EA430BF5AF; Mon, 4 Jun 2018 14:36:34 +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 F12383083328 for ; Mon, 4 Jun 2018 14:36:33 +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 47FFDF5706 for ; Mon, 4 Jun 2018 14:36:22 +0000 (UTC) Received: by mail-pf0-f195.google.com with SMTP id a22-v6so2950876pfo.12 for ; Mon, 04 Jun 2018 07:36:22 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36:20 -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=5uswZkEfXtRqeQFwzcel0Vstz76NVud3YFP3eomJUYw=; b=TZGi1quF4IZ2+v3hKft1fm56Njae2hNZFQwJ59ONLC2mTNkcn5R8/8TkYbLpTg8VRz LAoBYet/UPd1NTFZQ/N4SMk/DAnhQHx77jfYbKwcEYx1lz91jzMB06/FcuA5azNFGq9t oNjpU4VJbWk2/p8m0YQpFZKSdk96WuXuu46RCgDHG49aHQCmRVOgMPWvZsgiHix0yFgj j+vTj0E8Z8bDmwWvrsAqjTTTfVV1XSjRfz4t/K1GA9ei5bkPHs8O/uQ0l9q0Ma7xhJOa aJLGU4zzUm0h2uj5w1jr3gru63QDyIxgbPDfg1AQBkJsYEpVM/yq3nDmEZqGFPna/y4A yagQ== 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=5uswZkEfXtRqeQFwzcel0Vstz76NVud3YFP3eomJUYw=; b=BShR8JtmZYM+s9h9EdPSdS1Pqocb72vlpaQ18G1jmbqC/T1oIT+z/0zpn+BRkTQJxd mLs7arM+yvzzD4JfJLw0ewuhENfG3Ye6yfathDIZfOGZYG2K8nTkNvCrpnSrfbDLlrv2 EUxXjCah/Jfd7mRu2htgABu8cWhNHC5how2qyTsE+wqFBYxvCCZW9v8pGf4XIPhuRg7m RQNLe0gbVbeYwK1RAyZUXB3nrQ5JPz4C1CnXZOZqv3/AEqPCz9sdp2bvx2PXZbQcsYcc oObN3z0NVLioLFCkyKJNmcjeu+wtM1DRjiVrkPEob4UmaWPiVHvCP2ISBrcXV5XfuCYZ pijw== X-Gm-Message-State: APt69E1LqOHvOcSSo2/6xF8dY56hHnhMpRZWhWXVc3a9JL+iLu5rQBdB qlTY6VGEykktHyGSTWHnqMxVsWV5 X-Google-Smtp-Source: ADUXVKKf+rgvy1HO5jKZoYewW4dFqqCiC8wN8kABGL5a4SIJT/s7Wa/jNbQ72UnobpoHgAMbR4h8/w== X-Received: by 2002:a63:721d:: with SMTP id n29-v6mr5228574pgc.194.1528122981490; Mon, 04 Jun 2018 07:36:21 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:41:59 +0530 Message-Id: <1528013536-22196-2-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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]); Mon, 04 Jun 2018 14:36:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 04 Jun 2018 14:36:22 +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.991 (DATE_IN_PAST_24_48, 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.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 01/18] 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.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.25]); Mon, 04 Jun 2018 14:51: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" 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..bb37c48 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 + * + * This macro defines a function for automatic freeing of + * 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 automatic clearing of + * 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 variable 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 Fri May 3 19:08:29 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 1528123023433156.52997986981381; Mon, 4 Jun 2018 07:37:03 -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 D446830C75D3; Mon, 4 Jun 2018 14:37:00 +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 26CCD5C578; Mon, 4 Jun 2018 14:37:00 +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 801061800FC1; Mon, 4 Jun 2018 14:36:58 +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 w54EaZ7i008050 for ; Mon, 4 Jun 2018 10:36:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id CE5523083326; Mon, 4 Jun 2018 14:36:35 +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 C5E15307D983 for ; Mon, 4 Jun 2018 14:36: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 7222830A74D3 for ; Mon, 4 Jun 2018 14:36:24 +0000 (UTC) Received: by mail-pf0-f195.google.com with SMTP id a22-v6so2950924pfo.12 for ; Mon, 04 Jun 2018 07:36:24 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36: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=Y8oYvAXydUCf11SqxrRRXK43DENB6q9NqWz5pFc7B+Q=; b=lq2+Z+uZk0nVFFzxZAFISyjxmFW68MHpENYSranBCobPzivjPUehdwPmv2lfa4ZenO /rirkwm0bcCsMpDAMhlFQQtXtMtDl9VzE/OOk290VXQrclJziCIso/1IZ/hpLxP/Dm9m NS25q9DCWzOkAmyVR4ofkiMXlt5pQeEAOwA2jww9ps3c0iLvZbvjA+Uj6BKftUjsDkEn I95yd3Hdp7k4y2nG3cHxqFHV15CGI3cfmRwkBFps7UtnCpbqtXikNXGd5KSfSrnu3mLD rMwljSpoESs41cLiRcYQozdobwdEY+y/6BgqIOaQtPW5KrDx2p0s+B8ks34SfMB4WxZs xm0w== 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=Y8oYvAXydUCf11SqxrRRXK43DENB6q9NqWz5pFc7B+Q=; b=PxlhXP9A7gVioS1CWWXSPPrX7d3WmNAgGcqw/drkmnzcCh3qQxjtzsi2XYjm2R976Q +flpJy7/o8QE/AzxUBAsLZUd13aR8KlWi+0Gc2zVb5ESoMxO+CLAT5L5WLuPBp5Sev/6 aRWxHJqycHJTxgVWM7LoWUWSnSh5DwCfWjrGSWKFwMNeFVXMyMJRk9vtdtUUQMM3ohyi bG+16JGCYVcaLCo/h/LWD+umZ90pOao801sBVZcP+RAZIUVS4ImVNGENAe9jEQGHkOgD VFp9F4gU/oKWseLgMz9+TOOsD1yZ1bVF+u4TBdPi4SbJGeL0hssulwOUryckpwqILwSD MeyA== X-Gm-Message-State: APt69E3VyET38ECW7Ak3+ssKz0GyaXjcfXKRNKzQJXfdcdi4k1BDfFP9 /RsFJ7kVe7S4PXk0gNa+XehrycIu X-Google-Smtp-Source: ADUXVKImQGlvFFB1YOi+aVOZ9upjbhLr6L6VwujhisLib3BjWEezN6HSFTyaEsuRsZD1nd1qoD7Vhw== X-Received: by 2002:a63:bf0b:: with SMTP id v11-v6mr4269149pgf.29.1528122983610; Mon, 04 Jun 2018 07:36:23 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:00 +0530 Message-Id: <1528013536-22196-3-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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]); Mon, 04 Jun 2018 14:36:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 04 Jun 2018 14:36: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.991 (DATE_IN_PAST_24_48, 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.45 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 02/18] use VIR_AUTOFREE 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 04 Jun 2018 14:37:02 +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" Modify code to use VIR_AUTOFREE macro wherever 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 Fri May 3 19:08:29 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 1528124045200612.4429396399174; Mon, 4 Jun 2018 07:54:05 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94E1530C98ED; Mon, 4 Jun 2018 14:54:03 +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 25BDE608EF; Mon, 4 Jun 2018 14:54: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 7A85C1800FD8; Mon, 4 Jun 2018 14:54:02 +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 w54EacOQ008060 for ; Mon, 4 Jun 2018 10:36:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3D73F2010D5D; Mon, 4 Jun 2018 14:36:38 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 30CB02010D5C for ; Mon, 4 Jun 2018 14:36:38 +0000 (UTC) Received: from mail-pg0-f52.google.com (mail-pg0-f52.google.com [74.125.83.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 A8B7729A69 for ; Mon, 4 Jun 2018 14:36:26 +0000 (UTC) Received: by mail-pg0-f52.google.com with SMTP id e11-v6so5341090pgq.0 for ; Mon, 04 Jun 2018 07:36:26 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36: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=DKEH/74fDCOTvqcXU0MzDZ5+tFtR/fBCECOLpwBuQP8=; b=RKFtEdwWzMtKNorffYWa8lysFYPNmiv1Ea283m6wyY8AdRfTqJcnmVTRF7EJTssOsf 9KqSYnGFxEcyIbMersUN+fvzD7LLpwIGwzJyCVguU3LZs/vjRrlexUIlVMsUmTTA9ycx o9h2Y8E+ExsiO4rkRJGuuMY28gpQvPLgvd193PrINJjedLfQSmxzTnIzc+6tIbWJ/vYW hjzAYWbCDwiiNb6Aq6HYT65nTJ2EPitnnX83c6Wb+KWUMYemAUIVWd3VhlehyOu7yFdI x9NES3HHqfkrCICFQnAdizdI29mZKXlpeO4CQrKfnzjxfcdGPtdRSPrX/PjPxvyiBA3e RFuA== 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=DKEH/74fDCOTvqcXU0MzDZ5+tFtR/fBCECOLpwBuQP8=; b=jSrdk3M9IJHt2o/JNTpyWAyEF4laxGs1Ut9uuV1Nm6OSGoWpKzT08FCc3qkBgW2Rkw NoKnfKKZKs9D77EB4bFyymGuL9yV8lckWVTPOezmqi16TpIa+TlfJR23y6P9zSyQa24w Yl0/Yd6+FdTMQvICpA2m4qA3qRGbYA0UfrNWa/1bPVohT9PntTglJvx0762etexEzQtt 1Z2UmXf9At5oHwP6Yqtc1V6awQJbnkaWvf42enJ/67TImLfI67fjoHb5vkNAWIG3dKl+ b4Gmz2oeEEL3XCnJJzmWMYR/c9xTnhqp4hctkVpgyalyR7kl4f8AT1fMqcYl7v4Mswqe wgpw== X-Gm-Message-State: ALKqPwcBGnW70X7IW3sa7NwblwFVrmBy1L9HdWysMThn9fy30J5p3R/G dkKE+bg8dUMMyIhHMWDH/u/YkZGv X-Google-Smtp-Source: ADUXVKILsESNd/iddcnr/KDz41cx+jEheRl83Ux1a6OjKLt+N2jsJ+YL4cs+vnHsQgHLU0s2JFi4Eg== X-Received: by 2002:a63:2dc2:: with SMTP id t185-v6mr17815917pgt.204.1528122985768; Mon, 04 Jun 2018 07:36:25 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:01 +0530 Message-Id: <1528013536-22196-4-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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.28]); Mon, 04 Jun 2018 14:36:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 04 Jun 2018 14:36:26 +0000 (UTC) for IP:'74.125.83.52' DOMAIN:'mail-pg0-f52.google.com' HELO:'mail-pg0-f52.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.786 * (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 74.125.83.52 mail-pg0-f52.google.com 74.125.83.52 mail-pg0-f52.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 03/18] use VIR_AUTOFREE 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.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 04 Jun 2018 14:54:04 +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" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- src/util/virauth.c | 60 +++++++++++++++++++-------------------------------= ---- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/src/util/virauth.c b/src/util/virauth.c index adb093e..089a820 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -42,10 +42,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 +53,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 +63,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 @@ -156,7 +152,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 +189,6 @@ virAuthGetUsernamePath(const char *path, break; } =20 - VIR_FREE(prompt); - return cred.result; } =20 @@ -206,18 +200,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 @@ -230,7 +219,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 +253,6 @@ virAuthGetPasswordPath(const char *path, break; } =20 - VIR_FREE(prompt); - return cred.result; } =20 @@ -277,15 +264,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 Fri May 3 19:08:29 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 1528124181630653.9171141081146; Mon, 4 Jun 2018 07:56:21 -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 4FC3BE8CC8; Mon, 4 Jun 2018 14:56:19 +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 D59C1308BDC2; Mon, 4 Jun 2018 14:56:18 +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 33E241800FD9; Mon, 4 Jun 2018 14:56:18 +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 w54EaeI6008071 for ; Mon, 4 Jun 2018 10:36:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id A2DD72016A87; Mon, 4 Jun 2018 14:36:40 +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 96C142016A85 for ; Mon, 4 Jun 2018 14:36:40 +0000 (UTC) Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 27B52175826 for ; Mon, 4 Jun 2018 14:36:29 +0000 (UTC) Received: by mail-pg0-f67.google.com with SMTP id a13-v6so14531776pgu.4 for ; Mon, 04 Jun 2018 07:36:29 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36: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=d438f0vrStWV041NTAU3meoX8etVbS7ZTOD4O2Ywdog=; b=qBeF3wIacx/jH5waMkGF7hlEx1ZE8C0PslucGR8Q6vLAX1YQvCSwKLV5X9F9sYPL/v POF48vJ/Zu/3xY13Z2MInQ6J1tjJdbP+YKzk9NjvUteWb8eUhk4LBxJY8qSlhF34z8XF yz5PK0dMgYuwHZle3qPax52Zj+o5K9fz+sEAUOnLFrSELZV2hk8m+A4sEHWDuJ6F79Gr zn4qKfU5T0AkfZdeTMfedltvj8fH9h1IM0AYY8CJBmuJbnZLw3260UdZr+DXN2zIIfyR +KAd5YCy76XjniPzNX0GHaGfKJ0btb2PWCaWtYvvpttjvErtlu6a4/SnFoU9s3uMwPqj 9SAg== 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=d438f0vrStWV041NTAU3meoX8etVbS7ZTOD4O2Ywdog=; b=CTkvgF8KXWZRnzsXcOviMler1XahDmd1k539Qg13ng9r8qerE68jky2uAbaVW0S4/d eWE5N7QmnsE86HT2N6KGSEcqwd/RQnNmd0HLJatFp6U257lDGKKRi5O2rKiHyOOo0f74 KIavNokpPLA1t4dUJ6B6WnE4qSO28SMosiifTDxlo0Ijm3wZ7pYXbuTr2sMpBFvWuytu +6HczklXyWc9sYIpdyBUq6Ecw7DT8O4x/j4Qe7PaixrEBG/E6eWP+jbTRGqMqW2Cx20r YmxIoQhEF9/6rsCvbOGM6oqEBss86XBEyFcOXY0MOFv1JVoG4pEx3wAWfZmw97LrMtVg Hqkw== X-Gm-Message-State: ALKqPwe3N1eZyNumKBILBvw1k8D533Af6TSNXdHXoCAwax2KiURD7Mx9 lNJ6VdIgr4ZKJNye7v40HNFFQqOo X-Google-Smtp-Source: ADUXVKJHd4cCgpbW5Dp18kZpwaERb6Xpq4OzFWy7bjG4VvaTzmjcuVJv+DgXdMG/QKEVYWfEok/3XQ== X-Received: by 2002:a62:c8a:: with SMTP id 10-v6mr21630426pfm.27.1528122988329; Mon, 04 Jun 2018 07:36:28 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:02 +0530 Message-Id: <1528013536-22196-5-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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]); Mon, 04 Jun 2018 14:36:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 04 Jun 2018 14:36:29 +0000 (UTC) for IP:'74.125.83.67' DOMAIN:'mail-pg0-f67.google.com' HELO:'mail-pg0-f67.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.766 * (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 74.125.83.67 mail-pg0-f67.google.com 74.125.83.67 mail-pg0-f67.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 04/18] use VIR_AUTOFREE 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.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.38]); Mon, 04 Jun 2018 14:56:20 +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" Modify code to use VIR_AUTOFREE macro wherever 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 Fri May 3 19:08:29 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 1528124316728294.0318095936026; Mon, 4 Jun 2018 07:58: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 DAF3430C94C6; Mon, 4 Jun 2018 14:58:34 +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 A21E89B004; Mon, 4 Jun 2018 14:58:34 +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 4C5604CA81; Mon, 4 Jun 2018 14:58:34 +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 w54EagFH008082 for ; Mon, 4 Jun 2018 10:36:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6F3A72010DA1; Mon, 4 Jun 2018 14:36:42 +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 653152010D9F for ; Mon, 4 Jun 2018 14:36:42 +0000 (UTC) Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7CC9FB8904 for ; Mon, 4 Jun 2018 14:36:31 +0000 (UTC) Received: by mail-pg0-f67.google.com with SMTP id a13-v6so14531815pgu.4 for ; Mon, 04 Jun 2018 07:36:31 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36: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=+7RgcvDSujfvXMnHXCGvnKxHhs5ns48+imawVJGWVXw=; b=QH+aRGb2BUAyfLmqySQE3a07+2zUDWHCsnxFwvIGzU5aSjvUFirJHv+VZjxp2bWORz +seTkox5eRqhDs1JudoUK5mbtfQPwokbHeHqrA8x2jbdudb+YIn/ZkF9PKgx582DT8zc 3k25fFygb6AJpkrc4zWHgUtBp1Go68ONYkCeVuYLdkDYlLHz4ihaTDPRLOxf8kpc2RYK jYluhe2kbIWrHsFFZ0NqEHYkZ37Sr4ISeogGo0dhyqgjGhqjFf0hShVEL0+0IoEJGUG8 Xnonro7aKPi3ZZgG8qxXaM/O6oUgeEx+EbCMmfZkQcGwWn40n1gZMmk18UISFcjWPnFo y4oA== 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=+7RgcvDSujfvXMnHXCGvnKxHhs5ns48+imawVJGWVXw=; b=pDDo1tdy3AGrkNiSh3YQTTrl3AH4z9WGyCZ8uenY8lHOQc+xdRJx848SAGJrkfr5+f o3c8zbcRHsAat1o0x9rGQbn0ea3o5rYtsOlWOeWeS4NnBvuYfIMy9wIkm/H3wXRpSjzs ZyM6YEJpiLY05S2Wtz00dyp3A9qcQdMA2H9/a8rDVVZ+9/82hU4uSqs/4OcNu1p+iFSo oSnWBNAFi1iL4Hdp8+Wz8JIQCoRjZfI8j/Aa2z8XRSnbDbAepf4IewhUQnAlPt+70WNd 4IhFTcancciCfLSqE4Z1ZAr4VtxHVsIX56yVXdoKAbSX1lU+TRb4oM0P/S6lnaYymVXk PKag== X-Gm-Message-State: APt69E0em6enmdXfKllju+sMr4//onhxAKLy8jGUpLr4sgW90LQPggtQ mVNxK/hxxo8b5UdR3pQIUD+/NYx+ X-Google-Smtp-Source: ADUXVKKjrQRBW16gcmhq6VzlCxgkLyTem1xd6Eafk2+GX0V46T7zuy6HxkxgAUXo39/aGgOG3YlOmQ== X-Received: by 2002:a62:8d03:: with SMTP id z3-v6mr8082821pfd.112.1528122990669; Mon, 04 Jun 2018 07:36:30 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:03 +0530 Message-Id: <1528013536-22196-6-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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]); Mon, 04 Jun 2018 14:36:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 04 Jun 2018 14:36:31 +0000 (UTC) for IP:'74.125.83.67' DOMAIN:'mail-pg0-f67.google.com' HELO:'mail-pg0-f67.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.766 * (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 74.125.83.67 mail-pg0-f67.google.com 74.125.83.67 mail-pg0-f67.google.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 05/18] use VIR_AUTOFREE in src/util/iohelper.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.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 04 Jun 2018 14:58: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" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- 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 Fri May 3 19:08:29 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 1528123980691948.2883043371231; Mon, 4 Jun 2018 07:53:00 -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 892EBECF9B; Mon, 4 Jun 2018 14:52:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 15183600C8; Mon, 4 Jun 2018 14:52:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 53F6918005DF; Mon, 4 Jun 2018 14:52:55 +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 w54Eakdf008098 for ; Mon, 4 Jun 2018 10:36:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id E6D0A308BDAF; Mon, 4 Jun 2018 14:36:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE67A308BDAE for ; Mon, 4 Jun 2018 14:36:46 +0000 (UTC) Received: from mail-pg0-f66.google.com (mail-pg0-f66.google.com [74.125.83.66]) (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 B8B4130CADE7 for ; Mon, 4 Jun 2018 14:36:35 +0000 (UTC) Received: by mail-pg0-f66.google.com with SMTP id c9-v6so11715004pgf.5 for ; Mon, 04 Jun 2018 07:36:35 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36: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=s2qMJ2Tp/vbElWv3lNioZ8IWR96pXElEPCkmCXf6VcM=; b=aDcgQyZPpzva0l+Yaobe4QP62da83LoHXUsvuiGS6ojRJpfAuNwcD5CcL/s0o2PXnB aEJ32s6sLT5m5upM7JMC5RAmvMpF7Xdim18tgpi2YOqM5u2TiIr+RNj1TXFJzMr8EVJQ Kn/GICT35PMHjvxU0q9Wqm7/ZxPrTy1VgWVIlCDcaPWUBCmbyK9W7oMigzKpid4Ct83Q ohQGh0mvi5ksame3QvT9tbSHWiUPQrcxe7dP102X/ba9NYH/Xj0WvWs8ETdCsxgz9YO/ OVfbADmDdbYEhdz3RNGUNC9XdwD8AFYxZL4dDAfyvJd1RJqz/URAD7OTQywV5pPFU68H BeJg== 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=s2qMJ2Tp/vbElWv3lNioZ8IWR96pXElEPCkmCXf6VcM=; b=ZtzC9X+gBDyJ35UliU/p2deNPhnD0NC1P1hQ4nSaLG6OdfTQYJz08pDkjslO83i0fR F+oesXyzbzYamzCruIKpNcKRk6woKih3iKUcKP4ai3qAR+KDZhAPbky3lgECivQTZ6fj 5q4IWcEpOuIaaA0qPAdrtY/VG62Zxkh5zTmUSbRWKIchFv/5HBDkYeVOmKEeHxJf9Cbh 6Mqv61dLDXBvrguUV0g+pHLl+6i65Jz+vm10g+Fyfy2wuWGhOBHEDWerut4rr1dzoHw+ RMeqazI0coZOYe59CLDgLfK+/Q3VFfTKSMwbpV1J6K1mls3xXJivZhO+4BPBWQBda4Pl KR/w== X-Gm-Message-State: ALKqPwfs3Fl5hgdStIPF4Pk6Q1PP6/DRBhVp9o7h180oML2Vttl6cE5i kS94CbDL13P+pQOptHziEbftBWsq X-Google-Smtp-Source: ADUXVKIOj6XSHKUkuZtvqvrr5dDUihfo3UsN7Uy5j5vMHxmL+gzRWXws8+uByYwqVD5JmAV361OkkA== X-Received: by 2002:a65:61d1:: with SMTP id j17-v6mr14543948pgv.447.1528122994878; Mon, 04 Jun 2018 07:36:34 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:04 +0530 Message-Id: <1528013536-22196-7-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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.46]); Mon, 04 Jun 2018 14:36:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 04 Jun 2018 14:36:35 +0000 (UTC) for IP:'74.125.83.66' DOMAIN:'mail-pg0-f66.google.com' HELO:'mail-pg0-f66.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.766 * (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 74.125.83.66 mail-pg0-f66.google.com 74.125.83.66 mail-pg0-f66.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 06/18] use VIR_AUTOFREE in src/util/viraudit.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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 04 Jun 2018 14:52:59 +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" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- 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 Fri May 3 19:08:29 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 1528124448225710.8402342669248; Mon, 4 Jun 2018 08:00:48 -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 D848E387D84; Mon, 4 Jun 2018 15:00: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 650EA30BD340; Mon, 4 Jun 2018 15:00:45 +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 EF47D18033EF; Mon, 4 Jun 2018 15:00: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 w54Ean4Y008114 for ; Mon, 4 Jun 2018 10:36:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id D84BA600D1; Mon, 4 Jun 2018 14:36:49 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D0003600CC for ; Mon, 4 Jun 2018 14:36:49 +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 22BDF3153785 for ; Mon, 4 Jun 2018 14:36:38 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id n10-v6so19840589plp.0 for ; Mon, 04 Jun 2018 07:36:38 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36: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=FJzwz3jFDWZzBqA2Xps0+kRI380uwzkw/ZP+6aJqjaQ=; b=rGgPaqzp9b8vD6vHQGry9WgRAx+vdAbE6zYSVZK1XU+9DidtaK7S18WAkGxlZgskX6 NqL2CFmKxhD4IAHnC0JpddfQGAukEm0DDz2Jy0IQO2XoxLDo/juOxuFwvRO1x1SW+QTe 35XAd0PMmJYhYLMciTjTnw/SPGnCmACyGOArfl7+gEJoavUW5Jh1+Q1kfofV41Q9qGq8 rh+GiWYJ9ekZ7rDn1SBViCHwZd/PqK1g0vvjmT+wPm1H38i1isHfTPItfjIusIX5OUWa lGNM9FtNTkxkvigqvpTDSMTY0UibaNzX4E582n4KKl6QQ1VJKS+f7fTSnEm+BWgMZqPR xZZA== 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=FJzwz3jFDWZzBqA2Xps0+kRI380uwzkw/ZP+6aJqjaQ=; b=bHOp880pu40k+ehMJeanYHktWoaQ06HB64xpPcGfAjo72aKZ9cv1e5DJwrZLk36xkp qqnAfe/2cKPAovQML5zN9dFiHPKHLhGxLYeQLICG5Xb944S31Vg0kud5yVBI3fu/KIpm Z/bPn6ZAbi5kBaK+yQfII7xL5+IbSAlouvEOWizjrhclDaQDTsveyULgn0ZcKiXJXw2u aQT1/DFmCQnQQZAQLnRDQHgyNmrELcWuGYBIa2RdMaRS8NBEsEIkqY9SAIE0APQA7n6v IoG9h4Zg9CGBsrNByWxA0gg7IrBDFkgW5g++HagFdBk0q1R7yd5gqxFbXLEnZ1JO9NJR uH/Q== X-Gm-Message-State: ALKqPwc4L6I6UiQHOCb7SlJuVBdsUou+L69Y53sKviyFS246cins1kNi p4GV1mHcec3yLkgPT5WNf/fD388+ X-Google-Smtp-Source: ADUXVKLZaL/w94WhFDPm7fNgo1VqhQ31on7DYBqoAoRB87mzlcVd60/1XXIcon9h4CHrStBm+8IZZg== X-Received: by 2002:a17:902:246a:: with SMTP id m39-v6mr13345312plg.141.1528122997128; Mon, 04 Jun 2018 07:36:37 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:05 +0530 Message-Id: <1528013536-22196-8-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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.49]); Mon, 04 Jun 2018 14:36:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 04 Jun 2018 14:36:38 +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.766 * (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 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.49 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 07/18] use VIR_AUTOFREE in src/util/virbuffer.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.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 04 Jun 2018 15:00: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" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- src/util/virbuffer.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 3d6defb..5152f73 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -456,7 +456,8 @@ void virBufferEscapeString(virBufferPtr buf, const char *format, const char *st= r) { int len; - char *escaped, *out; + VIR_AUTOFREE(char *) escaped =3D NULL; + char *out; const char *cur; const char forbidden_characters[] =3D { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, @@ -533,7 +534,6 @@ virBufferEscapeString(virBufferPtr buf, const char *for= mat, const char *str) *out =3D 0; =20 virBufferAsprintf(buf, format, escaped); - VIR_FREE(escaped); } =20 /** @@ -612,7 +612,8 @@ virBufferEscape(virBufferPtr buf, char escape, const ch= ar *toescape, const char *format, const char *str) { int len; - char *escaped, *out; + VIR_AUTOFREE(char *) escaped =3D NULL; + char *out; const char *cur; =20 if ((format =3D=3D NULL) || (buf =3D=3D NULL) || (str =3D=3D NULL)) @@ -644,7 +645,6 @@ virBufferEscape(virBufferPtr buf, char escape, const ch= ar *toescape, *out =3D 0; =20 virBufferAsprintf(buf, format, escaped); - VIR_FREE(escaped); } =20 =20 @@ -675,11 +675,11 @@ virBufferEscapeN(virBufferPtr buf, { int len; size_t i; - char *escaped =3D NULL; + VIR_AUTOFREE(char *) escaped =3D NULL; char *out; const char *cur; struct _virBufferEscapePair escapeItem; - struct _virBufferEscapePair *escapeList =3D NULL; + VIR_AUTOFREE(struct _virBufferEscapePair *) escapeList =3D NULL; size_t nescapeList =3D 0; va_list ap; =20 @@ -696,7 +696,8 @@ virBufferEscapeN(virBufferPtr buf, while ((escapeItem.escape =3D va_arg(ap, int))) { if (!(escapeItem.toescape =3D va_arg(ap, char *))) { virBufferSetError(buf, errno); - goto cleanup; + va_end(ap); + return; } =20 if (strcspn(str, escapeItem.toescape) =3D=3D len) @@ -704,19 +705,22 @@ virBufferEscapeN(virBufferPtr buf, =20 if (VIR_APPEND_ELEMENT_QUIET(escapeList, nescapeList, escapeItem) = < 0) { virBufferSetError(buf, errno); - goto cleanup; + va_end(ap); + return; } } =20 if (nescapeList =3D=3D 0) { virBufferAsprintf(buf, format, str); - goto cleanup; + va_end(ap); + return; } =20 if (xalloc_oversized(2, len) || VIR_ALLOC_N_QUIET(escaped, 2 * len + 1) < 0) { virBufferSetError(buf, errno); - goto cleanup; + va_end(ap); + return; } =20 cur =3D str; @@ -734,11 +738,6 @@ virBufferEscapeN(virBufferPtr buf, *out =3D 0; =20 virBufferAsprintf(buf, format, escaped); - - cleanup: - va_end(ap); - VIR_FREE(escapeList); - VIR_FREE(escaped); } =20 =20 @@ -803,7 +802,8 @@ void virBufferEscapeShell(virBufferPtr buf, const char *str) { int len; - char *escaped, *out; + VIR_AUTOFREE(char *) escaped =3D NULL; + char *out; const char *cur; =20 if ((buf =3D=3D NULL) || (str =3D=3D NULL)) @@ -847,7 +847,6 @@ virBufferEscapeShell(virBufferPtr buf, const char *str) *out =3D 0; =20 virBufferAdd(buf, escaped, -1); - VIR_FREE(escaped); } =20 /** --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 19:08:29 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 1528124111581738.66229609376; Mon, 4 Jun 2018 07:55:11 -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 654EF30A78DA; Mon, 4 Jun 2018 14:55:09 +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 10D89308BDB1; Mon, 4 Jun 2018 14:55: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 801374CA80; Mon, 4 Jun 2018 14:55:08 +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 w54EaruG008125 for ; Mon, 4 Jun 2018 10:36:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id DAF8E8B327; Mon, 4 Jun 2018 14:36:53 +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 D011A8B336 for ; Mon, 4 Jun 2018 14:36:53 +0000 (UTC) Received: from mail-pl0-f66.google.com (mail-pl0-f66.google.com [209.85.160.66]) (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 E225CFA8C0 for ; Mon, 4 Jun 2018 14:36:40 +0000 (UTC) Received: by mail-pl0-f66.google.com with SMTP id f1-v6so19408129plt.6 for ; Mon, 04 Jun 2018 07:36:40 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36:39 -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=yndiVfNe8cn0fSvMqznQAgtaJjeBrSUwZxMFygv+zR8=; b=tS0FFM8hr+ncqS7++TBmQ0z0WWGF93tB4A2120noG9je31XztzYfWedQ3UUxrmMJI2 wr4UoqNqTF/gp30oKTEyD5UkRvQRAz0la88vBPfRyOiEi5rW09njmMB+bzFeTNggt40P btMusJdRq9YFsTRcr6PYWfie8BX1kJDLeZd/awWP5Vr1KhJ3FXkrUmLPyaIFgl4YeVtB ZEJbGEQK2ZwQ37WlbRO065L3x4z3LVDds7p02Dm3xy+4bK/syn6GWch+3HrbGlC+lgOz PqNbB6TVx5oGIEkxzZKneDqWUP2zCe9sfINbPbBaycr92VK0U7C1UiqcC44rP1CczV1T VTtg== 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=yndiVfNe8cn0fSvMqznQAgtaJjeBrSUwZxMFygv+zR8=; b=ZCbM+bNU30CPeniAM2wHaqT4PzHVJWJSn8MINhQhICf4lTLJYSzVmQY+uOJrUN6zHf Qc3XdShXRiH0c6/h1uksaS3etQBY/EZ3QtnghOtpV2VPaqPrWAR4exLYL3Tzduk+avqF IrK3hawgq6QzGlo3M3vxxZnt/E8zu82OmF82RAybBdn6HnjBIa5p3tYfKLzeruPcFF/1 DpmhFyH5lLd/65Co9/b2B1C69V5gic51ACNsnKB0m7wtnR7PMKRaxzZHN3VnuXv1qSIH 47jv1dlCmUPxe06/cqBqVOKrkQ9p0N0uMkN0i3AYiaHxRFh6TgjZW9K9VgPcRfWKrnDT 0q4g== X-Gm-Message-State: ALKqPwc2OPFzHsIM7Odjv/W5L+NXX3eKQaXbaV75H/9gTnL7ib5m730q DEX2p2EcM+IhcUtKCCvglIjUe9hM X-Google-Smtp-Source: ADUXVKJ+J4lwqD2f30XP45YTfM2jP+R/dyJ3SVGRSWmZ5WmKkb9xUJAvJLas1YewFFEOVxy09CwOhg== X-Received: by 2002:a17:902:10c:: with SMTP id 12-v6mr22306664plb.252.1528122999637; Mon, 04 Jun 2018 07:36:39 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:06 +0530 Message-Id: <1528013536-22196-9-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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]); Mon, 04 Jun 2018 14:36:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 04 Jun 2018 14:36:41 +0000 (UTC) for IP:'209.85.160.66' DOMAIN:'mail-pl0-f66.google.com' HELO:'mail-pl0-f66.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.766 * (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.160.66 mail-pl0-f66.google.com 209.85.160.66 mail-pl0-f66.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 08/18] use VIR_AUTOFREE in src/util/vircgroup.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.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 04 Jun 2018 14:55:10 +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" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- src/util/vircgroup.c | 526 ++++++++++++++++++-----------------------------= ---- 1 file changed, 179 insertions(+), 347 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 0a31947..ed86d31 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -163,7 +163,7 @@ virCgroupPartitionNeedsEscaping(const char *path) { FILE *fp =3D NULL; int ret =3D 0; - char *line =3D NULL; + VIR_AUTOFREE(char *) line =3D NULL; size_t buflen; =20 /* If it starts with 'cgroup.' or a '_' of any @@ -223,7 +223,6 @@ virCgroupPartitionNeedsEscaping(const char *path) } =20 cleanup: - VIR_FREE(line); VIR_FORCE_FCLOSE(fp); return ret; } @@ -256,41 +255,40 @@ virCgroupValidateMachineGroup(virCgroupPtr group, const char *machinename) { size_t i; - bool valid =3D false; - char *partname =3D NULL; - char *scopename_old =3D NULL; - char *scopename_new =3D NULL; - char *partmachinename =3D NULL; + VIR_AUTOFREE(char *) partname =3D NULL; + VIR_AUTOFREE(char *) scopename_old =3D NULL; + VIR_AUTOFREE(char *) scopename_new =3D NULL; + VIR_AUTOFREE(char *) partmachinename =3D NULL; =20 if (virAsprintf(&partname, "%s.libvirt-%s", name, drivername) < 0) - goto cleanup; + return false; =20 if (virCgroupPartitionEscape(&partname) < 0) - goto cleanup; + return false; =20 if (machinename && (virAsprintf(&partmachinename, "%s.libvirt-%s", machinename, drivername) < 0 || virCgroupPartitionEscape(&partmachinename) < 0)) - goto cleanup; + return false; =20 if (!(scopename_old =3D virSystemdMakeScopeName(name, drivername, true= ))) - goto cleanup; + return false; =20 /* We should keep trying even if this failed */ if (!machinename) virResetLastError(); else if (!(scopename_new =3D virSystemdMakeScopeName(machinename, drivername, false))) - goto cleanup; + return false; =20 if (virCgroupPartitionEscape(&scopename_old) < 0) - goto cleanup; + return false; =20 if (scopename_new && virCgroupPartitionEscape(&scopename_new) < 0) - goto cleanup; + return false; =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { char *tmp; @@ -303,7 +301,7 @@ virCgroupValidateMachineGroup(virCgroupPtr group, =20 tmp =3D strrchr(group->controllers[i].placement, '/'); if (!tmp) - goto cleanup; + return false; =20 if (stripEmulatorSuffix && (i =3D=3D VIR_CGROUP_CONTROLLER_CPU || @@ -313,7 +311,7 @@ virCgroupValidateMachineGroup(virCgroupPtr group, *tmp =3D '\0'; tmp =3D strrchr(group->controllers[i].placement, '/'); if (!tmp) - goto cleanup; + return false; } =20 tmp++; @@ -329,18 +327,11 @@ virCgroupValidateMachineGroup(virCgroupPtr group, tmp, virCgroupControllerTypeToString(i), name, NULLSTR(machinename), partname, scopename_old, NULLSTR(scopename_new)); - goto cleanup; + return false; } } =20 - valid =3D true; - - cleanup: - VIR_FREE(partmachinename); - VIR_FREE(partname); - VIR_FREE(scopename_old); - VIR_FREE(scopename_new); - return valid; + return true; } =20 =20 @@ -378,7 +369,7 @@ virCgroupDetectMountsFromFile(virCgroupPtr group, FILE *mounts =3D NULL; struct mntent entry; char buf[CGROUP_MAX_VAL]; - char *linksrc =3D NULL; + VIR_AUTOFREE(char *) linksrc =3D NULL; int ret =3D -1; =20 mounts =3D fopen(path, "r"); @@ -468,7 +459,6 @@ virCgroupDetectMountsFromFile(virCgroupPtr group, =20 ret =3D 0; cleanup: - VIR_FREE(linksrc); VIR_FORCE_FCLOSE(mounts); return ret; } @@ -547,7 +537,7 @@ virCgroupDetectPlacement(virCgroupPtr group, FILE *mapping =3D NULL; char line[1024]; int ret =3D -1; - char *procfile; + VIR_AUTOFREE(char *) procfile =3D NULL; =20 VIR_DEBUG("Detecting placement for pid %lld path %s", (long long) pid, path); @@ -628,9 +618,7 @@ virCgroupDetectPlacement(virCgroupPtr group, ret =3D 0; =20 cleanup: - VIR_FREE(procfile); VIR_FORCE_FCLOSE(mapping); - return ret; } =20 @@ -786,8 +774,7 @@ virCgroupSetValueStr(virCgroupPtr group, const char *key, const char *value) { - int ret =3D -1; - char *keypath =3D NULL; + VIR_AUTOFREE(char *) keypath =3D NULL; char *tmp =3D NULL; =20 if (virCgroupPathOfController(group, controller, key, &keypath) < 0) @@ -800,18 +787,14 @@ virCgroupSetValueStr(virCgroupPtr group, virReportSystemError(errno, _("Invalid value '%s' for '%s'"), value, tmp + 1); - goto cleanup; + return -1; } virReportSystemError(errno, _("Unable to write to '%s'"), keypath); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(keypath); - return ret; + return 0; } =20 =20 @@ -821,8 +804,8 @@ virCgroupGetValueStr(virCgroupPtr group, const char *key, char **value) { - char *keypath =3D NULL; - int ret =3D -1, rc; + VIR_AUTOFREE(char *) keypath =3D NULL; + int rc; =20 *value =3D NULL; =20 @@ -834,18 +817,14 @@ virCgroupGetValueStr(virCgroupPtr group, if ((rc =3D virFileReadAll(keypath, 1024*1024, value)) < 0) { virReportSystemError(errno, _("Unable to read from '%s'"), keypath); - goto cleanup; + return -1; } =20 /* Terminated with '\n' has sometimes harmful effects to the caller */ if (rc > 0 && (*value)[rc - 1] =3D=3D '\n') (*value)[rc - 1] =3D '\0'; =20 - ret =3D 0; - - cleanup: - VIR_FREE(keypath); - return ret; + return 0; } =20 =20 @@ -856,8 +835,8 @@ virCgroupGetValueForBlkDev(virCgroupPtr group, const char *path, char **value) { - char *prefix =3D NULL; - char *str =3D NULL; + VIR_AUTOFREE(char *) prefix =3D NULL; + VIR_AUTOFREE(char *) str =3D NULL; char **lines =3D NULL; int ret =3D -1; =20 @@ -875,8 +854,6 @@ virCgroupGetValueForBlkDev(virCgroupPtr group, =20 ret =3D 0; error: - VIR_FREE(str); - VIR_FREE(prefix); virStringListFree(lines); return ret; } @@ -888,17 +865,12 @@ virCgroupSetValueU64(virCgroupPtr group, const char *key, unsigned long long int value) { - char *strval =3D NULL; - int ret; + VIR_AUTOFREE(char *) strval =3D NULL; =20 if (virAsprintf(&strval, "%llu", value) < 0) return -1; =20 - ret =3D virCgroupSetValueStr(group, controller, key, strval); - - VIR_FREE(strval); - - return ret; + return virCgroupSetValueStr(group, controller, key, strval); } =20 =20 @@ -908,17 +880,12 @@ virCgroupSetValueI64(virCgroupPtr group, const char *key, long long int value) { - char *strval =3D NULL; - int ret; + VIR_AUTOFREE(char *) strval =3D NULL; =20 if (virAsprintf(&strval, "%lld", value) < 0) return -1; =20 - ret =3D virCgroupSetValueStr(group, controller, key, strval); - - VIR_FREE(strval); - - return ret; + return virCgroupSetValueStr(group, controller, key, strval); } =20 =20 @@ -928,24 +895,19 @@ virCgroupGetValueI64(virCgroupPtr group, const char *key, long long int *value) { - char *strval =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) strval =3D NULL; =20 if (virCgroupGetValueStr(group, controller, key, &strval) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ll(strval, NULL, 10, value) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), strval); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(strval); - return ret; + return 0; } =20 =20 @@ -955,24 +917,19 @@ virCgroupGetValueU64(virCgroupPtr group, const char *key, unsigned long long int *value) { - char *strval =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) strval =3D NULL; =20 if (virCgroupGetValueStr(group, controller, key, &strval) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ull(strval, NULL, 10, value) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), strval); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(strval); - return ret; + return 0; } =20 =20 @@ -988,7 +945,7 @@ virCgroupCpuSetInherit(virCgroupPtr parent, virCgroupPt= r group) =20 VIR_DEBUG("Setting up inheritance %s -> %s", parent->path, group->path= ); for (i =3D 0; i < ARRAY_CARDINALITY(inherit_values); i++) { - char *value; + VIR_AUTOFREE(char *) value =3D NULL; =20 if (virCgroupGetValueStr(parent, VIR_CGROUP_CONTROLLER_CPUSET, @@ -1001,11 +958,8 @@ virCgroupCpuSetInherit(virCgroupPtr parent, virCgroup= Ptr group) if (virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_CPUSET, inherit_values[i], - value) < 0) { - VIR_FREE(value); + value) < 0) return -1; - } - VIR_FREE(value); } =20 return 0; @@ -1044,11 +998,10 @@ virCgroupMakeGroup(virCgroupPtr parent, unsigned int flags) { size_t i; - int ret =3D -1; =20 VIR_DEBUG("Make group %s", group->path); for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; =20 /* We must never mkdir() in systemd's hierarchy */ if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) { @@ -1074,10 +1027,8 @@ virCgroupMakeGroup(virCgroupPtr parent, if (!virFileExists(path)) { if (!create || mkdir(path, 0755) < 0) { - if (errno =3D=3D EEXIST) { - VIR_FREE(path); + if (errno =3D=3D EEXIST) continue; - } /* With a kernel that doesn't support multi-level directory * for blkio controller, libvirt will fail and disable all * other controllers even though they are available. So @@ -1085,24 +1036,20 @@ virCgroupMakeGroup(virCgroupPtr parent, if (i =3D=3D VIR_CGROUP_CONTROLLER_BLKIO) { VIR_DEBUG("Ignoring mkdir failure with blkio controlle= r. Kernel probably too old"); VIR_FREE(group->controllers[i].mountPoint); - VIR_FREE(path); continue; } else { virReportSystemError(errno, _("Failed to create controller %s= for group"), virCgroupControllerTypeToString(i= )); - VIR_FREE(path); - goto cleanup; + return -1; } } if (group->controllers[VIR_CGROUP_CONTROLLER_CPUSET].mountPoin= t !=3D NULL && (i =3D=3D VIR_CGROUP_CONTROLLER_CPUSET || STREQ(group->controllers[i].mountPoint, group->controllers[VIR_CGROUP_CONTROLLER_CPUSET].mo= untPoint))) { - if (virCgroupCpuSetInherit(parent, group) < 0) { - VIR_FREE(path); - goto cleanup; - } + if (virCgroupCpuSetInherit(parent, group) < 0) + return -1; } /* * Note that virCgroupSetMemoryUseHierarchy should always be @@ -1113,21 +1060,14 @@ virCgroupMakeGroup(virCgroupPtr parent, (i =3D=3D VIR_CGROUP_CONTROLLER_MEMORY || STREQ(group->controllers[i].mountPoint, group->controllers[VIR_CGROUP_CONTROLLER_MEMORY].mo= untPoint))) { - if (virCgroupSetMemoryUseHierarchy(group) < 0) { - VIR_FREE(path); - goto cleanup; - } + if (virCgroupSetMemoryUseHierarchy(group) < 0) + return -1; } } - - VIR_FREE(path); } =20 VIR_DEBUG("Done making controllers for group"); - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -1339,9 +1279,9 @@ virCgroupNewPartition(const char *path, virCgroupPtr *group) { int ret =3D -1; - char *parentPath =3D NULL; + VIR_AUTOFREE(char *) parentPath =3D NULL; virCgroupPtr parent =3D NULL; - char *newPath =3D NULL; + VIR_AUTOFREE(char *) newPath =3D NULL; VIR_DEBUG("path=3D%s create=3D%d controllers=3D%x", path, create, controllers); =20 @@ -1381,8 +1321,6 @@ virCgroupNewPartition(const char *path, if (ret !=3D 0) virCgroupFree(group); virCgroupFree(&parent); - VIR_FREE(parentPath); - VIR_FREE(newPath); return ret; } =20 @@ -1421,18 +1359,17 @@ virCgroupNewDomainPartition(virCgroupPtr partition, bool create, virCgroupPtr *group) { - int ret =3D -1; - char *grpname =3D NULL; + VIR_AUTOFREE(char *)grpname =3D NULL; =20 if (virAsprintf(&grpname, "%s.libvirt-%s", name, driver) < 0) - goto cleanup; + return -1; =20 if (virCgroupPartitionEscape(&grpname) < 0) - goto cleanup; + return -1; =20 if (virCgroupNew(-1, grpname, partition, -1, group) < 0) - goto cleanup; + return -1; =20 /* * Create a cgroup with memory.use_hierarchy enabled to @@ -1448,14 +1385,10 @@ virCgroupNewDomainPartition(virCgroupPtr partition, VIR_CGROUP_MEM_HIERACHY) < 0) { virCgroupRemove(*group); virCgroupFree(group); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(grpname); - return ret; + return 0; } =20 =20 @@ -1477,27 +1410,26 @@ virCgroupNewThread(virCgroupPtr domain, bool create, virCgroupPtr *group) { - int ret =3D -1; - char *name =3D NULL; + VIR_AUTOFREE(char *) name =3D NULL; int controllers; =20 switch (nameval) { case VIR_CGROUP_THREAD_VCPU: if (virAsprintf(&name, "vcpu%d", id) < 0) - goto cleanup; + return -1; break; case VIR_CGROUP_THREAD_EMULATOR: if (VIR_STRDUP(name, "emulator") < 0) - goto cleanup; + return -1; break; case VIR_CGROUP_THREAD_IOTHREAD: if (virAsprintf(&name, "iothread%d", id) < 0) - goto cleanup; + return -1; break; case VIR_CGROUP_THREAD_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected name value %d"), nameval); - goto cleanup; + return -1; } =20 controllers =3D ((1 << VIR_CGROUP_CONTROLLER_CPU) | @@ -1505,18 +1437,15 @@ virCgroupNewThread(virCgroupPtr domain, (1 << VIR_CGROUP_CONTROLLER_CPUSET)); =20 if (virCgroupNew(-1, name, domain, controllers, group) < 0) - goto cleanup; + return -1; =20 if (virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_NONE) < 0) { virCgroupRemove(*group); virCgroupFree(group); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(name); - return ret; + return 0; } =20 =20 @@ -1577,7 +1506,7 @@ virCgroupNewMachineSystemd(const char *name, int ret =3D -1; int rv; virCgroupPtr init, parent =3D NULL; - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; char *offset; =20 VIR_DEBUG("Trying to setup machine '%s' via systemd", name); @@ -1662,7 +1591,6 @@ virCgroupNewMachineSystemd(const char *name, ret =3D 0; cleanup: virCgroupFree(&parent); - VIR_FREE(path); return ret; } =20 @@ -1894,9 +1822,10 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, long long *requests_write) { long long stats_val; - char *str1 =3D NULL, *str2 =3D NULL, *p1, *p2; + VIR_AUTOFREE(char *) str1 =3D NULL; + VIR_AUTOFREE(char *) str2 =3D NULL; + char *p1, *p2; size_t i; - int ret =3D -1; =20 const char *value_names[] =3D { "Read ", @@ -1919,12 +1848,12 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.io_service_bytes", &str1) < 0) - goto cleanup; + return -1; =20 if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.io_serviced", &str2) < 0) - goto cleanup; + return -1; =20 /* sum up all entries of the same kind, from all devices */ for (i =3D 0; i < ARRAY_CARDINALITY(value_names); i++) { @@ -1938,7 +1867,7 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, _("Cannot parse byte %sstat '%s'"), value_names[i], p1); - goto cleanup; + return -1; } =20 if (stats_val < 0 || @@ -1947,7 +1876,7 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, virReportError(VIR_ERR_OVERFLOW, _("Sum of byte %sstat overflows"), value_names[i]); - goto cleanup; + return -1; } *bytes_ptrs[i] +=3D stats_val; } @@ -1959,7 +1888,7 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, _("Cannot parse %srequest stat '%s'"), value_names[i], p2); - goto cleanup; + return -1; } =20 if (stats_val < 0 || @@ -1968,18 +1897,13 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, virReportError(VIR_ERR_OVERFLOW, _("Sum of %srequest stat overflows"), value_names[i]); - goto cleanup; + return -1; } *requests_ptrs[i] +=3D stats_val; } } =20 - ret =3D 0; - - cleanup: - VIR_FREE(str2); - VIR_FREE(str1); - return ret; + return 0; } =20 =20 @@ -2003,9 +1927,11 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group, long long *requests_read, long long *requests_write) { - char *str1 =3D NULL, *str2 =3D NULL, *str3 =3D NULL, *p1, *p2; + VIR_AUTOFREE(char *) str1 =3D NULL; + VIR_AUTOFREE(char *) str2 =3D NULL; + VIR_AUTOFREE(char *) str3 =3D NULL; + char *p1, *p2; size_t i; - int ret =3D -1; =20 const char *value_names[] =3D { "Read ", @@ -2023,28 +1949,28 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr grou= p, if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.io_service_bytes", &str1) < 0) - goto cleanup; + return -1; =20 if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.io_serviced", &str2) < 0) - goto cleanup; + return -1; =20 if (!(str3 =3D virCgroupGetBlockDevString(path))) - goto cleanup; + return -1; =20 if (!(p1 =3D strstr(str1, str3))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find byte stats for block device '%s'"), str3); - goto cleanup; + return -1; } =20 if (!(p2 =3D strstr(str2, str3))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find request stats for block device '%s'"= ), str3); - goto cleanup; + return -1; } =20 for (i =3D 0; i < ARRAY_CARDINALITY(value_names); i++) { @@ -2052,38 +1978,32 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr grou= p, virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find byte %sstats for block device '%= s'"), value_names[i], str3); - goto cleanup; + return -1; } =20 if (virStrToLong_ll(p1 + strlen(value_names[i]), &p1, 10, bytes_pt= rs[i]) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot parse %sstat '%s'"), value_names[i], p1 + strlen(value_names[i])); - goto cleanup; + return -1; } =20 if (!(p2 =3D strstr(p2, value_names[i]))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find request %sstats for block device= '%s'"), value_names[i], str3); - goto cleanup; + return -1; } =20 if (virStrToLong_ll(p2 + strlen(value_names[i]), &p2, 10, requests= _ptrs[i]) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot parse %sstat '%s'"), value_names[i], p2 + strlen(value_names[i])); - goto cleanup; + return -1; } } =20 - ret =3D 0; - - cleanup: - VIR_FREE(str3); - VIR_FREE(str2); - VIR_FREE(str1); - return ret; + return 0; } =20 =20 @@ -2139,24 +2059,19 @@ virCgroupSetBlkioDeviceReadIops(virCgroupPtr group, const char *path, unsigned int riops) { - char *str =3D NULL; - char *blkstr =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; =20 if (!(blkstr =3D virCgroupGetBlockDevString(path))) return -1; =20 if (virAsprintf(&str, "%s%u", blkstr, riops) < 0) - goto error; + return -1; =20 - ret =3D virCgroupSetValueStr(group, + return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.read_iops_device", str); - error: - VIR_FREE(blkstr); - VIR_FREE(str); - return ret; } =20 =20 @@ -2173,24 +2088,19 @@ virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group, const char *path, unsigned int wiops) { - char *str =3D NULL; - char *blkstr =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; =20 if (!(blkstr =3D virCgroupGetBlockDevString(path))) return -1; =20 if (virAsprintf(&str, "%s%u", blkstr, wiops) < 0) - goto error; + return -1; =20 - ret =3D virCgroupSetValueStr(group, + return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.write_iops_device", str); - error: - VIR_FREE(blkstr); - VIR_FREE(str); - return ret; } =20 =20 @@ -2207,24 +2117,19 @@ virCgroupSetBlkioDeviceReadBps(virCgroupPtr group, const char *path, unsigned long long rbps) { - char *str =3D NULL; - char *blkstr =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; =20 if (!(blkstr =3D virCgroupGetBlockDevString(path))) return -1; =20 if (virAsprintf(&str, "%s%llu", blkstr, rbps) < 0) - goto error; + return -1; =20 - ret =3D virCgroupSetValueStr(group, + return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.read_bps_device", str); - error: - VIR_FREE(blkstr); - VIR_FREE(str); - return ret; } =20 /** @@ -2240,24 +2145,19 @@ virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long wbps) { - char *str =3D NULL; - char *blkstr =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; =20 if (!(blkstr =3D virCgroupGetBlockDevString(path))) return -1; =20 if (virAsprintf(&str, "%s%llu", blkstr, wbps) < 0) - goto error; + return -1; =20 - ret =3D virCgroupSetValueStr(group, + return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.write_bps_device", str); - error: - VIR_FREE(blkstr); - VIR_FREE(str); - return ret; } =20 =20 @@ -2275,24 +2175,19 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group, const char *path, unsigned int weight) { - char *str =3D NULL; - char *blkstr =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; =20 if (!(blkstr =3D virCgroupGetBlockDevString(path))) return -1; =20 if (virAsprintf(&str, "%s%d", blkstr, weight) < 0) - goto error; + return -1; =20 - ret =3D virCgroupSetValueStr(group, + return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.weight_device", str); - error: - VIR_FREE(blkstr); - VIR_FREE(str); - return ret; } =20 /** @@ -2308,15 +2203,14 @@ virCgroupGetBlkioDeviceReadIops(virCgroupPtr group, const char *path, unsigned int *riops) { - char *str =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; =20 if (virCgroupGetValueForBlkDev(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.read_iops_device", path, &str) < 0) - goto error; + return -1; =20 if (!str) { *riops =3D 0; @@ -2324,13 +2218,10 @@ virCgroupGetBlkioDeviceReadIops(virCgroupPtr group, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); - goto error; + return -1; } =20 - ret =3D 0; - error: - VIR_FREE(str); - return ret; + return 0; } =20 /** @@ -2346,15 +2237,14 @@ virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group, const char *path, unsigned int *wiops) { - char *str =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; =20 if (virCgroupGetValueForBlkDev(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.write_iops_device", path, &str) < 0) - goto error; + return -1; =20 if (!str) { *wiops =3D 0; @@ -2362,13 +2252,10 @@ virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); - goto error; + return -1; } =20 - ret =3D 0; - error: - VIR_FREE(str); - return ret; + return 0; } =20 /** @@ -2384,15 +2271,14 @@ virCgroupGetBlkioDeviceReadBps(virCgroupPtr group, const char *path, unsigned long long *rbps) { - char *str =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; =20 if (virCgroupGetValueForBlkDev(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.read_bps_device", path, &str) < 0) - goto error; + return -1; =20 if (!str) { *rbps =3D 0; @@ -2400,13 +2286,10 @@ virCgroupGetBlkioDeviceReadBps(virCgroupPtr group, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); - goto error; + return -1; } =20 - ret =3D 0; - error: - VIR_FREE(str); - return ret; + return 0; } =20 /** @@ -2422,15 +2305,14 @@ virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long *wbps) { - char *str =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; =20 if (virCgroupGetValueForBlkDev(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.write_bps_device", path, &str) < 0) - goto error; + return -1; =20 if (!str) { *wbps =3D 0; @@ -2438,13 +2320,10 @@ virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); - goto error; + return -1; } =20 - ret =3D 0; - error: - VIR_FREE(str); - return ret; + return 0; } =20 /** @@ -2460,15 +2339,14 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group, const char *path, unsigned int *weight) { - char *str =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; =20 if (virCgroupGetValueForBlkDev(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.weight_device", path, &str) < 0) - goto error; + return -1; =20 if (!str) { *weight =3D 0; @@ -2476,13 +2354,10 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); - goto error; + return -1; } =20 - ret =3D 0; - error: - VIR_FREE(str); - return ret; + return 0; } =20 =20 @@ -2941,36 +2816,29 @@ int virCgroupAllowDevice(virCgroupPtr group, char type, int major, int minor, int perms) { - int ret =3D -1; - char *devstr =3D NULL; - char *majorstr =3D NULL; - char *minorstr =3D NULL; + VIR_AUTOFREE(char *) devstr =3D NULL; + VIR_AUTOFREE(char *) majorstr =3D NULL; + VIR_AUTOFREE(char *) minorstr =3D NULL; =20 if ((major < 0 && VIR_STRDUP(majorstr, "*") < 0) || (major >=3D 0 && virAsprintf(&majorstr, "%i", major) < 0)) - goto cleanup; + return -1; =20 if ((minor < 0 && VIR_STRDUP(minorstr, "*") < 0) || (minor >=3D 0 && virAsprintf(&minorstr, "%i", minor) < 0)) - goto cleanup; + return -1; =20 if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr, virCgroupGetDevicePermsString(perms)) < 0) - goto cleanup; + return -1; =20 if (virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_DEVICES, "devices.allow", devstr) < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(devstr); - VIR_FREE(majorstr); - VIR_FREE(minorstr); - return ret; + return 0; } =20 =20 @@ -3032,36 +2900,29 @@ int virCgroupDenyDevice(virCgroupPtr group, char type, int major, int minor, int perms) { - int ret =3D -1; - char *devstr =3D NULL; - char *majorstr =3D NULL; - char *minorstr =3D NULL; + VIR_AUTOFREE(char *) devstr =3D NULL; + VIR_AUTOFREE(char *) majorstr =3D NULL; + VIR_AUTOFREE(char *) minorstr =3D NULL; =20 if ((major < 0 && VIR_STRDUP(majorstr, "*") < 0) || (major >=3D 0 && virAsprintf(&majorstr, "%i", major) < 0)) - goto cleanup; + return -1; =20 if ((minor < 0 && VIR_STRDUP(minorstr, "*") < 0) || (minor >=3D 0 && virAsprintf(&minorstr, "%i", minor) < 0)) - goto cleanup; + return -1; =20 if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr, virCgroupGetDevicePermsString(perms)) < 0) - goto cleanup; + return -1; =20 if (virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_DEVICES, "devices.deny", devstr) < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(devstr); - VIR_FREE(majorstr); - VIR_FREE(minorstr); - return ret; + return 0; } =20 =20 @@ -3131,10 +2992,10 @@ virCgroupGetPercpuVcpuSum(virCgroupPtr group, { int ret =3D -1; ssize_t i =3D -1; - char *buf =3D NULL; virCgroupPtr group_vcpu =3D NULL; =20 while ((i =3D virBitmapNextSetBit(guestvcpus, i)) >=3D 0) { + VIR_AUTOFREE(char *) buf =3D NULL; char *pos; unsigned long long tmp; ssize_t j; @@ -3159,13 +3020,11 @@ virCgroupGetPercpuVcpuSum(virCgroupPtr group, } =20 virCgroupFree(&group_vcpu); - VIR_FREE(buf); } =20 ret =3D 0; cleanup: virCgroupFree(&group_vcpu); - VIR_FREE(buf); return ret; } =20 @@ -3202,8 +3061,8 @@ virCgroupGetPercpuStats(virCgroupPtr group, size_t i; int need_cpus, total_cpus; char *pos; - char *buf =3D NULL; - unsigned long long *sum_cpu_time =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOFREE(unsigned long long *) sum_cpu_time =3D NULL; virTypedParameterPtr ent; int param_idx; unsigned long long cpu_time; @@ -3289,8 +3148,6 @@ virCgroupGetPercpuStats(virCgroupPtr group, =20 cleanup: virBitmapFree(cpumap); - VIR_FREE(sum_cpu_time); - VIR_FREE(buf); return ret; } =20 @@ -3461,7 +3318,7 @@ virCgroupRemoveRecursively(char *grppath) /* This is best-effort cleanup: we want to log failures with just * VIR_ERROR instead of normal virReportError */ while ((direrr =3D virDirRead(grpdir, &ent, NULL)) > 0) { - char *path; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (ent->d_type !=3D DT_DIR) continue; =20 @@ -3470,7 +3327,6 @@ virCgroupRemoveRecursively(char *grppath) break; } rc =3D virCgroupRemoveRecursively(path); - VIR_FREE(path); if (rc !=3D 0) break; } @@ -3508,10 +3364,11 @@ virCgroupRemove(virCgroupPtr group) { int rc =3D 0; size_t i; - char *grppath =3D NULL; =20 VIR_DEBUG("Removing cgroup %s", group->path); for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + VIR_AUTOFREE(char *) grppath =3D NULL; + /* Skip over controllers not mounted */ if (!group->controllers[i].mountPoint) continue; @@ -3533,7 +3390,6 @@ virCgroupRemove(virCgroupPtr group) =20 VIR_DEBUG("Removing cgroup %s and all child cgroups", grppath); rc =3D virCgroupRemoveRecursively(grppath); - VIR_FREE(grppath); } VIR_DEBUG("Done removing cgroup %s", group->path); =20 @@ -3549,7 +3405,7 @@ virCgroupKillInternal(virCgroupPtr group, int signum,= virHashTablePtr pids) { int ret =3D -1; bool killedAny =3D false; - char *keypath =3D NULL; + VIR_AUTOFREE(char *) keypath =3D NULL; bool done =3D false; FILE *fp =3D NULL; VIR_DEBUG("group=3D%p path=3D%s signum=3D%d pids=3D%p", @@ -3613,7 +3469,6 @@ virCgroupKillInternal(virCgroupPtr group, int signum,= virHashTablePtr pids) ret =3D killedAny ? 1 : 0; =20 cleanup: - VIR_FREE(keypath); VIR_FORCE_FCLOSE(fp); =20 return ret; @@ -3678,7 +3533,7 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, int ret =3D -1; int rc; bool killedAny =3D false; - char *keypath =3D NULL; + VIR_AUTOFREE(char *) keypath =3D NULL; DIR *dp =3D NULL; virCgroupPtr subgroup =3D NULL; struct dirent *ent; @@ -3732,7 +3587,6 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, =20 cleanup: virCgroupFree(&subgroup); - VIR_FREE(keypath); VIR_DIR_CLOSE(dp); return ret; } @@ -3846,9 +3700,8 @@ int virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user, unsigned long long *sys) { - char *str; + VIR_AUTOFREE(char *) str =3D NULL; char *p; - int ret =3D -1; static double scale =3D -1.0; =20 if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT, @@ -3860,14 +3713,14 @@ virCgroupGetCpuacctStat(virCgroupPtr group, unsigne= d long long *user, virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot parse user stat '%s'"), p); - goto cleanup; + return -1; } if (!(p =3D STRSKIP(p, "\nsystem ")) || virStrToLong_ull(p, NULL, 10, sys) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot parse sys stat '%s'"), p); - goto cleanup; + return -1; } /* times reported are in system ticks (generally 100 Hz), but that * rate can theoretically vary between machines. Scale things @@ -3877,17 +3730,14 @@ virCgroupGetCpuacctStat(virCgroupPtr group, unsigne= d long long *user, if (ticks_per_sec =3D=3D -1) { virReportSystemError(errno, "%s", _("Cannot determine system clock HZ")); - goto cleanup; + return -1; } scale =3D 1000000000.0 / ticks_per_sec; } *user *=3D scale; *sys *=3D scale; =20 - ret =3D 0; - cleanup: - VIR_FREE(str); - return ret; + return 0; } =20 =20 @@ -3913,10 +3763,9 @@ int virCgroupBindMount(virCgroupPtr group, const char *oldroot, const char *mountopts) { - int ret =3D -1; size_t i; - char *opts =3D NULL; - char *root =3D NULL; + VIR_AUTOFREE(char *) opts =3D NULL; + VIR_AUTOFREE(char *) root =3D NULL; =20 if (!(root =3D virCgroupIdentifyRoot(group))) return -1; @@ -3927,18 +3776,18 @@ virCgroupBindMount(virCgroupPtr group, const char *= oldroot, virReportSystemError(errno, _("Unable to create directory %s"), root); - goto cleanup; + return -1; } =20 if (virAsprintf(&opts, "mode=3D755,size=3D65536%s", mountopts) < 0) - goto cleanup; + return -1; =20 if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) = < 0) { virReportSystemError(errno, _("Failed to mount %s on %s type %s"), "tmpfs", root, "tmpfs"); - goto cleanup; + return -1; } =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { @@ -3946,11 +3795,11 @@ virCgroupBindMount(virCgroupPtr group, const char *= oldroot, continue; =20 if (!virFileExists(group->controllers[i].mountPoint)) { - char *src; + VIR_AUTOFREE(char *) src =3D NULL; if (virAsprintf(&src, "%s%s", oldroot, group->controllers[i].mountPoint) < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Create mount point '%s'", group->controllers[i].mountPoint); @@ -3958,8 +3807,7 @@ virCgroupBindMount(virCgroupPtr group, const char *ol= droot, virReportSystemError(errno, _("Unable to create directory %s"), group->controllers[i].mountPoint); - VIR_FREE(src); - goto cleanup; + return -1; } =20 if (mount(src, group->controllers[i].mountPoint, NULL, MS_BIND, @@ -3967,11 +3815,8 @@ virCgroupBindMount(virCgroupPtr group, const char *o= ldroot, virReportSystemError(errno, _("Failed to bind cgroup '%s' on '%s'= "), src, group->controllers[i].mountPoint= ); - VIR_FREE(src); - goto cleanup; + return -1; } - - VIR_FREE(src); } =20 if (group->controllers[i].linkPoint) { @@ -3984,16 +3829,12 @@ virCgroupBindMount(virCgroupPtr group, const char *= oldroot, _("Unable to symlink directory %s to = %s"), group->controllers[i].mountPoint, group->controllers[i].linkPoint); - goto cleanup; + return -1; } } } - ret =3D 0; =20 - cleanup: - VIR_FREE(root); - VIR_FREE(opts); - return ret; + return 0; } =20 =20 @@ -4004,11 +3845,11 @@ int virCgroupSetOwner(virCgroupPtr cgroup, { int ret =3D -1; size_t i; - char *base =3D NULL, *entry =3D NULL; DIR *dh =3D NULL; int direrr; =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + VIR_AUTOFREE(char *) base =3D NULL; struct dirent *de; =20 if (!((1 << i) & controllers)) @@ -4025,6 +3866,8 @@ int virCgroupSetOwner(virCgroupPtr cgroup, goto cleanup; =20 while ((direrr =3D virDirRead(dh, &de, base)) > 0) { + VIR_AUTOFREE(char *) entry =3D NULL; + if (virAsprintf(&entry, "%s/%s", base, de->d_name) < 0) goto cleanup; =20 @@ -4034,8 +3877,6 @@ int virCgroupSetOwner(virCgroupPtr cgroup, entry, uid, gid); goto cleanup; } - - VIR_FREE(entry); } if (direrr < 0) goto cleanup; @@ -4047,7 +3888,6 @@ int virCgroupSetOwner(virCgroupPtr cgroup, goto cleanup; } =20 - VIR_FREE(base); VIR_DIR_CLOSE(dh); } =20 @@ -4055,8 +3895,6 @@ int virCgroupSetOwner(virCgroupPtr cgroup, =20 cleanup: VIR_DIR_CLOSE(dh); - VIR_FREE(entry); - VIR_FREE(base); return ret; } =20 @@ -4071,8 +3909,7 @@ int virCgroupSetOwner(virCgroupPtr cgroup, bool virCgroupSupportsCpuBW(virCgroupPtr cgroup) { - char *path =3D NULL; - bool ret =3D false; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (!cgroup) return false; @@ -4080,21 +3917,17 @@ virCgroupSupportsCpuBW(virCgroupPtr cgroup) if (virCgroupPathOfController(cgroup, VIR_CGROUP_CONTROLLER_CPU, "cpu.cfs_period_us", &path) < 0) { virResetLastError(); - goto cleanup; + return false; } =20 - ret =3D virFileExists(path); - - cleanup: - VIR_FREE(path); - return ret; + return virFileExists(path); } =20 int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller) { - int ret =3D -1; - char *content =3D NULL; + int ret; + VIR_AUTOFREE(char *) content =3D NULL; =20 if (!cgroup) return -1; @@ -4104,7 +3937,6 @@ virCgroupHasEmptyTasks(virCgroupPtr cgroup, int contr= oller) if (ret =3D=3D 0 && content[0] =3D=3D '\0') ret =3D 1; =20 - VIR_FREE(content); 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 Fri May 3 19:08:29 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 1528124235030485.21524830938233; Mon, 4 Jun 2018 07:57:15 -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 7AAA53184409; Mon, 4 Jun 2018 14:57: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 9A1562010CC7; Mon, 4 Jun 2018 14:57: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 77E091804480; Mon, 4 Jun 2018 14:57:07 +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 w54Easf5008130 for ; Mon, 4 Jun 2018 10:36:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 41EB98B327; Mon, 4 Jun 2018 14:36:54 +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 3ABB99BA51 for ; Mon, 4 Jun 2018 14:36:54 +0000 (UTC) Received: from mail-pl0-f66.google.com (mail-pl0-f66.google.com [209.85.160.66]) (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 9BEA3169380 for ; Mon, 4 Jun 2018 14:36:42 +0000 (UTC) Received: by mail-pl0-f66.google.com with SMTP id n10-v6so19840721plp.0 for ; Mon, 04 Jun 2018 07:36:42 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36:41 -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=pX9ItnH7XnkncjcyWfiDUOGBUi396SMT1pekT5X9KH4=; b=MUAuD91EgK1jBbbAxX1S6bJU8IVOhv41mIXib7hqaXL4FsM7Xq+Ply+nNk4/4kr9aM wiLX0N3Ey6oubKsury38ZXM9ANGnaevAbdDPul2JDrE9KDVTET9NImVhXco4NXm4bzRQ BBncop4ExSu4EkMdd+lb5LhHmqWxL/aILe1Dcp6ApXy2yuPZVRwYJRl2h4JgSUOQDS8f 8vCv1kM+NYoCWPA+8Qulz+XWUlQv0GIpIMz+SlQMguq38S9VSYstKuu5D9Kf7cQz9wYS cCulRjUbW77gq/yQdyn9dhjXi8nXP/KLt4gk7rq+MOoikGx0AcR9KK4k2hdS1YzwYP6a YBeQ== 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=pX9ItnH7XnkncjcyWfiDUOGBUi396SMT1pekT5X9KH4=; b=tAUc8aVDHb1F8MNbKQTrSM/N/yl5v8D4g0+Xuo639ncoyttSoNSD1f3YjABzr3oUA9 +cBShzmf6b6y1ORK1l6I0mCs4vlfiRBoCWfcIDQ4f79RoPcwkT1vOEeBnlI4ZwY6kbZ7 qPYskOWXoNdxApfBwq9MIQ8ZgFOBfbDl1dbV0fyzP/9dKB1S4tMO/aZcadLYA0cwwPVQ 2xQO9yHQ45WQPVAiO7ckLvvMkMJrcapL1q1+z8PPuHbIz7Gcm/KeRmkA5jhIO+eQMvXn Q0QU/Wk4BtmaAyvwBLPeYB0g/AcNdAbXsonOAqnhtxJ35Q6s2TvZ9+d7hB/Du1hSYDeq kCfg== X-Gm-Message-State: APt69E1Mcdf/k9IMYopcxmBbMjuvFg64XDnhl1ZuzJdfpejq9yz+5Dvq 1zuQY/+Z/x6CyKx9/zfZW/OcmeJt X-Google-Smtp-Source: ADUXVKIWDSHJ0brSJSXpRaJbOniRjA0FHNBkmucOaYm+QQbgn1fG3Nv6NbJ/t1Ymu0z9INawtUB4DA== X-Received: by 2002:a17:902:2869:: with SMTP id e96-v6mr8760818plb.58.1528123001812; Mon, 04 Jun 2018 07:36:41 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:07 +0530 Message-Id: <1528013536-22196-10-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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]); Mon, 04 Jun 2018 14:36:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 04 Jun 2018 14:36:42 +0000 (UTC) for IP:'209.85.160.66' DOMAIN:'mail-pl0-f66.google.com' HELO:'mail-pl0-f66.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.766 * (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.160.66 mail-pl0-f66.google.com 209.85.160.66 mail-pl0-f66.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 09/18] use VIR_AUTOFREE in src/util/virfcp.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.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 04 Jun 2018 14: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" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- 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; - - ret =3D 0; + return -1; =20 - 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 Fri May 3 19:08:29 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 1528124583002443.45959350471344; Mon, 4 Jun 2018 08:03:03 -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 32281DCA39; Mon, 4 Jun 2018 15:03:00 +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 6180227081; Mon, 4 Jun 2018 15:02:59 +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 667CE1800FC1; Mon, 4 Jun 2018 15:02:58 +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 w54EauX9008148 for ; Mon, 4 Jun 2018 10:36:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id E0E485C8AB; Mon, 4 Jun 2018 14:36:56 +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 D4F535C8AA for ; Mon, 4 Jun 2018 14:36:56 +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 D770BD818D for ; Mon, 4 Jun 2018 14:36:44 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id i5-v6so19842197plt.2 for ; Mon, 04 Jun 2018 07:36:44 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36:43 -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=XEGuHtOkhQTUYkLG6m9ILG8TY8RfpxK231Ie4XGS5R8=; b=N0JZcmpD4u7Tc99aXKnKkamMB5j0BNXzWRuppm9wX8o8aL02exSnWNHXXHJiH6m+HM bW67MbtS6faj16mcv16Rpwq0IUVtMQ4fBHTJHlJT+QXgqv/QRxr4ctK4Xdv2bQK6QmnH zV/orgTviLOxdN94ll/SbLBwkVvhZrVNnhxSGnTpFOSNeBrWTSYPsAZ7UD4PTn/7S/bR Eu5DFmHPBZpH4T26aeYUCkmaOo90Wn3kS8PjjHouneO7Wxf3C5Ft4KGQGGz6xDyRUrnl +r5nWph1rOiTh4/XXp8++XxD/coU0VhdP7flElRSXTfLSuhgVitnwD4Dxv9U5OgMekke 8EKw== 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=XEGuHtOkhQTUYkLG6m9ILG8TY8RfpxK231Ie4XGS5R8=; b=ieTkU/s3OH/HywWKfFDHoXk0zkyGEdX1/gkJC+xM2HrF0bxcYbDSFtduKCYVMV4VU8 G5/H/Cw5etH4ARRe2iaAho+gdnUiUnnTzuPx/Xw/X7rZgfcWpLppM1JZ7n1+4+r6LKhh Lrw3RL4IT3jmOLFKwFnrGp7TDv+Tn7nd7blLlg7bE3X8FhHrrBJluiR6uEwbQobm0lRJ qrPflIcQ48ytLy0jQaeCgK9dF5cztvt5WEcOgIOHKeH2FN/AqD/wVfvodlllHgzkmKVC CyPrKTzTiD/2aGerAjVTwARd6Sf6ehnhVnWU0oFVGX55mBJ0qEm4Ep1O+RxOCjamzmqV iP5g== X-Gm-Message-State: APt69E31b8Ix0FoRS3YLCe0SRfgPRpuV0k14vTFi/l40zE2YXGFru9Ko S1IVUaGgofZrlL5cjgE2IWPX4ihZ X-Google-Smtp-Source: ADUXVKI9Qa1uTHsT6dMyQ7AMxhYe4sAdtk7V1bNOTyzhepWZVlkV6suHoLB0riGFctW8JY1wq6Xdag== X-Received: by 2002:a17:902:854a:: with SMTP id d10-v6mr12146733plo.106.1528123003943; Mon, 04 Jun 2018 07:36:43 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:08 +0530 Message-Id: <1528013536-22196-11-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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]); Mon, 04 Jun 2018 14:36:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 04 Jun 2018 14:36:45 +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.766 * (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.160.68 mail-pl0-f68.google.com 209.85.160.68 mail-pl0-f68.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 10/18] use VIR_AUTOFREE in src/util/virdnsmasq.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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 04 Jun 2018 15:03:01 +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" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- src/util/virdnsmasq.c | 116 +++++++++++++++++-----------------------------= ---- 1 file changed, 39 insertions(+), 77 deletions(-) diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index 492dcad..c806cd2 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -95,7 +95,7 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile, virSocketAddr *ip, const char *name) { - char *ipstr =3D NULL; + VIR_AUTOFREE(char *) ipstr =3D NULL; int idx =3D -1; size_t i; =20 @@ -111,35 +111,29 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile, =20 if (idx < 0) { if (VIR_REALLOC_N(addnhostsfile->hosts, addnhostsfile->nhosts + 1)= < 0) - goto error; + return -1; =20 idx =3D addnhostsfile->nhosts; if (VIR_ALLOC(addnhostsfile->hosts[idx].hostnames) < 0) - goto error; + return -1; =20 if (VIR_STRDUP(addnhostsfile->hosts[idx].ip, ipstr) < 0) - goto error; + return -1; =20 addnhostsfile->hosts[idx].nhostnames =3D 0; addnhostsfile->nhosts++; } =20 if (VIR_REALLOC_N(addnhostsfile->hosts[idx].hostnames, addnhostsfile->= hosts[idx].nhostnames + 1) < 0) - goto error; + return -1; =20 if (VIR_STRDUP(addnhostsfile->hosts[idx].hostnames[addnhostsfile->host= s[idx].nhostnames], name) < 0) - goto error; - - VIR_FREE(ipstr); + return -1; =20 addnhostsfile->hosts[idx].nhostnames++; =20 return 0; - - error: - VIR_FREE(ipstr); - return -1; } =20 static dnsmasqAddnHostsfile * @@ -178,11 +172,10 @@ addnhostsWrite(const char *path, dnsmasqAddnHost *hosts, unsigned int nhosts) { - char *tmp; + VIR_AUTOFREE(char *) tmp =3D NULL; FILE *f; bool istmp =3D true; size_t i, j; - int rc =3D 0; =20 /* even if there are 0 hosts, create a 0 length file, to allow * for runtime addition. @@ -193,61 +186,50 @@ addnhostsWrite(const char *path, =20 if (!(f =3D fopen(tmp, "w"))) { istmp =3D false; - if (!(f =3D fopen(path, "w"))) { - rc =3D -errno; - goto cleanup; - } + if (!(f =3D fopen(path, "w"))) + return -errno; } =20 for (i =3D 0; i < nhosts; i++) { if (fputs(hosts[i].ip, f) =3D=3D EOF || fputc('\t', f) =3D=3D EOF)= { - rc =3D -errno; VIR_FORCE_FCLOSE(f); =20 if (istmp) unlink(tmp); =20 - goto cleanup; + return -errno; } =20 for (j =3D 0; j < hosts[i].nhostnames; j++) { if (fputs(hosts[i].hostnames[j], f) =3D=3D EOF || fputc('\t', = f) =3D=3D EOF) { - rc =3D -errno; VIR_FORCE_FCLOSE(f); =20 if (istmp) unlink(tmp); =20 - goto cleanup; + return -errno; } } =20 if (fputc('\n', f) =3D=3D EOF) { - rc =3D -errno; VIR_FORCE_FCLOSE(f); =20 if (istmp) unlink(tmp); =20 - goto cleanup; + return -errno; } } =20 - if (VIR_FCLOSE(f) =3D=3D EOF) { - rc =3D -errno; - goto cleanup; - } + if (VIR_FCLOSE(f) =3D=3D EOF) + return -errno; =20 if (istmp && rename(tmp, path) < 0) { - rc =3D -errno; unlink(tmp); - goto cleanup; + return -errno; } =20 - cleanup: - VIR_FREE(tmp); - - return rc; + return 0; } =20 static int @@ -310,9 +292,10 @@ hostsfileAdd(dnsmasqHostsfile *hostsfile, const char *id, bool ipv6) { - char *ipstr =3D NULL; + VIR_AUTOFREE(char *) ipstr =3D NULL; + if (VIR_REALLOC_N(hostsfile->hosts, hostsfile->nhosts + 1) < 0) - goto error; + return -1; =20 if (!(ipstr =3D virSocketAddrFormat(ip))) return -1; @@ -322,38 +305,33 @@ hostsfileAdd(dnsmasqHostsfile *hostsfile, if (name && id) { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "id:%s,%s,[%s]", id, name, ipstr) < 0) - goto error; + return -1; } else if (name && !id) { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,[%s]", name, ipstr) < 0) - goto error; + return -1; } else if (!name && id) { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "id:%s,[%s]", id, ipstr) < 0) - goto error; + return -1; } } else if (name && mac) { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s,= %s", mac, ipstr, name) < 0) - goto error; + return -1; } else if (name && !mac) { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s", name, ipstr) < 0) - goto error; + return -1; } else { if (virAsprintf(&hostsfile->hosts[hostsfile->nhosts].host, "%s,%s", mac, ipstr) < 0) - goto error; + return -1; } - VIR_FREE(ipstr); =20 hostsfile->nhosts++; =20 return 0; - - error: - VIR_FREE(ipstr); - return -1; } =20 static dnsmasqHostsfile * @@ -391,11 +369,10 @@ hostsfileWrite(const char *path, dnsmasqDhcpHost *hosts, unsigned int nhosts) { - char *tmp; + VIR_AUTOFREE(char *) tmp =3D NULL; FILE *f; bool istmp =3D true; size_t i; - int rc =3D 0; =20 /* even if there are 0 hosts, create a 0 length file, to allow * for runtime addition. @@ -406,39 +383,30 @@ hostsfileWrite(const char *path, =20 if (!(f =3D fopen(tmp, "w"))) { istmp =3D false; - if (!(f =3D fopen(path, "w"))) { - rc =3D -errno; - goto cleanup; - } + if (!(f =3D fopen(path, "w"))) + return -errno; } =20 for (i =3D 0; i < nhosts; i++) { if (fputs(hosts[i].host, f) =3D=3D EOF || fputc('\n', f) =3D=3D EO= F) { - rc =3D -errno; VIR_FORCE_FCLOSE(f); =20 if (istmp) unlink(tmp); =20 - goto cleanup; + return -errno; } } =20 - if (VIR_FCLOSE(f) =3D=3D EOF) { - rc =3D -errno; - goto cleanup; - } + if (VIR_FCLOSE(f) =3D=3D EOF) + return -errno; =20 if (istmp && rename(tmp, path) < 0) { - rc =3D -errno; unlink(tmp); - goto cleanup; + return -errno; } =20 - cleanup: - VIR_FREE(tmp); - - return rc; + return 0; } =20 static int @@ -708,17 +676,12 @@ dnsmasqCapsSetFromBuffer(dnsmasqCapsPtr caps, const c= har *buf) static int dnsmasqCapsSetFromFile(dnsmasqCapsPtr caps, const char *path) { - int ret =3D -1; - char *buf =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; =20 if (virFileReadAll(path, 1024 * 1024, &buf) < 0) - goto cleanup; - - ret =3D dnsmasqCapsSetFromBuffer(caps, buf); + return -1; =20 - cleanup: - VIR_FREE(buf); - return ret; + return dnsmasqCapsSetFromBuffer(caps, buf); } =20 static int @@ -727,7 +690,9 @@ dnsmasqCapsRefreshInternal(dnsmasqCapsPtr caps, bool fo= rce) int ret =3D -1; struct stat sb; virCommandPtr cmd =3D NULL; - char *help =3D NULL, *version =3D NULL, *complete =3D NULL; + VIR_AUTOFREE(char *) help =3D NULL; + VIR_AUTOFREE(char *) version =3D NULL; + VIR_AUTOFREE(char *) complete =3D NULL; =20 if (!caps || caps->noRefresh) return 0; @@ -779,9 +744,6 @@ dnsmasqCapsRefreshInternal(dnsmasqCapsPtr caps, bool fo= rce) =20 cleanup: virCommandFree(cmd); - VIR_FREE(help); - VIR_FREE(version); - VIR_FREE(complete); 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 Fri May 3 19:08:29 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 1528124716508186.80296440401207; Mon, 4 Jun 2018 08:05:16 -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 DA8B730C4ACF; Mon, 4 Jun 2018 15:05:14 +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 693B52010CD1; Mon, 4 Jun 2018 15:05:14 +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 EBE051800FD9; Mon, 4 Jun 2018 15:05:13 +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 w54Eaw7D008164 for ; Mon, 4 Jun 2018 10:36:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id D36D45C8AB; Mon, 4 Jun 2018 14:36:58 +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 CB74B17AF9 for ; Mon, 4 Jun 2018 14:36:58 +0000 (UTC) Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F007B3002A0F for ; Mon, 4 Jun 2018 14:36:46 +0000 (UTC) Received: by mail-pg0-f67.google.com with SMTP id w12-v6so13320545pgc.6 for ; Mon, 04 Jun 2018 07:36:46 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36: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=CJ9o3iG/haNkIK5yXOOoeWmmSWDAUM2CqN+Xoe33P7k=; b=DWZE3VkeqOigsIovgV0ERdd8G3Wh9TZO2xWXnfqAy/4ZBByySkdqgh0x3HprRpnlCj qT0Ior00ruWGoMx/uAKsb32xMTR5vEpgNvvGPtp5kTMZuTp4KGSn4BxL1rVcghgyrZXW a4JoBZlRH+ouFJWMgJmPLhPqnFbTf1jD62CBCVfS6u7vXf5ERuyICmTGW3HrZS4UdeT/ Yy0C6BZSWYZsVOmV+5g1jaKZgT7A4EaMjZS6OE95oCGbbU65hR+5ap6S0i5qBojUyhhN LfyBbJmVzSPprhENF3MNWqT5JhActVk1HLATCnMYHa/HP8PlxvD5AhI/70VmMW/E0qMg twTQ== 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=CJ9o3iG/haNkIK5yXOOoeWmmSWDAUM2CqN+Xoe33P7k=; b=q8Z/B3G1Yx4O5M83fbvcEWXnhiPuD0BWaSQa+aBV9xTts5p0x0ArtWoFZMoxAgwARu NHFkdNO5bIqWzfE7Hw5xL9TpKBwaUDbqEag51///VI6UDdglfCjugcoMDolarbl9qyAA qlNR148h8J8ynwQm4RutjpNVVGwBH4UKk7jbsJTXGPdyG0P0APeFqgYq8Gwpdm/46j/n UKiL89gLT5SooC2mDeyFQFjNtG1T+vCOjbAEd7KKnqN1N4p1zHJawd7IvPpVgIJ4igqI iuKLO89RNL6o2UZOq36WQYFPxyjFEvjFMj/WJe6Q9B6Ow2W+esLViB4akzBZdO0Pad5k +dMQ== X-Gm-Message-State: APt69E0KSbfDhFWHtHgs/MjnaJMqzVAEX8gZtWKoTszHCrzHQ44MRg67 +YOvztlxpsulIVfEMsFNKE32OiYh X-Google-Smtp-Source: ADUXVKJnr0q4AE7qe88+zHl2T6eSV+qvutEy0gqYJLqGURA3NDOOK2wrisNTasmtOv4HScoIkjZLRQ== X-Received: by 2002:a62:484d:: with SMTP id v74-v6mr7469013pfa.256.1528123006169; Mon, 04 Jun 2018 07:36:46 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:09 +0530 Message-Id: <1528013536-22196-12-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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]); Mon, 04 Jun 2018 14:36:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 04 Jun 2018 14:36:47 +0000 (UTC) for IP:'74.125.83.67' DOMAIN:'mail-pg0-f67.google.com' HELO:'mail-pg0-f67.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.766 * (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 74.125.83.67 mail-pg0-f67.google.com 74.125.83.67 mail-pg0-f67.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 11/18] use VIR_AUTOFREE in src/util/vireventpoll.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.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 04 Jun 2018 15:05:15 +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" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- 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 Fri May 3 19:08:29 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 1528124729279712.8764067804609; Mon, 4 Jun 2018 08:05:29 -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 3D533D7E53; Mon, 4 Jun 2018 15:05: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 DF8955B681; Mon, 4 Jun 2018 15:05: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 892301800FD9; Mon, 4 Jun 2018 15:05:26 +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 w54Eb08u008177 for ; Mon, 4 Jun 2018 10:37:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 49CB22016A81; Mon, 4 Jun 2018 14:37:00 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4035B2016A80 for ; Mon, 4 Jun 2018 14:37:00 +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 191FFC0D4726 for ; Mon, 4 Jun 2018 14:36:49 +0000 (UTC) Received: by mail-pf0-f194.google.com with SMTP id w7-v6so690334pfn.9 for ; Mon, 04 Jun 2018 07:36:49 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36: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=5lS8s/Exorw8W9Row1xyoPdCg9BFKURzqUpbEV/O2lQ=; b=VGnID0BkqocVC7Uefc6DwKz9dSJyrqXHlyLqlBxOhbF3acXrDKdw6J+VjcqkpQ22Hb SYdQEaJYNRXAq1y3IoNlBJNiBfXavOL+91iJQJFTFbRxww329Pa7TPCqPeVTm9aYy0ak ohF8BkGrg0zLcBS+rtLW4ULlqo7u+YqXkRAXR2ry6UjEaM0CovjcXCCbP9m6N5fLTEIg OhdesV7i4JJ7tlC2i1Ro6xap4vw2cAobgbPL181sNrsIVn5fuAgd/2vJRQMj0xVOvVWP iBsSgfMBoxJEP0lkaLq8YrpQsSm+IYdQT/adB/Oh6uK6z1n7LJLM8wnscq0p/Fn3wywn j7aA== 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=5lS8s/Exorw8W9Row1xyoPdCg9BFKURzqUpbEV/O2lQ=; b=PkqGMCaJmg7pEeDUAQIgFuwyhDVhaIDBeZ4XZOcbXUSZaayNnbJxyOzG+O4g86laI1 9ZB2W4cN1QZRKdRRhlKbliz3dnYaTVIl124GGtnbzI9XVyyAjpBC/dXostInn2ZhHOsd XJZZfLIi7WbSXnn993UueE/yUisS7MN6OesIcWOqg9DrDaTDY+hHCVt89OR22tjXjrOq gWda7PRCoVaa6sTVGuC03/P3KW3h4LlfYjqHPaOOHGCG/mrtEa0ZF/lLZwH+frXsEuvj IkaYusnD/7eZTREJNnPFbTRv1hkjGtA1c535Nakc7yQC3wWVKOcHp6fqF+O+oNTH9mrX cOaw== X-Gm-Message-State: ALKqPwfz3Qnc8HJGKnGn5X1dJtDH0V1I2c4gtGbQthyZGGeyU9iDHBAg cKVsdiKAbgRvM+Ny482iToRB5icV X-Google-Smtp-Source: ADUXVKJisW1m5JCuyKEUIE1FKzOlscI1NZWqZF+lWgwmu2xzBTSUjIxXM9xQXFHDq3/d+VueD6gMQA== X-Received: by 2002:a62:ed12:: with SMTP id u18-v6mr21741670pfh.127.1528123008204; Mon, 04 Jun 2018 07:36:48 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:10 +0530 Message-Id: <1528013536-22196-13-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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.31]); Mon, 04 Jun 2018 14:36:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 04 Jun 2018 14:36:49 +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: 0.991 (DATE_IN_PAST_24_48, 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.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 12/18] use VIR_AUTOFREE in src/util/virdbus.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.39]); Mon, 04 Jun 2018 15:05: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" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- src/util/virdbus.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/src/util/virdbus.c b/src/util/virdbus.c index ba8b684..66dbe41 100644 --- a/src/util/virdbus.c +++ b/src/util/virdbus.c @@ -614,9 +614,8 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter, size_t nstack =3D 0; size_t siglen; size_t skiplen; - char *contsig =3D NULL; const char *vsig; - DBusMessageIter *newiter =3D NULL; + VIR_AUTOFREE(DBusMessageIter *) newiter =3D NULL; DBusMessageIter *iter =3D rootiter; =20 VIR_DEBUG("rootiter=3D%p types=3D%s", rootiter, types); @@ -628,6 +627,7 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter, nstruct =3D strlen(types); =20 for (;;) { + VIR_AUTOFREE(char *) contsig =3D NULL; const char *t; =20 VIR_DEBUG("Loop nstack=3D%zu narray=3D%zd nstruct=3D%zu types=3D'%= s'", @@ -752,11 +752,8 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter, goto cleanup; if (virDBusTypeStackPush(&stack, &nstack, iter, types, - nstruct, narray) < 0) { - VIR_FREE(newiter); + nstruct, narray) < 0) goto cleanup; - } - VIR_FREE(contsig); iter =3D newiter; newiter =3D NULL; types =3D t + 1; @@ -780,10 +777,8 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter, goto cleanup; if (virDBusTypeStackPush(&stack, &nstack, iter, types, - nstruct, narray) < 0) { - VIR_FREE(newiter); + nstruct, narray) < 0) goto cleanup; - } iter =3D newiter; newiter =3D NULL; types =3D vsig; @@ -811,11 +806,8 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter, =20 if (virDBusTypeStackPush(&stack, &nstack, iter, types, - nstruct, narray) < 0) { - VIR_FREE(newiter); + nstruct, narray) < 0) goto cleanup; - } - VIR_FREE(contsig); iter =3D newiter; newiter =3D NULL; types =3D t + 1; @@ -847,8 +839,6 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter, } =20 virDBusTypeStackFree(&stack, &nstack); - VIR_FREE(contsig); - VIR_FREE(newiter); return ret; } # undef SET_NEXT_VAL @@ -891,9 +881,8 @@ virDBusMessageIterDecode(DBusMessageIter *rootiter, size_t nstack =3D 0; size_t skiplen; size_t siglen; - char *contsig =3D NULL; const char *vsig; - DBusMessageIter *newiter =3D NULL; + VIR_AUTOFREE(DBusMessageIter *) newiter =3D NULL; DBusMessageIter *iter =3D rootiter; =20 VIR_DEBUG("rootiter=3D%p types=3D%s", rootiter, types); @@ -905,6 +894,7 @@ virDBusMessageIterDecode(DBusMessageIter *rootiter, nstruct =3D strlen(types); =20 for (;;) { + VIR_AUTOFREE(char *) contsig =3D NULL; const char *t; bool advanceiter =3D true; =20 @@ -1053,7 +1043,6 @@ virDBusMessageIterDecode(DBusMessageIter *rootiter, iter, types, nstruct, narray) < 0) goto cleanup; - VIR_FREE(contsig); iter =3D newiter; newiter =3D NULL; types =3D t + 1; @@ -1112,7 +1101,6 @@ virDBusMessageIterDecode(DBusMessageIter *rootiter, iter, types, nstruct, narray) < 0) goto cleanup; - VIR_FREE(contsig); iter =3D newiter; newiter =3D NULL; types =3D t + 1; @@ -1167,8 +1155,6 @@ virDBusMessageIterDecode(DBusMessageIter *rootiter, =20 cleanup: virDBusTypeStackFree(&stack, &nstack); - VIR_FREE(contsig); - VIR_FREE(newiter); return ret; } # undef GET_NEXT_VAL --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 19:08:29 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 1528124745872884.3506066669247; Mon, 4 Jun 2018 08:05:45 -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 A28F630BFEDE; Mon, 4 Jun 2018 15:05:43 +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 62DB63001A5E; Mon, 4 Jun 2018 15:05: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 CD1D4180BA80; Mon, 4 Jun 2018 15:05:42 +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 w54Eb2rG008189 for ; Mon, 4 Jun 2018 10:37:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9F5C3308BDB0; Mon, 4 Jun 2018 14:37:02 +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 967A5308BDAE for ; Mon, 4 Jun 2018 14:37:02 +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 9DCA630B8990 for ; Mon, 4 Jun 2018 14:36:51 +0000 (UTC) Received: by mail-pf0-f196.google.com with SMTP id z24-v6so1889691pfe.7 for ; Mon, 04 Jun 2018 07:36:51 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36:50 -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=1kGa7e3WZPzYnXf4Eq42CpJ3QXd9xSH5QLIo35lbIOc=; b=gEAEX27HKKeBrrkpMVZDWSnAnCkHIgSwyXJf3oZq0s1v6AebCU4NbvpELA0HaHx5av mn70dkGn8tqwTWoZZVo4ZwNHU9/iq/qJmSZVjnWM2VCwOkSdBWzm6cCKBD/8fjNCXJ/P Hm8yEeDCrIOU73bvowBudiESLDQUQ9JQ7+OESEzJibikuEwOvbEQIFSF7vXifTm2o5CF +trTk1QXEByVucxs4WMS75O4+62V2ja6dYaqvcSdH/tb7l2yCexVg2AkJWHneTfhwwZ/ X3S4PRLm/vZIxs65S5y4INC9I8KRIQQ/Lz+xy3Mb0wdOQ9Bh/18qkgxCVhcuZoZgtdWn kKsg== 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=1kGa7e3WZPzYnXf4Eq42CpJ3QXd9xSH5QLIo35lbIOc=; b=Q8FjsSifxP6HkU0uc8V8kG/LzJEjZexZErtI6BeZAIK0UgrMg0JDXplgEA5POt0Tbt VowWnOcBKZiPfITIku6nYn2mrLD4bFex1GR7gQ3cihyFwJn4nUot3kwpeckyUkRUOjB/ HodH8tO8FIkmZIz5rSYgQPyZLKKC7BzgGz1dpCdbMApPd1HHtogBry9shoqaarw2Z7yE U9FcJ2LIIArWjwCaQnpc0BHRkmXXDcFerh4JWVwv5j4tL6hZhailx5hitAf/46+TmMls hR5KktD1IItbuLKLZBcrOVcJYosMpCzMSz8DsizO/1ihBoDqaOmLV/iufOWeT7YpinnA hs2w== X-Gm-Message-State: ALKqPwckp2myVPHfe0TAtHDj/gHswGfhj5T6uwQPR6g+0LhnnNCbsZbs zb+g90UDHrTdCQGfipIuMGj9ptrL X-Google-Smtp-Source: ADUXVKLN9so+PLeLGx3+rzfFLWDk3tJyzP3l6bs0pfW39iDbAj7Yl3ndi/vQPNrQOVtV7VNTflFkow== X-Received: by 2002:a62:3e11:: with SMTP id l17-v6mr21797341pfa.18.1528123010701; Mon, 04 Jun 2018 07:36:50 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:11 +0530 Message-Id: <1528013536-22196-14-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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]); Mon, 04 Jun 2018 14:36:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 04 Jun 2018 14:36:51 +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: 0.991 (DATE_IN_PAST_24_48, 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.43 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 13/18] use VIR_AUTOFREE in src/util/virfdstream.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.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 04 Jun 2018 15:05: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" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- src/util/virfdstream.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c index e4973a2..e7befbc 100644 --- a/src/util/virfdstream.c +++ b/src/util/virfdstream.c @@ -431,7 +431,7 @@ virFDStreamThreadDoRead(virFDStreamDataPtr fdst, virFDStreamMsgPtr msg =3D NULL; int inData =3D 0; long long sectionLen =3D 0; - char *buf =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; ssize_t got; =20 if (sparse && *dataLen =3D=3D 0) { @@ -496,7 +496,6 @@ virFDStreamThreadDoRead(virFDStreamDataPtr fdst, return got; =20 error: - VIR_FREE(buf); virFDStreamMsgFree(msg); return -1; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 19:08:29 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 152812475848094.251929500232; Mon, 4 Jun 2018 08:05:58 -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 0AEE25355E; Mon, 4 Jun 2018 15:05:56 +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 F03A81057FA3; Mon, 4 Jun 2018 15:05:54 +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 46DB14CA85; Mon, 4 Jun 2018 15:05:54 +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 w54Eb6e6008207 for ; Mon, 4 Jun 2018 10:37:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 90B4F308BDAE; Mon, 4 Jun 2018 14:37:06 +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 868F2308BDB0 for ; Mon, 4 Jun 2018 14:37:06 +0000 (UTC) Received: from mail-pg0-f66.google.com (mail-pg0-f66.google.com [74.125.83.66]) (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 BFCF0B8904 for ; Mon, 4 Jun 2018 14:36:54 +0000 (UTC) Received: by mail-pg0-f66.google.com with SMTP id 15-v6so14210798pge.2 for ; Mon, 04 Jun 2018 07:36:54 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36: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=LROB1BcLvMnLmpxtRKEQzAniJqraawzxcglwny+sj3Q=; b=T8/OuG73sSC57ZwQK292aDOvQjFzRrTl0SJ5fydD0OZMihJc9vN1predTDUj+qgwqb y5mD+8QXi+DBg96rCSLKDI8TyYif28PD+53gVJbQg2MHNMIWjeKOz9ksQAyQk07uNGEp 2t20Devl7L59K7N7XRaR6oLKeWR2p0nexlbzyiP8RuO5kGZqkA4nAts/YE4INwprotKm 0LsQEArV4YkfCat00RuQ3ic6w36EOj1vcmGN+BFO+LAoUpLZ0m/0uAPFc1tf1asr9/Dl QRnZwngwLa0sNbRjdP96jz3uHJPcen88Gg1TIgE9OuXqcLi2Li9ie6shrPxNXaVPpjhG HmwQ== 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=LROB1BcLvMnLmpxtRKEQzAniJqraawzxcglwny+sj3Q=; b=M3tOo9UlAcFayMWgQ0Rv2X5oB01tOhQ+r8oRgirVwtOibLy4p5kcshPYhLek8mknVJ kTD38u87Z6dRFEVEdtKcy27od2hYDhqRNSG3gzY0HXPtYRgLdQZBDHXHv5dg6mvXElRk 70wNGwH/yXH8rud8leqqqck+pytm2fFCTpfmU/rWqAzYPHcHvloSGiSjpjvp6ZXpUkgw I6jgvkWr9mdTQoTwcBJNPtCbV2cOz7yokkeO2/i7G0itYMwrjrdYlaE0WhMsjIBzAg2u Sv+uij6l6fYDdIt05GQUcaQYylhAMxtfxsWsd8FteHva8NTkqJrAi5lBlWF6VaBEQogL G58Q== X-Gm-Message-State: ALKqPwcfEF1w51liNzS1cfMVLjbl+DrSz77ap+SCcKkh83xRSzavzVbm 7S06uGWEd0IHuAi6WF6N5dNu2UgK X-Google-Smtp-Source: ADUXVKJykbAzr1srPb4Xmw++TGmMv5tsTCn0PzRCFe2Olsn9XpczjZnDuN1W1iMp67PJkJ3YJeULuw== X-Received: by 2002:a65:4204:: with SMTP id c4-v6mr17125914pgq.26.1528123013773; Mon, 04 Jun 2018 07:36:53 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:12 +0530 Message-Id: <1528013536-22196-15-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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]); Mon, 04 Jun 2018 14:36:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 04 Jun 2018 14:36:54 +0000 (UTC) for IP:'74.125.83.66' DOMAIN:'mail-pg0-f66.google.com' HELO:'mail-pg0-f66.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.766 * (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 74.125.83.66 mail-pg0-f66.google.com 74.125.83.66 mail-pg0-f66.google.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 14/18] use VIR_AUTOFREE in src/util/virfile.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.28]); Mon, 04 Jun 2018 15:05:57 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- src/util/virfile.c | 303 +++++++++++++++++--------------------------------= ---- 1 file changed, 99 insertions(+), 204 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 523241f..52b601d 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); @@ -453,7 +450,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 @@ -494,10 +491,8 @@ virFileRewrite(const char *path, =20 cleanup: VIR_FORCE_CLOSE(fd); - if (newfile) { + if (newfile) unlink(newfile); - VIR_FREE(newfile); - } return ret; } =20 @@ -724,7 +719,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) @@ -762,7 +757,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); @@ -777,8 +771,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) @@ -786,18 +779,15 @@ 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; =20 - cleanup: - VIR_FREE(path); - return ret; + return 1; } =20 =20 @@ -842,15 +832,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; } @@ -860,8 +848,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; @@ -909,8 +897,6 @@ int virFileNBDDeviceAssociate(const char *file, ret =3D 0; =20 cleanup: - VIR_FREE(nbddev); - VIR_FREE(qemunbd); virCommandFree(cmd); return ret; } @@ -957,7 +943,6 @@ int virFileDeleteTree(const char *dir) { DIR *dh; struct dirent *de; - char *filepath =3D NULL; int ret =3D -1; int direrr; =20 @@ -969,6 +954,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", @@ -992,8 +978,6 @@ int virFileDeleteTree(const char *dir) goto cleanup; } } - - VIR_FREE(filepath); } if (direrr < 0) goto cleanup; @@ -1008,7 +992,6 @@ int virFileDeleteTree(const char *dir) ret =3D 0; =20 cleanup: - VIR_FREE(filepath); VIR_DIR_CLOSE(dh); return ret; } @@ -1166,7 +1149,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) @@ -1187,15 +1170,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 @@ -1558,8 +1538,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); @@ -1571,9 +1550,8 @@ 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 @@ -1897,44 +1875,39 @@ 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); - - cleanup: - VIR_FREE(parent); return ret; } =20 @@ -2118,7 +2091,7 @@ virFileAccessibleAs(const char *path, int mode, pid_t pid =3D 0; int status, ret =3D 0; int forkRet =3D 0; - gid_t *groups; + VIR_AUTOFREE(gid_t *) groups =3D NULL; int ngroups; =20 if (uid =3D=3D geteuid() && @@ -2131,13 +2104,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; @@ -2242,7 +2212,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 @@ -2260,16 +2230,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 @@ -2334,7 +2300,6 @@ virFileOpenForked(const char *path, int openflags, mo= de_t mode, =20 /* parent */ =20 - VIR_FREE(groups); VIR_FORCE_CLOSE(pair[1]); =20 do { @@ -2535,7 +2500,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)) { @@ -2560,15 +2525,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 @@ -2700,7 +2661,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 @@ -2736,15 +2697,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 @@ -3045,19 +3002,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 @@ -3065,8 +3017,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 @@ -3077,15 +3028,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 @@ -3119,7 +3066,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. @@ -3180,7 +3127,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; } @@ -3280,7 +3226,7 @@ virFileSkipRoot(const char *path) int virFileAbsPath(const char *path, char **abspath) { - char *buf; + VIR_AUTOFREE(char *) buf =3D NULL; =20 if (path[0] =3D=3D '/') { if (VIR_STRDUP(*abspath, path) < 0) @@ -3290,11 +3236,8 @@ virFileAbsPath(const char *path, char **abspath) 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; @@ -3394,7 +3337,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); @@ -3408,8 +3351,6 @@ int virFilePrintf(FILE *fp, const char *msg, ...) ret =3D -1; } =20 - VIR_FREE(str); - cleanup: va_end(vargs); =20 @@ -3445,7 +3386,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 @@ -3465,7 +3407,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 @@ -3478,8 +3419,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'"), @@ -3546,18 +3485,18 @@ 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, *n, *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 @@ -3570,13 +3509,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" @@ -3589,7 +3525,7 @@ virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs, FILE *f =3D NULL; struct mntent mb; char mntbuf[1024]; - virHugeTLBFSPtr fs =3D NULL; + VIR_AUTOFREE(virHugeTLBFSPtr) fs =3D NULL; size_t nfs =3D 0; unsigned long long default_hugepagesz =3D 0; =20 @@ -3634,7 +3570,6 @@ virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs, endmntent(f); while (nfs) VIR_FREE(fs[--nfs].mnt_dir); - VIR_FREE(fs); return ret; } =20 @@ -3870,10 +3805,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 @@ -3882,19 +3815,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; - - ret =3D STREQ_NULLABLE(res1, res2); - - cleanup: - VIR_FREE(res1); - VIR_FREE(res2); + return -1; =20 - return ret; + return STREQ_NULLABLE(res1, res2); } =20 =20 @@ -4038,25 +3965,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 @@ -4064,14 +3988,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 @@ -4088,25 +4008,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 @@ -4114,14 +4031,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 @@ -4138,26 +4051,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 @@ -4165,14 +4075,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 @@ -4192,37 +4098,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 /** @@ -4240,30 +4139,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 Fri May 3 19:08:29 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 1528124769420702.4833240014613; Mon, 4 Jun 2018 08:06:09 -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 7AFF8C0D1FBC; Mon, 4 Jun 2018 15:06:07 +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 27ED0600C4; Mon, 4 Jun 2018 15:06:07 +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 8EC5A4CA81; Mon, 4 Jun 2018 15:06:06 +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 w54Eb7JC008212 for ; Mon, 4 Jun 2018 10:37:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id DB6118B336; Mon, 4 Jun 2018 14:37:07 +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 D41638B327 for ; Mon, 4 Jun 2018 14:37:07 +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 D13B73003C7B for ; Mon, 4 Jun 2018 14:36:56 +0000 (UTC) Received: by mail-pf0-f195.google.com with SMTP id w7-v6so690524pfn.9 for ; Mon, 04 Jun 2018 07:36:56 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36: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=ssrCY465CBfTImnKaGCPXyj1RsMn32r7WPHZBtmK0wM=; b=lQ75RQbD+hF+bUThUbBoKV53WfgnjYv43YJQ1TARyY4hgaOIfpaKv0s9bq8cmcHJJC eb1vFMdV/rFOTdMfzqFI+nA5WuaDTpCygHpfmF2dQfog8DYbhf3O8QEPlO6fP5DxdJzd lrUntGfKo6eghKXWuzvG//f+nPJ/jfQ30YIr2eXMNeD/aS5xCUPP4Siv3/Y0030xXcxh f6LuxWNy96PzUWFibyPXe/cGWyRWGws5M9Dfp1YQm+Iyz3qM3xEciVWu/03LShR05jBt xzVbwSi0FE7QYkeGby1JayDc9/6biY6SW4he/KyKxY2HVWtNXBVrtYhKCrDTbE62tbpG rORw== 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=ssrCY465CBfTImnKaGCPXyj1RsMn32r7WPHZBtmK0wM=; b=QiKjzTR6FD/579aa2wEAmKWK/JX3fEAu8YZe0sMw9rv9zzpepFmfxP3x0pJemK6Fn3 N+5fJmJHOudNgAfqEZqMOb7u5PfwwVvo+d98MvHM+Dx/IJIcgFE0G4A/IkVt7eNU7/0j yAbZy397YysS8e5wBvEz1M6QUKwx35mKXqxBdpnRI78pXkVKqxFk1jD05JYxg0wuV90V QRMlLBLK3g7nldfGsstnOlm6G/UDBLCDCDXpOkTScBRZ+eVo7xYdTQS7WRrnJH1afzGp 64Ne8Q/FYzexkeBVQrCdjQCw++xfWaRH1k1Ic7+I75AZ+KjL0pQMfdYpC87v2qOw8O+O ShTg== X-Gm-Message-State: APt69E3mualR0P8kdYQHymZZIIJaOEbD/MpSYl1u9BXYy1M9tsv5NCqD eu+kqMwW9iQgD6YIEkxX66U8qLeM X-Google-Smtp-Source: ADUXVKIviNbqvfV1QIv7vPfbjb9D8ZhOKv2ruflUih8zGfGjqxm9nfS1vmo+9BU4hktudFK12mvk8Q== X-Received: by 2002:a63:721d:: with SMTP id n29-v6mr5230238pgc.194.1528123016025; Mon, 04 Jun 2018 07:36:56 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:13 +0530 Message-Id: <1528013536-22196-16-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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]); Mon, 04 Jun 2018 14:36:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 04 Jun 2018 14:36:56 +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.991 (DATE_IN_PAST_24_48, 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.44 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 15/18] use VIR_AUTOFREE in src/util/virconf.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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 04 Jun 2018 15:06:08 +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" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- src/util/virconf.c | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/src/util/virconf.c b/src/util/virconf.c index e0a3fd1..7dd8820 100644 --- a/src/util/virconf.c +++ b/src/util/virconf.c @@ -745,9 +745,8 @@ virConfParse(const char *filename, const char *content,= int len, virConfPtr virConfReadFile(const char *filename, unsigned int flags) { - char *content; + VIR_AUTOFREE(char *) content =3D NULL; int len; - virConfPtr conf; =20 VIR_DEBUG("filename=3D%s", NULLSTR(filename)); =20 @@ -759,11 +758,7 @@ virConfReadFile(const char *filename, unsigned int fla= gs) if ((len =3D virFileReadAll(filename, MAX_CONFIG_FILE_SIZE, &content))= < 0) return NULL; =20 - conf =3D virConfParse(filename, content, len, flags); - - VIR_FREE(content); - - return conf; + return virConfParse(filename, content, len, flags); } =20 /** @@ -1451,7 +1446,7 @@ virConfWriteFile(const char *filename, virConfPtr con= f) virConfEntryPtr cur; int ret; int fd; - char *content; + VIR_AUTOFREE(char *) content =3D NULL; unsigned int use; =20 if (conf =3D=3D NULL) @@ -1476,7 +1471,6 @@ virConfWriteFile(const char *filename, virConfPtr con= f) use =3D virBufferUse(&buf); content =3D virBufferContentAndReset(&buf); ret =3D safewrite(fd, content, use); - VIR_FREE(content); VIR_FORCE_CLOSE(fd); if (ret !=3D (int)use) { virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to save content= ")); @@ -1504,7 +1498,7 @@ virConfWriteMem(char *memory, int *len, virConfPtr co= nf) { virBuffer buf =3D VIR_BUFFER_INITIALIZER; virConfEntryPtr cur; - char *content; + VIR_AUTOFREE(char *) content =3D NULL; unsigned int use; =20 if ((memory =3D=3D NULL) || (len =3D=3D NULL) || (*len <=3D 0) || (con= f =3D=3D NULL)) @@ -1524,11 +1518,9 @@ virConfWriteMem(char *memory, int *len, virConfPtr c= onf) =20 if ((int)use >=3D *len) { *len =3D (int)use; - VIR_FREE(content); return -1; } memcpy(memory, content, use); - VIR_FREE(content); *len =3D use; return use; } @@ -1542,16 +1534,13 @@ virConfLoadConfigPath(const char *name) SYSCONFDIR, name) < 0) return NULL; } else { - char *userdir =3D virGetUserConfigDirectory(); + VIR_AUTOFREE(char *) userdir =3D virGetUserConfigDirectory(); if (!userdir) return NULL; =20 if (virAsprintf(&path, "%s/%s", - userdir, name) < 0) { - VIR_FREE(userdir); + userdir, name) < 0) return NULL; - } - VIR_FREE(userdir); } =20 return path; @@ -1560,26 +1549,19 @@ virConfLoadConfigPath(const char *name) int virConfLoadConfig(virConfPtr *conf, const char *name) { - char *path =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; =20 *conf =3D NULL; =20 if (!(path =3D virConfLoadConfigPath(name))) - goto cleanup; + return -1; =20 - if (!virFileExists(path)) { - ret =3D 0; - goto cleanup; - } + if (!virFileExists(path)) + return 0; =20 VIR_DEBUG("Loading config file '%s'", path); if (!(*conf =3D virConfReadFile(path, 0))) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(path); - 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 Fri May 3 19:08:29 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 1528124367448642.2766752202106; Mon, 4 Jun 2018 07:59:27 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F18A31647B7; Mon, 4 Jun 2018 14:59:25 +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 1FF2B608EF; Mon, 4 Jun 2018 14:59:25 +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 8C22A4CA81; Mon, 4 Jun 2018 14:59:24 +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 w54EbCFB008532 for ; Mon, 4 Jun 2018 10:37:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1FF9F1802D; Mon, 4 Jun 2018 14:37:12 +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 142245C8AA for ; Mon, 4 Jun 2018 14:37:09 +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 DA69230C036B for ; Mon, 4 Jun 2018 14:36:58 +0000 (UTC) Received: by mail-pl0-f65.google.com with SMTP id i5-v6so19842580plt.2 for ; Mon, 04 Jun 2018 07:36:58 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36:57 -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=h3Tn8+lIZbbFnrCZjYWtAPnmIrmqBsp/hGdpw3ZIBRg=; b=r3OEyF+vyvX9iSu5OrVleNsCVtZive8yYUP0tl9joIWi4shFx5QnXXNWDnzPb8/ee6 sCPO8/X+fsQaToxTesZ518eyFLz3YKLm0sKO2+Yfsu+SCTR8hnBd0NsYwKQiNS3EFIqH Cn06W+vpHIDKdz/wYuY/CTk4YkSakDKhHCnQQnoRanrU50Ov4pBLsHdkRMX6qr/CR/NK WTqfYWMnZS3LkQ+ZRs3USXXIeMAiNf3Ege6d8nETOuHysjqfwu590AA+AqN1ZHmfQQqL QLb8R7lUXdWHIV7Jak9Q89mF98DyT3kdEJjGMJVZzx8P0abjJBIQ4SWhEBAdmGT3fjAu tmEg== 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=h3Tn8+lIZbbFnrCZjYWtAPnmIrmqBsp/hGdpw3ZIBRg=; b=TGIZYgWj0ITTh4kkoqf/TU6tfVrgneM1fYSxW8UJbKyD00kVf+88q2A9YMwyyK8IOE KNj+Xy2odKyK47uJeGCdVki08Q3PHIAGbt9pWFoA7CZZ134PvmjZme+tmerwAmu4niBc imBvh0j5xOoZGywRB8Um69Ydn/qMz1sQsrDcj+YkssvsCF+bnTaeCjqMaV3vN0rdKa5x YUEcfJH8XzOqAhQhfGdp7xE/yDu2MBl03LDcemHO6UCFPpueeB1f2+ZNuYxqd/zni6aM fUKtNHTgCkKucVEi5fl7v82WIY0q44uO4dI1yM1gHXxkvYXdlz1HbMSwo3RJViycq+lZ xGow== X-Gm-Message-State: ALKqPwdaMGN28RzzDb8/21e1trw25ZeM1DBktVjJGnapgx4XBLQHNAjg gN5wmm6/pE29sFNjThBOmyQke7No X-Google-Smtp-Source: ADUXVKKqQb0rWKs7oMS5U1zAE8+uvMwyPje0xNmxY8qQ7isgP0lEY8PWNPwE/TsWmCxQy2tJ2f82/g== X-Received: by 2002:a17:902:a714:: with SMTP id w20-v6mr21598191plq.374.1528123018025; Mon, 04 Jun 2018 07:36:58 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:14 +0530 Message-Id: <1528013536-22196-17-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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]); Mon, 04 Jun 2018 14:36:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 04 Jun 2018 14:36:59 +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.766 * (DATE_IN_PAST_24_48, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 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.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 16/18] use VIR_AUTOFREE in src/util/virfilecache.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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 04 Jun 2018 14:59:26 +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" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- 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 dab7216..49049b7 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; - - file =3D virBufferContentAndReset(&buf); + return NULL; =20 - 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 @@ -179,7 +174,6 @@ virFileCacheLoad(virFileCachePtr cache, =20 cleanup: virObjectUnref(loadData); - VIR_FREE(file); return ret; } =20 @@ -189,20 +183,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; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(file); - return ret; + return 0; } =20 =20 @@ -347,7 +336,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 @@ -357,8 +346,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 Fri May 3 19:08:29 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 152812424388227.554678436492395; Mon, 4 Jun 2018 07:57:23 -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 89EF63184B16; Mon, 4 Jun 2018 14:57: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 334DE600C4; Mon, 4 Jun 2018 14:57: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 9656D4BB78; Mon, 4 Jun 2018 14:57:20 +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 w54EbETI008550 for ; Mon, 4 Jun 2018 10:37:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id A00971001941; Mon, 4 Jun 2018 14:37:14 +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 97AFF100164D for ; Mon, 4 Jun 2018 14:37:12 +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 04E52104D69 for ; Mon, 4 Jun 2018 14:37:01 +0000 (UTC) Received: by mail-pf0-f195.google.com with SMTP id a22-v6so2951751pfo.12 for ; Mon, 04 Jun 2018 07:37:00 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36:59 -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=6xKjzNQGHnbRQnKkMV4Ohunv4lCfQRorg9r1nN8j/us=; b=T9bsC/B6Qv4qU/Blczo4/ulBYn8aP/p2VSf/IZxKDV75h4ESquW+uOIRQvs421Wcbo pI8SIbgVubfEYhICHrhes7YIqfaO3nQlM2oogXmk/94NRZFJGToSfVA4A8SNBqFdN7C3 lI2dLYWwC9uxQWaehF1hp8Or6Gg5vxTJtI61pB2DyA8Om/n3gWEB65LFp7Rmtn2gk3/i osdoZa49dPIYOJvsqxbtjquZg3hOHKwd/ZklyVjd7KWbd7ob+dIaYRv6qmTNME4dc0ph mX1S6Jb4L4muSPY+Ccmfl8Zn9HfDHhvn+n7CbUmibbrgXs1ap5i2+7xGQJY/786KNR/1 Xkug== 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=6xKjzNQGHnbRQnKkMV4Ohunv4lCfQRorg9r1nN8j/us=; b=mgV6K7qcBJQwVlIE11hS/LnMHiJKOWbUUen6t3fxcL9unrfe0g779ByeHR5ojUeMyV H1cm+g69o/x/JzRgkgAMyYIVkS+QkCjCiC47AzNA7/jp9xrKU+/Xu3r3MULGv/j6miu2 djfRP0tapFjj51oXHWl8AdHH1gyDsKRiTKELWuDPwweK6/PoP6As1zGIvQ5t8tmUEWpY ZNQO00HcszttmER1amYWvHJqdm9FIzeBISqV30vPXs4BQROeWGJ+Bcpc+Ka4o+RNKq3c MnS++mUJmdwoaf1u0CpEC7yNAU0lv/o7FOxRzRRvMpYahHFAxVyPi4ZkQlhCE8XdJMoJ F23w== X-Gm-Message-State: APt69E2eaJfirsv3I5jRaSs4VugjZPshlkohtxkCEVH1J9hir9s/MOyz 0rz/oY0IyF3vY0AtR2/JEVqA2N+W X-Google-Smtp-Source: ADUXVKJSb61RhzCAVIDM261aU1bvy+SuiDwAxJXlTKgAMyERBWP68tH5xULNAlBMr+/icbVZ/jz/pg== X-Received: by 2002:a62:6e01:: with SMTP id j1-v6mr4204013pfc.93.1528123020165; Mon, 04 Jun 2018 07:37:00 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:15 +0530 Message-Id: <1528013536-22196-18-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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]); Mon, 04 Jun 2018 14:37:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 04 Jun 2018 14:37:01 +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.991 (DATE_IN_PAST_24_48, 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.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 17/18] use VIR_AUTOFREE in src/util/virfirewall.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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 04 Jun 2018 14:57: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" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- src/util/virfirewall.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c index 10c370a..568612c 100644 --- a/src/util/virfirewall.c +++ b/src/util/virfirewall.c @@ -512,7 +512,7 @@ void virFirewallRuleAddArgFormat(virFirewallPtr firewal= l, virFirewallRulePtr rule, const char *fmt, ...) { - char *arg; + VIR_AUTOFREE(char *) arg =3D NULL; va_list list; =20 VIR_FIREWALL_RULE_RETURN_IF_ERROR(firewall, rule); @@ -526,13 +526,11 @@ void virFirewallRuleAddArgFormat(virFirewallPtr firew= all, =20 va_end(list); =20 - VIR_FREE(arg); return; =20 no_memory: firewall->err =3D ENOMEM; va_end(list); - VIR_FREE(arg); } =20 =20 @@ -679,7 +677,7 @@ virFirewallApplyRuleDirect(virFirewallRulePtr rule, virCommandPtr cmd =3D NULL; int status; int ret =3D -1; - char *error =3D NULL; + VIR_AUTOFREE(char *) error =3D NULL; =20 if (!bin) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -715,7 +713,6 @@ virFirewallApplyRuleDirect(virFirewallRulePtr rule, =20 ret =3D 0; cleanup: - VIR_FREE(error); virCommandFree(cmd); return ret; } @@ -808,12 +805,11 @@ virFirewallApplyRule(virFirewallPtr firewall, virFirewallRulePtr rule, bool ignoreErrors) { - char *output =3D NULL; + VIR_AUTOFREE(char *) output =3D NULL; char **lines =3D NULL; int ret =3D -1; - char *str =3D virFirewallRuleToString(rule); + VIR_AUTOFREE(char *) str =3D virFirewallRuleToString(rule); VIR_INFO("Applying rule '%s'", NULLSTR(str)); - VIR_FREE(str); =20 if (rule->ignoreErrors) ignoreErrors =3D rule->ignoreErrors; @@ -858,7 +854,6 @@ virFirewallApplyRule(virFirewallPtr firewall, ret =3D 0; cleanup: virStringListFree(lines); - VIR_FREE(output); 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 Fri May 3 19:08:29 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 1528124503118767.6701127205044; Mon, 4 Jun 2018 08:01:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0B46F2ED2DE; Mon, 4 Jun 2018 15:01: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 9B4AD5F7C2; Mon, 4 Jun 2018 15:01:40 +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 89C621800FC1; Mon, 4 Jun 2018 15:01:39 +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 w54EbFJd008555 for ; Mon, 4 Jun 2018 10:37:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5A41720155E3; Mon, 4 Jun 2018 14:37:15 +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 442312007836 for ; Mon, 4 Jun 2018 14:37:15 +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 2D30730D0CF6 for ; Mon, 4 Jun 2018 14:37:04 +0000 (UTC) Received: by mail-pf0-f193.google.com with SMTP id x9-v6so16149726pfm.2 for ; Mon, 04 Jun 2018 07:37:04 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.37.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:37: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=AZ/VlMrl1x50e2ErqRGlRZCTSTohm4SeznC1eKuoMn8=; b=T7oZ0/6mt0uBgyLZrfm87QiDChxoncN9zqpOs9HjsQbUgO5MdEgtRUgcfOloavhzLh gonVFqKS89Abn0OcsGHlds1oD4ARW6BHoTTCco9cST6eneLPi2ECwgg38BzIdePOs0au 7Pc6YolC3cp1gkzRH5uA5muOthqP5KWDXEfrYCdIcM+4WwKV5kbRzbPYYImJv9t0HY/X o8XEhTpAEs9kQ5R7HW6ZG+Hc6S13wVbNFMZEB31GmoWvYQWOn9uOx/nrcHqKXT1bPoAS MHOU+chMYxFsz/yGBmi1u16DS07Z4vPFAgNbGBhAxJi4XY3FfWpyZX3Lfrjux8pfe1I5 9erA== 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=AZ/VlMrl1x50e2ErqRGlRZCTSTohm4SeznC1eKuoMn8=; b=KERHk46vzZVYqHoPPPxOkY+zbrQkeajUDVI2Eefgidc/IeDPZ2kg2H8WQrSFhkkjG1 PIKiwGT8kDpik2/jEQApXInzYl215+JioUTq7FQJsNcgguDikJReLrS/o7b9JrQjhBCw OZQJe4PFnH4MV48ZHM/zQFQYhCY4uoNEpnmFHk8tqNn3JPJF4Xfrx8kjQ+ZeKMMeES3Y QFeQLbvWuUfSq13DAOS4lX3or/wKo8ALtv+9+KeLdiILtKcUGXlA8cUoMhtL5qA9TJil QLWcGr4svIpBdA0alsFPQsZMjXYbvg9w6u7RXHX1A92Wx1cX2FWQKDTvI5ZzcsGmzs98 IhSA== X-Gm-Message-State: APt69E07cqUH8U8H5tW3kniMAhpNBW+HN8c0hj5oHfgq+DiYGA42QMtG hkdWBgrTBLv/TbwvDjanCH+Wksz1 X-Google-Smtp-Source: ADUXVKL+a3hm2yhgtkD+YoahCXm+kzmAnXJeKl9CyXsModm2QFSSPYy/c+bx+sYKSAl9wzDcRYUWHA== X-Received: by 2002:a63:bf0b:: with SMTP id v11-v6mr4271060pgf.29.1528123023186; Mon, 04 Jun 2018 07:37:03 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:16 +0530 Message-Id: <1528013536-22196-19-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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]); Mon, 04 Jun 2018 14:37:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Mon, 04 Jun 2018 14:37:04 +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: 0.991 (DATE_IN_PAST_24_48, 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.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 v1 18/18] use VIR_AUTOFREE in src/util/virhook.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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 04 Jun 2018 15:01: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" Modify code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- src/util/virhook.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/util/virhook.c b/src/util/virhook.c index facd74a..51f0eb5 100644 --- a/src/util/virhook.c +++ b/src/util/virhook.c @@ -122,8 +122,7 @@ static int virHooksFound =3D -1; static int virHookCheck(int no, const char *driver) { - char *path; - int ret; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (driver =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -139,18 +138,15 @@ virHookCheck(int no, const char *driver) } =20 if (!virFileExists(path)) { - ret =3D 0; VIR_DEBUG("No hook script %s", path); + return 0; } else if (!virFileIsExecutable(path)) { - ret =3D 0; VIR_WARN("Non-executable hook script %s", path); + return 0; } else { - ret =3D 1; VIR_DEBUG("Found hook script %s", path); + return 1; } - - VIR_FREE(path); - return ret; } =20 /* @@ -233,7 +229,7 @@ virHookCall(int driver, char **output) { int ret; - char *path; + VIR_AUTOFREE(char *) path =3D NULL; virCommandPtr cmd; const char *drvstr; const char *opstr; @@ -318,7 +314,5 @@ virHookCall(int driver, =20 virCommandFree(cmd); =20 - VIR_FREE(path); - return ret; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list