threads/138603: localtime handles pthread errors badly
Mikulas Patocka
mikulas at artax.karlin.mff.cuni.cz
Mon Sep 7 00:00:06 UTC 2009
>Number: 138603
>Category: threads
>Synopsis: localtime handles pthread errors badly
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-threads
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Mon Sep 07 00:00:05 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator: Mikulas Patocka
>Release: 8.0-BETA3
>Organization:
>Environment:
not FreeBSD, I just use some of its libraries
>Description:
localtime function calls _pthread_key_create and treats negative value as an error.
In reality, _pthread_key_create return positive number on error and zero on non-error. _pthread_key_create doesn't set errno.
>How-To-Repeat:
Found during source review.
Could be triggered by filling-up the threadspecific key table and calling localtime().
>Fix:
A patch is attached.
Patch attached with submission follows:
--- libc.bak/stdtime/localtime.c 2009-08-03 10:13:06.000000000 +0200
+++ libc/stdtime/localtime.c 2009-09-07 01:48:32.000000000 +0200
@@ -23,6 +23,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
+#include <errno.h>
#include "private.h"
#include "un-namespace.h"
@@ -1418,8 +1419,10 @@
if (localtime_key < 0) {
_pthread_mutex_lock(&localtime_mutex);
if (localtime_key < 0) {
- if (_pthread_key_create(&localtime_key, free) < 0) {
+ int r;
+ if ((r = _pthread_key_create(&localtime_key, free))) {
_pthread_mutex_unlock(&localtime_mutex);
+ errno = r;
return(NULL);
}
}
@@ -1517,8 +1520,10 @@
if (gmtime_key < 0) {
_pthread_mutex_lock(&gmtime_mutex);
if (gmtime_key < 0) {
- if (_pthread_key_create(&gmtime_key, free) < 0) {
+ int r;
+ if ((r = _pthread_key_create(&gmtime_key, free))) {
_pthread_mutex_unlock(&gmtime_mutex);
+ errno = r;
return(NULL);
}
}
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-threads
mailing list