Fixed unsafe use of localtime

Since localtime is not thread-safe it should not be used in multithreaded
contexts. For this reason all calls to localtime were changed to localtime_r
in code where concurrency issues were possible.

Internal tests were left unchanged because they aren't multithreaded.
This commit is contained in:
Johan Wikman
2015-11-19 15:36:40 +02:00
committed by Markus Makela
parent 84d2c72db2
commit 6164b7f301
9 changed files with 43 additions and 51 deletions

View File

@ -639,7 +639,7 @@ size_t snprint_timestamp(
/** Generate timestamp */
t = time(NULL);
tm = *(localtime(&t));
localtime_r(&t, &tm);
snprintf(p_ts,
MIN(tslen,timestamp_len),
timestamp_formatstr,
@ -687,7 +687,7 @@ size_t snprint_timestamp_hp(
/** Generate timestamp */
gettimeofday(&tv,NULL);
tm = *(localtime(&tv.tv_sec));
localtime_r(&tv.tv_sec, &tm);
usec = tv.tv_usec/1000;
snprintf(p_ts,
MIN(tslen,timestamp_len_hp),
@ -1709,7 +1709,7 @@ static bool file_write_header(
t = (time_t *)malloc(sizeof(time_t));
tm = (struct tm *)malloc(sizeof(struct tm));
*t = time(NULL);
*tm = *localtime(t);
localtime_r(t, tm);
CHK_FILE(file);
header_buf1 = "\n\nMariaDB Corporation MaxScale\t";