mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 12:54:27 +00:00
tzcode: Avoid memory leak if pthread_setspecific() fails.
Reported by: Coverity (CID 1018472, 1018474) MFC after: 1 week Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D38036
This commit is contained in:
parent
3e2e5eebfa
commit
96e68c393f
|
@ -1761,7 +1761,10 @@ localtime(const time_t *timep)
|
|||
if ((p_tm = malloc(sizeof(*p_tm))) == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
_pthread_setspecific(localtime_key, p_tm);
|
||||
if (_pthread_setspecific(localtime_key, p_tm) != 0) {
|
||||
free(p_tm);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
return localtime_tzset(timep, p_tm, true);
|
||||
|
@ -1829,7 +1832,10 @@ gmtime(const time_t *timep)
|
|||
if ((p_tm = malloc(sizeof(*p_tm))) == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
_pthread_setspecific(gmtime_key, p_tm);
|
||||
if (_pthread_setspecific(gmtime_key, p_tm) != 0) {
|
||||
free(p_tm);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
return gmtime_r(timep, p_tm);
|
||||
|
|
Loading…
Reference in a new issue