diff options
author | Ola Bini <ola@olabini.se> | 2016-01-12 14:29:21 -0500 |
---|---|---|
committer | Ola Bini <ola@olabini.se> | 2016-01-13 10:35:05 -0500 |
commit | 0bfa616e2e0ea7425801142e7faf7bca020f4361 (patch) | |
tree | fb0def3aecb4d408fd8284596e122806501f80b5 /src/common/log.c | |
parent | ce953b864b25d89ecd0c4441114cab50e394a7ef (diff) | |
download | tor-0bfa616e2e0ea7425801142e7faf7bca020f4361.tar.gz tor-0bfa616e2e0ea7425801142e7faf7bca020f4361.zip |
Remove a small memory leak in log callback setup
Diffstat (limited to 'src/common/log.c')
-rw-r--r-- | src/common/log.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/common/log.c b/src/common/log.c index 4a8a7b1165..02ad7142e2 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -889,6 +889,29 @@ add_temp_log(int min_severity) UNLOCK_LOGS(); } +#define CALLBACK_FILENAME "<callback>" + +/** + * Removes the latest log handler added, if that log handler is a callback + * handler. + */ +void +remove_log_callback(void) +{ + if(logfiles && !strcmp(logfiles->filename, CALLBACK_FILENAME)) { + logfile_t *lf = logfiles; + + LOCK_LOGS(); + logfiles = lf->next; + log_global_min_severity_ = get_min_log_level(); + UNLOCK_LOGS(); + + tor_free(lf->filename); + tor_free(lf->severities); + tor_free(lf); + } +} + /** * Add a log handler to send messages in <b>severity</b> * to the function <b>cb</b>. @@ -900,7 +923,7 @@ add_callback_log(const log_severity_list_t *severity, log_callback cb) lf = tor_malloc_zero(sizeof(logfile_t)); lf->fd = -1; lf->severities = tor_memdup(severity, sizeof(log_severity_list_t)); - lf->filename = tor_strdup("<callback>"); + lf->filename = tor_strdup(CALLBACK_FILENAME); lf->callback = cb; lf->next = logfiles; @@ -1378,4 +1401,3 @@ truncate_logs(void) } } } - |