From: Doug Nazar <nazard@nazar.ca>
To: libtirpc-devel@lists.sourceforge.net
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 3/5] Add destructor functions to cleanup static resources on exit
Date: Wed, 22 Jul 2020 01:34:43 -0400 [thread overview]
Message-ID: <20200722053445.27987-4-nazard@nazar.ca> (raw)
In-Reply-To: <20200722053445.27987-1-nazard@nazar.ca>
Signed-off-by: Doug Nazar <nazard@nazar.ca>
---
src/auth_none.c | 14 ++++++++++++++
src/clnt_dg.c | 12 ++++++++++++
src/clnt_vc.c | 12 ++++++++++++
src/svc.c | 19 +++++++++++++++++++
4 files changed, 57 insertions(+)
diff --git a/src/auth_none.c b/src/auth_none.c
index 0b0bbd1..06db3b3 100644
--- a/src/auth_none.c
+++ b/src/auth_none.c
@@ -72,6 +72,20 @@ static struct authnone_private {
u_int mcnt;
} *authnone_private;
+__attribute__((destructor))
+static void
+authnone_cleanup(void)
+{
+ extern mutex_t authnone_lock;
+
+ mutex_lock(&authnone_lock);
+ if (authnone_private) {
+ free(authnone_private);
+ authnone_private = NULL;
+ }
+ mutex_unlock(&authnone_lock);
+}
+
AUTH *
authnone_create()
{
diff --git a/src/clnt_dg.c b/src/clnt_dg.c
index abc09f1..60e3503 100644
--- a/src/clnt_dg.c
+++ b/src/clnt_dg.c
@@ -130,6 +130,18 @@ struct cu_data {
char cu_inbuf[1];
};
+__attribute__((destructor))
+static void
+clnt_vc_cleanup(void)
+{
+ mutex_lock(&clnt_fd_lock);
+ if (dg_fd_locks) {
+ mem_free(dg_fd_locks, sizeof(*dg_fd_locks));
+ dg_fd_locks = NULL;
+ }
+ mutex_unlock(&clnt_fd_lock);
+}
+
/*
* Connection less client creation returns with client handle parameters.
* Default options are set, which the user can change using clnt_control().
diff --git a/src/clnt_vc.c b/src/clnt_vc.c
index 6f7f7da..a4b41df 100644
--- a/src/clnt_vc.c
+++ b/src/clnt_vc.c
@@ -158,6 +158,18 @@ static const char clnt_vc_errstr[] = "%s : %s";
static const char clnt_vc_str[] = "clnt_vc_create";
static const char __no_mem_str[] = "out of memory";
+__attribute__((destructor))
+static void
+clnt_vc_cleanup(void)
+{
+ mutex_lock(&clnt_fd_lock);
+ if (vc_fd_locks) {
+ mem_free(vc_fd_locks, sizeof(*vc_fd_locks));
+ vc_fd_locks = NULL;
+ }
+ mutex_unlock(&clnt_fd_lock);
+}
+
/*
* Create a client handle for a connection.
* Default options are set, which the user can change using clnt_control()'s.
diff --git a/src/svc.c b/src/svc.c
index 57f7ba3..b5f35c8 100644
--- a/src/svc.c
+++ b/src/svc.c
@@ -85,6 +85,25 @@ static void __xprt_do_unregister (SVCXPRT * xprt, bool_t dolock);
/* *************** SVCXPRT related stuff **************** */
+__attribute__((destructor))
+static void
+xprt_cleanup(void)
+{
+ rwlock_wrlock (&svc_fd_lock);
+ if (__svc_xports != NULL)
+ {
+ free (__svc_xports);
+ __svc_xports = NULL;
+ }
+ if (svc_pollfd != NULL)
+ {
+ free (svc_pollfd);
+ svc_pollfd = NULL;
+ svc_max_pollfd = 0;
+ }
+ rwlock_unlock (&svc_fd_lock);
+}
+
/*
* Activate a transport handle.
*/
--
2.26.2
next prev parent reply other threads:[~2020-07-22 5:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-22 5:34 [PATCH 0/5] libtirpc patches Doug Nazar
2020-07-22 5:34 ` [PATCH 1/5] svc_dg: Free xp_netid during destroy Doug Nazar
2020-07-22 5:34 ` [PATCH 2/5] svc: Batch allocations of pollfds Doug Nazar
2020-07-29 14:20 ` Steve Dickson
2020-07-22 5:34 ` Doug Nazar [this message]
2020-07-22 5:34 ` [PATCH 4/5] Add ability to detect if we're on the main thread Doug Nazar
2020-07-29 14:27 ` Steve Dickson
2020-07-22 5:34 ` [PATCH 5/5] Use static object on main thread, instead of thread specific data Doug Nazar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200722053445.27987-4-nazard@nazar.ca \
--to=nazard@nazar.ca \
--cc=libtirpc-devel@lists.sourceforge.net \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).