Date: Mon, 10 Aug 2009 10:04:45 -0400
From: Neil Horman <nhorman@tuxdriver.com>
To: linux-numa@vger.kernel.org
Subject: [PATCH] libnuma: introduce DSO destructor to free allocated memory

Hey-
	Patch to add a destructor to libnuma so that we can free the memory we
allocate in numa_init.  Without this various debug tools report leaked memory on
the unloading of the DSO

Neil


And, as Lee Shermerhorn observed, nodes_allowed_list is removed.  So all
references to it are removed. (Cliff)

Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Reported-by: Chris Lalancette <clalance@redhat.com>

 Makefile          |    2 +-
 libnuma.c         |   11 +++++++++++
 numa.h            |    2 --
 versions.ldscript |    1 -
 4 files changed, 12 insertions(+), 4 deletions(-)

Index: numactl-dev/libnuma.c
===================================================================
--- numactl-dev.orig/libnuma.c
+++ numactl-dev/libnuma.c
@@ -93,6 +93,17 @@ numa_init(void)
 	memset(&numa_no_nodes, 0, sizeof(numa_no_nodes));
 }
 
+void
+numa_fini(void)
+{
+	if (numa_all_cpus_ptr)
+		numa_bitmask_free(numa_all_cpus_ptr);
+	if (numa_all_nodes_ptr)
+		numa_bitmask_free(numa_all_nodes_ptr);
+	if (numa_no_nodes_ptr)
+		numa_bitmask_free(numa_no_nodes_ptr);
+}
+
 /*
  * The following bitmask declarations, bitmask_*() routines, and associated
  * _setbit() and _getbit() routines are:
Index: numactl-dev/Makefile
===================================================================
--- numactl-dev.orig/Makefile
+++ numactl-dev/Makefile
@@ -82,7 +82,7 @@ stream_main.o: stream_main.c
 libnuma.so.1: versions.ldscript
 
 libnuma.so.1: libnuma.o syscall.o distance.o
-	${CC} ${LDFLAGS} -shared -Wl,-soname=libnuma.so.1 -Wl,--version-script,versions.ldscript -Wl,-init,numa_init -o libnuma.so.1 $(filter-out versions.ldscript,$^)
+	${CC} ${LDFLAGS} -shared -Wl,-soname=libnuma.so.1 -Wl,--version-script,versions.ldscript -Wl,-init,numa_init -Wl,-fini,numa_fini -o libnuma.so.1 $(filter-out versions.ldscript,$^)
 
 libnuma.so: libnuma.so.1
 	ln -sf libnuma.so.1 libnuma.so
Index: numactl-dev/numa.h
===================================================================
--- numactl-dev.orig/numa.h
+++ numactl-dev/numa.h
@@ -161,8 +161,6 @@ extern struct bitmask *numa_no_nodes_ptr
 /* Source compatibility */
 extern nodemask_t numa_no_nodes;
 
-extern char *nodes_allowed_list;
-
 /* Only run and allocate memory from a specific set of nodes. */
 void numa_bind(struct bitmask *nodes);
 
Index: numactl-dev/versions.ldscript
===================================================================
--- numactl-dev.orig/versions.ldscript
+++ numactl-dev/versions.ldscript
@@ -144,7 +144,6 @@ libnuma_1.2 {
     numa_tonode_memory;
     numa_tonodemask_memory;
     numa_warn;
-    nodes_allowed_list;
   local:
     *;
 } libnuma_1.1;
