Skip to contentSkip to conversation

libnuma: introduce DSO desctructor to free allocated memory

PATCH New Neil Horman 1 participant 1 message Aug 10, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libnuma: introduce DSO desctructor 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

 Makefile  |    2 +-
 libnuma.c |   13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
libnuma.c renamed from libnuma.c.orig +13 -0
diff -up numactl-2.0.3/libnuma.c.orig numactl-2.0.3/libnuma.c
@@ -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:
Makefile renamed from Makefile.orig +1 -1
diff -up numactl-2.0.3/Makefile.orig numactl-2.0.3/Makefile
@@ -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