get_locale_time(): Fix locking of localtime()
authorFabian Keil <fk@fabiankeil.de>
Sun, 7 Jun 2020 17:23:30 +0000 (19:23 +0200)
committerFabian Keil <fk@fabiankeil.de>
Mon, 8 Jun 2020 13:34:36 +0000 (15:34 +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.

cgi.c

diff --git a/cgi.c b/cgi.c
index 580e2bf..15ef256 100644 (file)
--- a/cgi.c
+++ b/cgi.c
@@ -1515,13 +1515,15 @@ static void get_locale_time(char *buf, size_t buffer_size)
 #elif defined(MUTEX_LOCKS_AVAILABLE)
    privoxy_mutex_lock(&localtime_mutex);
    timeptr = localtime(&current_time);
-   privoxy_mutex_unlock(&localtime_mutex);
 #else
    timeptr = localtime(&current_time);
 #endif
 
    strftime(buf, buffer_size, "%a %b %d %X %Z %Y", timeptr);
 
+#if !defined(HAVE_LOCALTIME_R) && defined(MUTEX_LOCKS_AVAILABLE)
+   privoxy_mutex_unlock(&localtime_mutex);
+#endif
 }