From: Neil Horman Subject: [PATCH] libnuma: introduce DSO desctructor to free allocated memory Date: Mon, 10 Aug 2009 10:04:45 -0400 Message-ID: <20090810140445.GA14742@hmsreliant.think-freely.org> Mime-Version: 1.0 Return-path: Content-Disposition: inline Sender: linux-numa-owner@vger.kernel.org List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-numa@vger.kernel.org Cc: andi@firstfloor.org, clalance@redhat.com, nhorman@tuxdriver.com 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 Signed-off-by: Neil Horman Reported-by: Chris Lalancette Makefile | 2 +- libnuma.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff -up numactl-2.0.3/libnuma.c.orig numactl-2.0.3/libnuma.c --- numactl-2.0.3/libnuma.c.orig 2009-08-10 09:59:24.000000000 -0400 +++ numactl-2.0.3/libnuma.c 2009-08-10 10:00:40.000000000 -0400 @@ -95,6 +95,19 @@ 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); + if (nodes_allowed_list) + free(nodes_allowed_list); +} + /* * The following bitmask declarations, bitmask_*() routines, and associated * _setbit() and _getbit() routines are: diff -up numactl-2.0.3/Makefile.orig numactl-2.0.3/Makefile --- numactl-2.0.3/Makefile.orig 2009-06-10 08:30:03.000000000 -0400 +++ numactl-2.0.3/Makefile 2009-08-10 10:00:00.000000000 -0400 @@ -81,7 +81,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