diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-10-19 12:36:10 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-10-19 12:36:10 +0100 |
commit | 5a9e00e56e3bacefbfa52d9e099e195069fd50fb (patch) | |
tree | d865aee1e6a7a581c7b1eee4c28a48a6253cf1c9 /src | |
parent | 9821a9a62e615d9530d64dc4e5f76eddfe1cf8fd (diff) | |
download | rspamd-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.c | 19 |
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; } |