[dovecot-cvs] dovecot/src/lib module-dir.c,1.28,1.29

tss at dovecot.org tss at dovecot.org
Fri Feb 16 17:55:44 UTC 2007


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv14655

Modified Files:
	module-dir.c 
Log Message:
module_dir_init() was calling the init() functions in reverse order.



Index: module-dir.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/module-dir.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- module-dir.c	16 Feb 2007 13:12:15 -0000	1.28
+++ module-dir.c	16 Feb 2007 17:55:42 -0000	1.29
@@ -180,7 +180,7 @@
 	struct dirent *d;
 	const char *name, *path, *p, *stripped_name, **names_p;
 	const char **module_names_arr;
-	struct module *modules, *module;
+	struct module *modules, *module, **module_pos;
 	unsigned int i, count;
 	ARRAY_TYPE(const_string) names;
 	pool_t pool;
@@ -235,6 +235,8 @@
 				module_file_get_name(module_names_arr[i]);
 		}
 	}
+
+	module_pos = &modules;
 	for (i = 0; i < count; i++) {
 		const char *name = names_p[i];
 
@@ -252,8 +254,8 @@
 		t_pop();
 
 		if (module != NULL) {
-			module->next = modules;
-			modules = module;
+			*module_pos = module;
+			module_pos = &module->next;
 		}
 	}
 	if (module_names_arr != NULL) {
@@ -286,14 +288,27 @@
 
 void module_dir_deinit(struct module *modules)
 {
-	struct module *module;
+	struct module *module, **rev;
+	unsigned int i, count = 0;
+
+	for (module = modules; module != NULL; module = module->next)
+		count++;
+
+	/* @UNSAFE: deinitialize in reverse order */
+	t_push();
+	rev = t_new(struct module *, count);
+	for (i = 0, module = modules; i < count; i++, module = module->next)
+		rev[count-i-1] = module;
+
+	for (i = 0; i < count; i++) {
+		module = rev[i];
 
-	for (module = modules; module != NULL; module = module->next) {
 		if (module->deinit != NULL) {
 			module->deinit();
 			module->deinit = NULL;
 		}
 	}
+	t_pop();
 }
 
 void module_dir_unload(struct module **modules)



More information about the dovecot-cvs mailing list