GNOME Bugzilla – Bug 511807
g_time_val_to_iso8601() uses MT-unsafe gmtime() function
Last modified: 2008-02-03 10:54:48 UTC
g_time_val_to_iso8601() currently calls gmtime() to get the time in UTC. This function is not MT safe as the result is stored in a static variable according to the glibc docs at least. Better would be, to use gmtime_r() which unfortunately is POSIX.1c, or another replacement that actually is MT safe.
But maybe this doesn't matter that much because the global static variable is stored in TLS but even then it can cause weird effects:
- Call of gmtime()
- Call of g_time_val_to_iso8601()
- The old result of gmtime() is overwritten and contains something unexpected
glibc docs about gmtime(): http://www.gnu.org/software/libc/manual/html_node/Broken_002ddown-Time.html#index-gmtime-2641
Sounds right that we should use gmtime_r if it is available, at least.
FYI, in the Microsoft C library gmtime_r() isn't available, but that doesn't matter much, as gmtime() is MT-safe, it uses thread-local storage.
(Of course, this doesn't help for the use case mentioned, "Call of gmtime(). Call of g_time_val_to_iso8601(). The old result of gmtime() is overwritten" but then people who call gmtime() and don't copy the result immediately afterwards probably deserve what they get anyway.)
2008-01-28 Matthias Clasen <firstname.lastname@example.org>
* configure.in: Check for gmtime_r.
* glib/gtimer.c: Use gmtime_r when available. (#511807,
Didn't you forget to commit the configure.in change?
Well, I added the check now in trunk.