dovecot-2.0: Memory leak fixes.

dovecot at dovecot.org dovecot at dovecot.org
Fri May 15 23:47:20 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/b66054f9b8fb
changeset: 9300:b66054f9b8fb
user:      Timo Sirainen <tss at iki.fi>
date:      Fri May 15 16:47:14 2009 -0400
description:
Memory leak fixes.

diffstat:

6 files changed, 39 insertions(+), 11 deletions(-)
src/lib-master/master-service-settings.c |    5 +++--
src/lib-master/master-service.c          |    5 +++++
src/lib-settings/settings-parser.c       |    3 +++
src/lib-storage/mail-storage-service.c   |   19 ++++++++++++++++---
src/lib-storage/mail-storage-service.h   |    4 ++++
src/util/doveadm.c                       |   14 ++++++++------

diffs (165 lines):

diff -r 602adc1f2f83 -r b66054f9b8fb src/lib-master/master-service-settings.c
--- a/src/lib-master/master-service-settings.c	Fri May 15 16:46:51 2009 -0400
+++ b/src/lib-master/master-service-settings.c	Fri May 15 16:47:14 2009 -0400
@@ -195,9 +195,10 @@ int master_service_settings_read(struct 
 			return -1;
 	}
 
-	if (service->set_pool != NULL)
+	if (service->set_pool != NULL) {
+		settings_parser_deinit(&service->set_parser);
 		p_clear(service->set_pool);
-	else {
+	} else {
 		service->set_pool =
 			pool_alloconly_create("master service settings", 4096);
 	}
diff -r 602adc1f2f83 -r b66054f9b8fb src/lib-master/master-service.c
--- a/src/lib-master/master-service.c	Fri May 15 16:46:51 2009 -0400
+++ b/src/lib-master/master-service.c	Fri May 15 16:47:14 2009 -0400
@@ -8,6 +8,7 @@
 #include "home-expand.h"
 #include "restrict-access.h"
 #include "fd-close-on-exec.h"
+#include "settings-parser.h"
 #include "syslog-util.h"
 #include "master-service-private.h"
 #include "master-service-settings.h"
@@ -436,6 +437,10 @@ void master_service_deinit(struct master
 	if (array_is_created(&service->config_overrides))
 		array_free(&service->config_overrides);
 
+	if (service->set_parser != NULL) {
+		settings_parser_deinit(&service->set_parser);
+		pool_unref(&service->set_pool);
+	}
 	lib_signals_deinit();
 	io_loop_destroy(&service->ioloop);
 
diff -r 602adc1f2f83 -r b66054f9b8fb src/lib-settings/settings-parser.c
--- a/src/lib-settings/settings-parser.c	Fri May 15 16:46:51 2009 -0400
+++ b/src/lib-settings/settings-parser.c	Fri May 15 16:47:14 2009 -0400
@@ -113,6 +113,7 @@ settings_parser_init_list(pool_t set_poo
 
 	i_assert(count > 0);
 
+	pool_ref(set_pool);
 	parser_pool = pool_alloconly_create("settings parser", 8192);
 	ctx = p_new(parser_pool, struct setting_parser_context, 1);
 	ctx->set_pool = set_pool;
@@ -1095,6 +1096,7 @@ settings_parser_dup(struct setting_parse
 	void *key, *value;
 	unsigned int i;
 
+	pool_ref(new_pool);
 	new_ctx = p_new(new_pool, struct setting_parser_context, 1);
 	new_ctx->set_pool = new_pool;
 	new_ctx->parser_pool = pool_alloconly_create("settings parser", 2048);
@@ -1134,5 +1136,6 @@ settings_parser_dup(struct setting_parse
 				  new_link);
 	}
 	hash_table_iterate_deinit(&iter);
+	hash_table_destroy(&links);
 	return new_ctx;
 }
diff -r 602adc1f2f83 -r b66054f9b8fb src/lib-storage/mail-storage-service.c
--- a/src/lib-storage/mail-storage-service.c	Fri May 15 16:46:51 2009 -0400
+++ b/src/lib-storage/mail-storage-service.c	Fri May 15 16:47:14 2009 -0400
@@ -683,13 +683,24 @@ int mail_storage_service_multi_next(stru
 	return 0;
 }
 
+void mail_storage_service_multi_user_free(struct mail_storage_service_multi_user *user)
+{
+	settings_parser_deinit(&user->set_parser);
+}
+
+unsigned int
+mail_storage_service_multi_all_init(struct mail_storage_service_multi_ctx *ctx)
+{
+	if (ctx->auth_list != NULL)
+		(void)auth_master_user_list_deinit(&ctx->auth_list);
+	ctx->auth_list = auth_master_user_list_init(ctx->conn);
+	return auth_master_user_list_count(ctx->auth_list);
+}
+
 int mail_storage_service_multi_all_next(struct mail_storage_service_multi_ctx *ctx,
 					const char **username_r)
 {
 	i_assert((ctx->flags & MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP) != 0);
-
-	if (ctx->auth_list == NULL)
-		ctx->auth_list = auth_master_user_list_init(ctx->conn);
 
 	*username_r = auth_master_user_list_next(ctx->auth_list);
 	if (*username_r != NULL)
@@ -702,6 +713,8 @@ void mail_storage_service_multi_deinit(s
 	struct mail_storage_service_multi_ctx *ctx = *_ctx;
 
 	*_ctx = NULL;
+	if (ctx->auth_list != NULL)
+		(void)auth_master_user_list_deinit(&ctx->auth_list);
 	if (ctx->conn != NULL)
 		auth_master_deinit(&ctx->conn);
 	i_free(ctx);
diff -r 602adc1f2f83 -r b66054f9b8fb src/lib-storage/mail-storage-service.h
--- a/src/lib-storage/mail-storage-service.h	Fri May 15 16:46:51 2009 -0400
+++ b/src/lib-storage/mail-storage-service.h	Fri May 15 16:47:14 2009 -0400
@@ -47,6 +47,10 @@ int mail_storage_service_multi_next(stru
 				    struct mail_storage_service_multi_user *user,
 				    struct mail_user **mail_user_r,
 				    const char **error_r);
+void mail_storage_service_multi_user_free(struct mail_storage_service_multi_user *user);
+/* Initialize iterating through all users. Return the number of users. */
+unsigned int
+mail_storage_service_multi_all_init(struct mail_storage_service_multi_ctx *ctx);
 /* Iterate through all usernames. Returns 1 if username was returned, 0 if
    there are no more users, -1 if error. */
 int mail_storage_service_multi_all_next(struct mail_storage_service_multi_ctx *ctx,
diff -r 602adc1f2f83 -r b66054f9b8fb src/util/doveadm.c
--- a/src/util/doveadm.c	Fri May 15 16:46:51 2009 -0400
+++ b/src/util/doveadm.c	Fri May 15 16:47:14 2009 -0400
@@ -140,8 +140,10 @@ handle_next_user(struct mail_storage_ser
 	if (mail_storage_service_multi_next(multi, multi_user,
 					    &mail_user, &error) < 0) {
 		i_error("User init failed: %s", error);
+		mail_storage_service_multi_user_free(multi_user);
 		return -1;
 	}
+	mail_storage_service_multi_user_free(multi_user);
 	handle_command(mail_user, argv[0], argv+1);
 	mail_user_unref(&mail_user);
 	return 0;
@@ -175,12 +177,6 @@ handle_all_users(struct master_service *
 	
 	user_idx = 0;
 	while ((ret = mail_storage_service_multi_all_next(multi, &user)) > 0) {
-		if (killed_signo != 0) {
-			/* killed by a signal */
-			i_warning("Killed with signal %d", killed_signo);
-			ret = -1;
-			break;
-		}
 		p_clear(pool);
 		input.username = user;
 		T_BEGIN {
@@ -194,6 +190,11 @@ handle_all_users(struct master_service *
 				fflush(stdout);
 			}
 		}
+		if (killed_signo != 0) {
+			i_warning("Killed with signal %d", killed_signo);
+			ret = -1;
+			break;
+		}
 	}
 	if ((service_flags & MAIL_STORAGE_SERVICE_FLAG_DEBUG) != 0)
 		printf("\n");
@@ -201,6 +202,7 @@ handle_all_users(struct master_service *
 	if (ret < 0)
 		i_error("Failed to iterate through some users");
 	mail_storage_service_multi_deinit(&multi);
+	pool_unref(&pool);
 }
 
 int main(int argc, char *argv[])


More information about the dovecot-cvs mailing list