misc/185010: atexit() does not set errno on error
Jeremy Huddleston Sequoia
jeremyhu at apple.com
Thu Dec 19 20:30:00 UTC 2013
>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:
More information about the freebsd-bugs
mailing list