From: Fabian Keil Date: Sun, 7 Jun 2020 17:24:00 +0000 (+0200) Subject: get_clf_timestamp(): Fix locking of localtime() X-Git-Tag: v_3_0_29~285 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=326d2da979c442da79590d388cbfca249f55a103 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. --- 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) {