diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-02-11 13:41:31 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-02-11 13:41:31 -0500 |
commit | fed8c5199a9fbc91a7476323c145c59e9e30e30c (patch) | |
tree | d1d45808191b6a1931eaa7a1b455870e0c34e55e /src/common/log.c | |
parent | 5a164d50bbfd66ef51408794d03c8db8071ddabb (diff) | |
parent | a7a98e27eadff634655a7845976adc7a23dcdc3f (diff) | |
download | tor-fed8c5199a9fbc91a7476323c145c59e9e30e30c.tar.gz tor-fed8c5199a9fbc91a7476323c145c59e9e30e30c.zip |
Merge branch 'check_log_mutex_uncherrypicked'
Diffstat (limited to 'src/common/log.c')
-rw-r--r-- | src/common/log.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/common/log.c b/src/common/log.c index 4a8a7b1165..4779751543 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -149,10 +149,14 @@ static int pretty_fn_has_parens = 0; /** Lock the log_mutex to prevent others from changing the logfile_t list */ #define LOCK_LOGS() STMT_BEGIN \ + tor_assert(log_mutex_initialized); \ tor_mutex_acquire(&log_mutex); \ STMT_END /** Unlock the log_mutex */ -#define UNLOCK_LOGS() STMT_BEGIN tor_mutex_release(&log_mutex); STMT_END +#define UNLOCK_LOGS() STMT_BEGIN \ + tor_assert(log_mutex_initialized); \ + tor_mutex_release(&log_mutex); \ + STMT_END /** What's the lowest log level anybody cares about? Checking this lets us * bail out early from log_debug if we aren't debugging. */ @@ -482,9 +486,12 @@ logv,(int severity, log_domain_mask_t domain, const char *funcname, /* check that severity is sane. Overrunning the masks array leads to * interesting and hard to diagnose effects */ assert(severity >= LOG_ERR && severity <= LOG_DEBUG); + /* check that we've initialised the log mutex before we try to lock it */ + assert(log_mutex_initialized); LOCK_LOGS(); - if ((! (domain & LD_NOCB)) && smartlist_len(pending_cb_messages)) + if ((! (domain & LD_NOCB)) && pending_cb_messages + && smartlist_len(pending_cb_messages)) flush_pending_log_callbacks(); if (queue_startup_messages && @@ -939,7 +946,7 @@ flush_pending_log_callbacks(void) smartlist_t *messages, *messages_tmp; LOCK_LOGS(); - if (0 == smartlist_len(pending_cb_messages)) { + if (!pending_cb_messages || 0 == smartlist_len(pending_cb_messages)) { UNLOCK_LOGS(); return; } |