From owner-freebsd-threads@FreeBSD.ORG Mon Sep 7 00:00:06 2009 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 14AEE1065672 for ; Mon, 7 Sep 2009 00:00:06 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id DB7BD8FC18 for ; Mon, 7 Sep 2009 00:00:05 +0000 (UTC) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n870052m096801 for ; Mon, 7 Sep 2009 00:00:05 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n87005wa096800; Mon, 7 Sep 2009 00:00:05 GMT (envelope-from gnats) Resent-Date: Mon, 7 Sep 2009 00:00:05 GMT Resent-Message-Id: <200909070000.n87005wa096800@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-threads@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Mikulas Patocka Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EF4781065670 for ; Sun, 6 Sep 2009 23:56:45 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id DEC1F8FC1D for ; Sun, 6 Sep 2009 23:56:45 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n86Nujnu005674 for ; Sun, 6 Sep 2009 23:56:45 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id n86Nujih005656; Sun, 6 Sep 2009 23:56:45 GMT (envelope-from nobody) Message-Id: <200909062356.n86Nujih005656@www.freebsd.org> Date: Sun, 6 Sep 2009 23:56:45 GMT From: Mikulas Patocka To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: threads/138603: localtime handles pthread errors badly X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Sep 2009 00:00:06 -0000 >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 #include #include +#include #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: