about summary refs log tree commit diff
path: root/manual
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2020-12-29 00:45:49 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2020-12-29 00:46:46 -0800
commit69fda43b8dd795c3658869633ca0708ed3134006 (patch)
treee86b216293d450bfbecaaf8230c3247444b668c4 /manual
parent016c64236dee6e28f09c10ba38f274aad7205f95 (diff)
downloadglibc-69fda43b8dd795c3658869633ca0708ed3134006.tar.gz
glibc-69fda43b8dd795c3658869633ca0708ed3134006.tar.xz
glibc-69fda43b8dd795c3658869633ca0708ed3134006.zip
free: preserve errno [BZ#17924]
In the next release of POSIX, free must preserve errno
<https://www.austingroupbugs.net/view.php?id=385>.
Modify __libc_free to save and restore errno, so that
any internal munmap etc. syscalls do not disturb the caller's errno.
Add a test malloc/tst-free-errno.c (almost all by Bruno Haible),
and document that free preserves errno.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'manual')
-rw-r--r--manual/memory.texi9
1 files changed, 9 insertions, 0 deletions
diff --git a/manual/memory.texi b/manual/memory.texi
index c132261084..b2cc65228a 100644
--- a/manual/memory.texi
+++ b/manual/memory.texi
@@ -738,6 +738,12 @@ later call to @code{malloc} to reuse the space.  In the meantime, the
 space remains in your program as part of a free-list used internally by
 @code{malloc}.
 
+The @code{free} function preserves the value of @code{errno}, so that
+cleanup code need not worry about saving and restoring @code{errno}
+around a call to @code{free}.  Although neither @w{ISO C} nor
+POSIX.1-2017 requires @code{free} to preserve @code{errno}, a future
+version of POSIX is planned to require it.
+
 There is no point in freeing blocks at the end of a program, because all
 of the program's space is given back to the system when the process
 terminates.
@@ -1935,6 +1941,9 @@ linking against @code{libc.a} (explicitly or implicitly).
 functions (that is, all the functions used by the application,
 @theglibc{}, and other linked-in libraries) can lead to static linking
 failures, and, at run time, to heap corruption and application crashes.
+Replacement functions should implement the behavior documented for
+their counterparts in @theglibc{}; for example, the replacement
+@code{free} should also preserve @code{errno}.
 
 The minimum set of functions which has to be provided by a custom
 @code{malloc} is given in the table below.