This is the mail archive of the newlib-cvs@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]

[newlib-cygwin] Fix atexit logic to honor _ATEXIT_DYNAMIC_ALLOC setting.


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=c2bbc54a62da248a1b828bb6c0518185be3324eb

commit c2bbc54a62da248a1b828bb6c0518185be3324eb
Author: Jeff Johnston <jjohnstn@redhat.com>
Date:   Mon Dec 21 11:53:14 2015 -0500

    Fix atexit logic to honor _ATEXIT_DYNAMIC_ALLOC setting.
    
    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.
    
    2015-12-21  Freddie Chopin  <freddie.chopin@gmail.com>
    
            * libc/stdlib/__atexit.c (__register_exitproc): Fix for
            _ATEXIT_DYNAMIC_ALLOC.

Diff:
---
 newlib/ChangeLog              | 5 +++++
 newlib/libc/stdlib/__atexit.c | 7 +++++++
 2 files changed, 12 insertions(+)

diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 480eb86..736def6 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,5 +1,10 @@
 2015-12-21  Freddie Chopin  <freddie.chopin@gmail.com>
 
+	* libc/stdlib/__atexit.c (__register_exitproc): Fix for
+	_ATEXIT_DYNAMIC_ALLOC.
+
+2015-12-21  Freddie Chopin  <freddie.chopin@gmail.com>
+
 	* libc/stdlib/on_exit_args.{c,h}: New files.
 	* libc/stdlib/Makefile.am: Add new source file.
 	* libc/stdlib/Makefile.in: Regenerate.
diff --git a/newlib/libc/stdlib/__atexit.c b/newlib/libc/stdlib/__atexit.c
index 23eab29..d07f6c1 100644
--- a/newlib/libc/stdlib/__atexit.c
+++ b/newlib/libc/stdlib/__atexit.c
@@ -131,6 +131,12 @@ _DEFUN (__register_exitproc,
       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);
 
@@ -144,6 +150,7 @@ _DEFUN (__register_exitproc,
 	  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]