[netfilter-cvslog] r3366 - in trunk/nfsim: core kernelenv

rusty at netfilter.org rusty at netfilter.org
Tue Dec 14 05:55:22 CET 2004


Author: rusty at netfilter.org
Date: 2004-12-14 05:55:21 +0100 (Tue, 14 Dec 2004)
New Revision: 3366

Modified:
   trunk/nfsim/core/core.c
   trunk/nfsim/core/core.h
   trunk/nfsim/kernelenv/kernelenv.c
Log:
Move create_device() prototype out to header.
Use talloc to check allocations at exit time; centralize declarations.


Modified: trunk/nfsim/core/core.c
===================================================================
--- trunk/nfsim/core/core.c	2004-12-14 04:52:48 UTC (rev 3365)
+++ trunk/nfsim/core/core.c	2004-12-14 04:55:21 UTC (rev 3366)
@@ -73,8 +73,6 @@
 
 LIST_HEAD(interfaces);
 
-/* From tools/ifconfig.c */
-extern struct net_device *create_device(const char *name, int argc, char **);
 struct net_device *loopback_dev_p;
 
 static void core_init(void)
@@ -246,6 +244,7 @@
 	message_cleanup();
 	tui_cleanup(termfd);
 	unload_all_modules();
+	check_allocations();
 
 	return 0;
 }

Modified: trunk/nfsim/core/core.h
===================================================================
--- trunk/nfsim/core/core.h	2004-12-14 04:52:48 UTC (rev 3365)
+++ trunk/nfsim/core/core.h	2004-12-14 04:55:21 UTC (rev 3366)
@@ -260,6 +260,11 @@
 bool load_all_modules(void);
 void unload_all_modules(void);
 
+void check_allocations(void);
+
+/* tools/ifconfig.c: used to create initial devices. */
+struct net_device *create_device(const char *name, int argc, char **);
+
 /* init code */
 typedef void (*initcall_t)(void);
 #define init_call(fn) \

Modified: trunk/nfsim/kernelenv/kernelenv.c
===================================================================
--- trunk/nfsim/kernelenv/kernelenv.c	2004-12-14 04:52:48 UTC (rev 3365)
+++ trunk/nfsim/kernelenv/kernelenv.c	2004-12-14 04:55:21 UTC (rev 3366)
@@ -22,6 +22,9 @@
 #include <kernelenv.h>
 #include "utils.h"
 
+/* Root of talloc trees for different allocators */
+void *__skb_ctx, *__vmalloc_ctx, *__kmalloc_ctx, *__kmalloc_atomic_ctx, *__kmem_cache_ctx;
+
 unsigned long num_physpages = 1024;
 
 int init_timers(void);
@@ -40,8 +43,6 @@
 }
 	
 /* skbuff */
-static void *__skb_ctx;
-
 struct sk_buff *alloc_skb(unsigned int size, int gfp_mask)
 {
 	struct sk_buff *skb;
@@ -496,7 +497,7 @@
 {
 	kmem_cache_t *cache;
 
-	cache = talloc(NULL, kmem_cache_t);
+	cache = talloc(__kmem_cache_ctx, kmem_cache_t);
 	cache->name = name;
 	cache->objsize = objsize;
 	cache->ctor = ctor;
@@ -540,8 +541,6 @@
 	panic("[cache] attempting to free non-cache memory\n");
 }
 
-void *__vmalloc_ctx, *__kmalloc_ctx, *__kmalloc_atomic_ctx;
-
 void kernelenv_init(void)
 {
 	__vmalloc_ctx = talloc_named_const(NULL, 1, "vmallocs");
@@ -549,4 +548,33 @@
 	__kmalloc_atomic_ctx = talloc_named_const(NULL, 1,
 						  "kmallocs (atomic)");
 	__skb_ctx = talloc_named_const(NULL, 1, "skbs");
+	__kmem_cache_ctx = talloc_named_const(NULL, 1, "kmem caches");
 }
+
+void check_allocations(void)
+{
+	int fail = 0;
+	if (talloc_total_blocks(__vmalloc_ctx) != 1) {
+		talloc_report_full(__vmalloc_ctx, stderr);
+		fail = 1;
+	}
+	if (talloc_total_blocks(__kmalloc_ctx) != 1) {
+		talloc_report_full(__kmalloc_ctx, stderr);
+		fail = 1;
+	}
+	if (talloc_total_blocks(__kmalloc_atomic_ctx) != 1) {
+		talloc_report_full(__kmalloc_atomic_ctx, stderr);
+		fail = 1;
+	}
+	if (talloc_total_blocks(__skb_ctx) != 1) {
+		talloc_report_full(__skb_ctx, stderr);
+		fail = 1;
+	}
+	if (talloc_total_blocks(__kmem_cache_ctx) != 1) {
+		talloc_report_full(__kmem_cache_ctx, stderr);
+		fail = 1;
+	}
+
+	if (fail)
+		barf("Memory leak");
+}




More information about the netfilter-cvslog mailing list