diff options
author | Roger Dingledine <arma@torproject.org> | 2004-09-23 04:59:02 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2004-09-23 04:59:02 +0000 |
commit | a1979800abcb170ebc185987b83a770c70905848 (patch) | |
tree | 59e9580bda03be2557028fb433f39afddffee4a5 /src/common/log.c | |
parent | 8727a281196a581d5932a5d04ce3981e9616db80 (diff) | |
download | tor-a1979800abcb170ebc185987b83a770c70905848.tar.gz tor-a1979800abcb170ebc185987b83a770c70905848.zip |
bugfix on the bugfix
actually unlink the log entry.
ok, that wasn't cleverly hidden enough. let's try again.
svn:r2367
Diffstat (limited to 'src/common/log.c')
-rw-r--r-- | src/common/log.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/common/log.c b/src/common/log.c index ce7e7b68b2..bdbb488ade 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -51,7 +51,10 @@ static INLINE const char *sev_to_string(int severity) { /** Linked list of logfile_t. */ static logfile_t *logfiles = NULL; -static INLINE size_t _log_prefix(char *buf, size_t buf_len, int severity) +static void delete_log(logfile_t *victim); + +static INLINE size_t +_log_prefix(char *buf, size_t buf_len, int severity) { time_t t; struct timeval now; @@ -159,10 +162,7 @@ logv(int severity, const char *funcname, const char *format, va_list ap) /* don't log the error! Blow away this log entry and continue. */ logfile_t *victim = lf; lf = victim->next; - if(victim == logfiles) - logfiles = lf; - tor_free(victim->filename); - tor_free(victim); + delete_log(victim); } else { lf = lf->next; } @@ -212,10 +212,7 @@ void reset_logs() /* error. don't log it. delete the log entry and continue. */ logfile_t *victim = lf; lf = victim->next; - if(victim == logfiles) - logfiles = lf; - tor_free(victim->filename); - tor_free(victim); + delete_log(victim); continue; } else { log_tor_version(lf, 1); @@ -225,6 +222,24 @@ void reset_logs() } } +/** Remove and free the log entry <b>victim</b> from the linked-list + * logfiles (it must be present in the list when this function is + * called). After this function is called, the caller shouldn't refer + * to <b>victim</b> anymore. + */ +static void delete_log(logfile_t *victim) { + logfile_t *tmpl; + if(victim == logfiles) + logfiles = victim->next; + else { + for(tmpl = logfiles; tmpl && tmpl->next != victim; tmpl=tmpl->next) ; + tor_assert(tmpl->next == victim); + tmpl->next = victim->next; + } + tor_free(victim->filename); + tor_free(victim); +} + /** Add a log handler to send all messages of severity <b>loglevel</b> * or higher to <b>stream</b>. */ void add_stream_log(int loglevelMin, int loglevelMax, const char *name, FILE *stream) |