Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 19 Dec 2013 20:27:28 GMT
From:      Jeremy Huddleston Sequoia <jeremyhu@apple.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   misc/185010: atexit() does not set errno on error
Message-ID:  <201312192027.rBJKRSJR038481@oldred.freebsd.org>
Resent-Message-ID: <201312192030.rBJKU0N8091531@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         185010
>Category:       misc
>Synopsis:       atexit() does not set errno on error
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 19 20:30:00 UTC 2013
>Closed-Date:
>Last-Modified:
>Originator:     Jeremy Huddleston Sequoia
>Release:        HEAD
>Organization:
Apple Inc
>Environment:
N/A
>Description:
On error, atexit() should return -1 and set errno appropriately, but I just noticed that is not being done.

http://svnweb.freebsd.org/base/head/lib/libc/stdlib/atexit.c?revision=259042&view=markup

Notice that on malloc error, -1 is returned, but errno is not set.

>How-To-Repeat:
I have not seen it in practice.  Memory pressure with an appropriately timed atexit() will result in a -1 return value with an invalid errno set.
>Fix:
This is a modified diff against our (Apple) atexit.c which is based on your (FreeBSD) atexit.c:

Index: atexit.c
===================================================================
--- atexit.c	(revision 98115)
+++ atexit.c	(working copy)
@@ -37,6 +37,7 @@
 __FBSDID("$FreeBSD: src/lib/libc/stdlib/atexit.c,v 1.8 2007/01/09 00:28:09 imp Exp $");
 
 #include "namespace.h"
+#include <errno.h>
 #include <stddef.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -121,8 +125,10 @@
 		struct atexit *old__atexit;
 		old__atexit = __atexit;
 	        _MUTEX_UNLOCK(&atexit_mutex);
-		if ((p = (struct atexit *)malloc(sizeof(*p))) == NULL)
+		if ((p = (struct atexit *)malloc(sizeof(*p))) == NULL) {
+			errno = ENOMEM;
 			return (-1);
+                }
 		_MUTEX_LOCK(&atexit_mutex);
 		if (old__atexit != __atexit) {
 			/* Lost race, retry operation */


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201312192027.rBJKRSJR038481>