[PATCH 3/5] Add destructor functions to cleanup static resources on exit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Doug Nazar <nazard@xxxxxxxx>
---
 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




[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux