Skip to content
Snippets Groups Projects
Commit d9a4b77a authored by Stephan Bosch's avatar Stephan Bosch Committed by Timo Sirainen
Browse files

lib-sieve-tool: sieve-tool - Use pool

parent 892240b3
No related branches found
No related tags found
No related merge requests found
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
*/ */
struct sieve_tool { struct sieve_tool {
pool_t pool;
char *name; char *name;
bool no_config; bool no_config;
...@@ -143,6 +144,7 @@ sieve_tool_init(const char *name, int *argc, char **argv[], ...@@ -143,6 +144,7 @@ sieve_tool_init(const char *name, int *argc, char **argv[],
MASTER_SERVICE_FLAG_STANDALONE | MASTER_SERVICE_FLAG_STANDALONE |
MASTER_SERVICE_FLAG_DONT_SEND_STATS | MASTER_SERVICE_FLAG_DONT_SEND_STATS |
MASTER_SERVICE_FLAG_NO_INIT_DATASTACK_FRAME; MASTER_SERVICE_FLAG_NO_INIT_DATASTACK_FRAME;
pool_t pool;
if (no_config) if (no_config)
service_flags |= MASTER_SERVICE_FLAG_NO_CONFIG_SETTINGS; service_flags |= MASTER_SERVICE_FLAG_NO_CONFIG_SETTINGS;
...@@ -150,11 +152,13 @@ sieve_tool_init(const char *name, int *argc, char **argv[], ...@@ -150,11 +152,13 @@ sieve_tool_init(const char *name, int *argc, char **argv[],
master_service = master_service_init(name, service_flags, master_service = master_service_init(name, service_flags,
argc, argv, getopt_str); argc, argv, getopt_str);
tool = i_new(struct sieve_tool, 1); pool = pool_alloconly_create("sieve tool", 8192);
tool->name = i_strdup(name); tool = p_new(pool, struct sieve_tool, 1);
tool->pool = pool;
tool->name = p_strdup(tool->pool, name);
tool->no_config = no_config; tool->no_config = no_config;
i_array_init(&tool->sieve_plugins, 16); p_array_init(&tool->sieve_plugins, pool, 16);
return tool; return tool;
} }
...@@ -172,17 +176,17 @@ int sieve_tool_getopt(struct sieve_tool *tool) ...@@ -172,17 +176,17 @@ int sieve_tool_getopt(struct sieve_tool *tool)
"duplicate -x option specified, " "duplicate -x option specified, "
"but only one allowed."); "but only one allowed.");
} }
tool->sieve_extensions = i_strdup(optarg); tool->sieve_extensions = p_strdup(tool->pool, optarg);
break; break;
case 'u': case 'u':
if (tool->username == NULL) if (tool->username == NULL)
tool->username = i_strdup(optarg); tool->username = p_strdup(tool->pool, optarg);
break; break;
case 'P': { case 'P': {
/* Plugin */ /* Plugin */
const char *plugin; const char *plugin;
plugin = t_strdup(optarg); plugin = p_strdup(tool->pool, optarg);
array_append(&tool->sieve_plugins, &plugin, 1); array_append(&tool->sieve_plugins, &plugin, 1);
break; break;
} }
...@@ -239,11 +243,9 @@ sieve_tool_init_finish(struct sieve_tool *tool, bool init_mailstore, ...@@ -239,11 +243,9 @@ sieve_tool_init_finish(struct sieve_tool *tool, bool init_mailstore,
if (username == NULL) { if (username == NULL) {
sieve_tool_get_user_data(&username, &homedir); sieve_tool_get_user_data(&username, &homedir);
username = tool->username = i_strdup(username); username = tool->username = p_strdup(tool->pool, username);
if (tool->homedir != NULL) tool->homedir = p_strdup(tool->pool, homedir);
i_free(tool->homedir);
tool->homedir = i_strdup(homedir);
if (preserve_root) { if (preserve_root) {
storage_service_flags |= storage_service_flags |=
...@@ -313,17 +315,6 @@ void sieve_tool_deinit(struct sieve_tool **_tool) ...@@ -313,17 +315,6 @@ void sieve_tool_deinit(struct sieve_tool **_tool)
/* Deinitialize Sieve engine */ /* Deinitialize Sieve engine */
sieve_deinit(&tool->svinst); sieve_deinit(&tool->svinst);
/* Free options */
if (tool->username != NULL)
i_free(tool->username);
if (tool->homedir != NULL)
i_free(tool->homedir);
if (tool->sieve_extensions != NULL)
i_free(tool->sieve_extensions);
array_free(&tool->sieve_plugins);
/* Free raw mail */ /* Free raw mail */
if (tool->mail_raw != NULL) if (tool->mail_raw != NULL)
...@@ -343,8 +334,7 @@ void sieve_tool_deinit(struct sieve_tool **_tool) ...@@ -343,8 +334,7 @@ void sieve_tool_deinit(struct sieve_tool **_tool)
/* Free sieve tool object */ /* Free sieve tool object */
i_free(tool->name); pool_unref(&tool->pool);
i_free(tool);
/* Deinitialize service */ /* Deinitialize service */
master_service_deinit(&master_service); master_service_deinit(&master_service);
...@@ -428,14 +418,10 @@ sieve_tool_open_data_as_mail(struct sieve_tool *tool, string_t *mail_data) ...@@ -428,14 +418,10 @@ sieve_tool_open_data_as_mail(struct sieve_tool *tool, string_t *mail_data)
void sieve_tool_set_homedir(struct sieve_tool *tool, const char *homedir) void sieve_tool_set_homedir(struct sieve_tool *tool, const char *homedir)
{ {
if (tool->homedir != NULL) { if (tool->homedir != NULL && strcmp(homedir, tool->homedir) == 0)
if (strcmp(homedir, tool->homedir) == 0) return;
return;
i_free(tool->homedir);
}
tool->homedir = i_strdup(homedir); tool->homedir = p_strdup(tool->pool, homedir);
if (tool->mail_user_dovecot != NULL) if (tool->mail_user_dovecot != NULL)
mail_user_set_home(tool->mail_user_dovecot, tool->homedir); mail_user_set_home(tool->mail_user_dovecot, tool->homedir);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.