From 326d2da979c442da79590d388cbfca249f55a103 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Sun, 7 Jun 2020 19:24:00 +0200 Subject: [PATCH] get_clf_timestamp(): Fix locking of localtime() Previously we were only locking the actual localtime() call while we should keep the lock until the returned pointer is no longer being used. --- errlog.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/errlog.c b/errlog.c index 8b12a436..7cc4e200 100644 --- a/errlog.c +++ b/errlog.c @@ -539,7 +539,6 @@ static inline size_t get_clf_timestamp(char *buffer, size_t buffer_size) #elif defined(MUTEX_LOCKS_AVAILABLE) privoxy_mutex_lock(&localtime_mutex); tm_now = localtime(&now); - privoxy_mutex_unlock(&localtime_mutex); #else tm_now = localtime(&now); #endif @@ -548,6 +547,9 @@ static inline size_t get_clf_timestamp(char *buffer, size_t buffer_size) mins = hrs * 60 + tm_now->tm_min - gmt.tm_min; length = strftime(buffer, buffer_size, "%d/%b/%Y:%H:%M:%S ", tm_now); +#if !defined(HAVE_LOCALTIME_R) && defined(MUTEX_LOCKS_AVAILABLE) + privoxy_mutex_unlock(&localtime_mutex); +#endif if (length > (size_t)0) { -- 2.39.2