dovecot-2.2: module_dir_deinit(): If no modules were actually in...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Nov 6 23:50:10 EET 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/6fc2502d6021
changeset: 15388:6fc2502d6021
user: Timo Sirainen <tss at iki.fi>
date: Tue Nov 06 23:49:24 2012 +0200
description:
module_dir_deinit(): If no modules were actually initialized, avoid doing memory allocation.
This allows calling module_dir_unload() with atexit(), as long as the module
doesn't need to call deinit().
diffstat:
src/lib/module-dir.c | 19 +++++++++++--------
1 files changed, 11 insertions(+), 8 deletions(-)
diffs (42 lines):
diff -r 2d0d0318b341 -r 6fc2502d6021 src/lib/module-dir.c
--- a/src/lib/module-dir.c Tue Nov 06 23:23:19 2012 +0200
+++ b/src/lib/module-dir.c Tue Nov 06 23:49:24 2012 +0200
@@ -494,8 +494,10 @@
struct module *module, **rev;
unsigned int i, count = 0;
- for (module = modules; module != NULL; module = module->next)
- count++;
+ for (module = modules; module != NULL; module = module->next) {
+ if (module->deinit != NULL && module->initialized)
+ count++;
+ }
if (count == 0)
return;
@@ -503,18 +505,19 @@
/* @UNSAFE: deinitialize in reverse order */
T_BEGIN {
rev = t_new(struct module *, count);
- for (i = 0, module = modules; i < count; i++) {
- rev[count-i-1] = module;
+ for (i = 0, module = modules; i < count; ) {
+ if (module->deinit != NULL && module->initialized) {
+ rev[count-i-1] = module;
+ i++;
+ }
module = module->next;
}
for (i = 0; i < count; i++) {
module = rev[i];
- if (module->deinit != NULL && module->initialized) {
- module->deinit();
- module->initialized = FALSE;
- }
+ module->deinit();
+ module->initialized = FALSE;
}
} T_END;
}
More information about the dovecot-cvs
mailing list