get_clf_timestamp(): Fix locking of localtime()
authorFabian Keil <fk@fabiankeil.de>
Sun, 7 Jun 2020 17:24:00 +0000 (19:24 +0200)
committerFabian Keil <fk@fabiankeil.de>
Mon, 8 Jun 2020 13:40:09 +0000 (15:40 +0200)
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

index 8b12a43..7cc4e20 100644 (file)
--- 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)
    {