aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-10-19 12:36:10 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-10-19 12:36:10 +0100
commit5a9e00e56e3bacefbfa52d9e099e195069fd50fb (patch)
treed865aee1e6a7a581c7b1eee4c28a48a6253cf1c9 /src
parent9821a9a62e615d9530d64dc4e5f76eddfe1cf8fd (diff)
downloadrspamd-5a9e00e56e3bacefbfa52d9e099e195069fd50fb.tar.gz
rspamd-5a9e00e56e3bacefbfa52d9e099e195069fd50fb.zip
[Minor] Switch to buffered IO + fix memory leak on reload
Diffstat (limited to 'src')
-rw-r--r--src/libserver/dynamic_cfg.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/libserver/dynamic_cfg.c b/src/libserver/dynamic_cfg.c
index e3ec39107..ab59b38dc 100644
--- a/src/libserver/dynamic_cfg.c
+++ b/src/libserver/dynamic_cfg.c
@@ -340,10 +340,17 @@ dump_dynamic_config (struct rspamd_config *cfg)
return FALSE;
}
+ struct ucl_emitter_functions *emitter_functions;
+ FILE *fp;
+
+ fp = fdopen (fd, "w");
+ emitter_functions = ucl_object_emit_file_funcs (fp);
+
if (!ucl_object_emit_full (cfg->current_dynamic_conf, UCL_EMIT_JSON,
- ucl_object_emit_fd_funcs (fd), NULL)) {
+ emitter_functions, NULL)) {
msg_err ("cannot emit ucl object: %s", strerror (errno));
- close (fd);
+ ucl_object_emit_funcs_free (emitter_functions);
+ fclose (fp);
return FALSE;
}
@@ -352,8 +359,10 @@ dump_dynamic_config (struct rspamd_config *cfg)
/* Rename old config */
if (rename (pathbuf, cfg->dynamic_conf) == -1) {
msg_err ("rename error: %s", strerror (errno));
- close (fd);
+ fclose (fp);
+ ucl_object_emit_funcs_free (emitter_functions);
unlink (pathbuf);
+
return FALSE;
}
/* Set permissions */
@@ -362,7 +371,9 @@ dump_dynamic_config (struct rspamd_config *cfg)
msg_warn ("chmod failed: %s", strerror (errno));
}
- close (fd);
+ fclose (fp);
+ ucl_object_emit_funcs_free (emitter_functions);
+
return TRUE;
}