This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix for _ATEXIT_DYNAMIC_ALLOC in __register_exitproc()


>From 337a0bbbad8d5a48c2bd6246ab6b8d2b52fda7ac Sat, 12 Dec 2015 15:07:53 +0100
From: Freddie Chopin <freddie.chopin@gmail.com>
Date: Sat, 12 Dec 2015 12:45:53 +0100
Subject: [PATCH] Fix for _ATEXIT_DYNAMIC_ALLOC in __register_exitproc()


If small reent is enabled (_REENT_SMALL is defined) then malloc() was
used in __register_exitproc() even if user requested it to be disabled
(_ATEXIT_DYNAMIC_ALLOC is defined). With this fix, function fails when
_ATEXIT_DYNAMIC_ALLOC is defined and whole static storage is already
used.

This fix has one potential downside. on_exit() and __cxa_atexit()
functions require additional storage for function arguments. In case of
small reent this storage is _NOT_ part of the _atexit struct and it was
always allocated with malloc(). With this fix, all on_exit() and all
__cxa_atexit() calls will fail.

        * libc/stdlib/__atexit.c (__register_exitproc): Fix for
        _ATEXIT_DYNAMIC_ALLOC.

diff --git a/newlib/libc/stdlib/__atexit.c b/newlib/libc/stdlib/__atexit.c
index a3d5bdf..949c6ba 100644
--- a/newlib/libc/stdlib/__atexit.c
+++ b/newlib/libc/stdlib/__atexit.c
@@ -124,6 +124,12 @@
       args = p->_on_exit_args_ptr;
       if (args == NULL)
 	{
+#ifndef _ATEXIT_DYNAMIC_ALLOC
+#ifndef __SINGLE_THREAD__
+	  __lock_release_recursive(__atexit_lock);
+#endif
+	  return -1;
+#else
 	  if (malloc)
 	    args = malloc (sizeof * p->_on_exit_args_ptr);
 
@@ -137,6 +143,7 @@
 	  args->_fntypes = 0;
 	  args->_is_cxa = 0;
 	  p->_on_exit_args_ptr = args;
+#endif
 	}
 #else
       args = &p->_on_exit_args;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]