Fix memory leak if ALL_STATE and multithreaded.

* localtime.c (gmtcheck) [ALL_STATE]: Don't leak memory if two
threads invoke this function nearly simultaneously.
Problem reported by Andy Heninger in:
http://mm.icann.org/pipermail/tz/2014-September/021599.html
* NEWS: Document this.
This commit is contained in:
Paul Eggert
2014-09-21 17:03:52 -07:00
parent 8dd540a1e5
commit 0eb01e8a0c
2 changed files with 10 additions and 4 deletions
+4
View File
@@ -30,6 +30,10 @@ Unreleased, experimental changes
An access to uninitalized data has been fixed.
(Thanks to Jörg Richter for reporting the problem.)
A memory leak has been fixed if ALL_STATE and THREAD_SAFE are defined
and two threads race to initialize data used by gmtime-like functions.
(Thanks to Andy Heninger for reporting the problem.)
Changes affecting build procedure
'make check' now checks better for properly-sorted data.
+6 -4
View File
@@ -1249,12 +1249,14 @@ gmtcheck(void)
return;
if (lock() != 0)
return;
if (! gmt_is_set) {
#ifdef ALL_STATE
gmtptr = malloc(sizeof *gmtptr);
gmtptr = malloc(sizeof *gmtptr);
#endif
if (gmtptr)
gmtload(gmtptr);
gmt_is_set = true;
if (gmtptr)
gmtload(gmtptr);
gmt_is_set = true;
}
unlock();
}