WG: missing TZ_LOCK

Corinna Vinschen vinschen@redhat.com
Tue Jun 28 10:11:00 GMT 2011


On Jun 27 10:54, Becker, Andreas wrote:
> Hi Folks,
> 
> We are using the localtime, mktime -  functions really heavy. Sometimes a miscalculation happened. 
> With hard investigations, we could verify that the problem is a missing lock around the global __tzinfo_type *tz structure.  
> This structure is returned by __gettzinfo() and changed by __tz_calc_limits(year) .
> Operations on this structure should be protected by TZ_LOCK() and TZ_UNLOCK(). 
> This is correctly done in (newlib/time/) mktm_r.c, tzset_r.c and strftime.c but missing in mktime.c
> 
> --- a/newlib/libc/time/mktime.c Mon Jun 28 11:00:35 2010 +0200
> +++ b/newlib/libc/time/mktime.c Mon Jun 27 10:18:58 2011 +0200
> @@ -204,6 +204,8 @@
> 
>    isdst = tim_p->tm_isdst;
> 
> +  TZ_LOCK;
> +    
>    if (_daylight)
>      {
>        int y = tim_p->tm_year + YEAR_BASE;
> @@ -251,6 +253,8 @@
>    else /* otherwise assume std time */
>      tim += (time_t) tz->__tzrule[0].offset;
> 
> +  TZ_UNLOCK;
> +  
>    /* reset isdst flag to what we have calculated */
>    tim_p->tm_isdst = isdst;

Thanks for catching this.  I applied your patch.


Corinna

-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat



More information about the Newlib mailing list