1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-05 19:35:52 +03:00

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>
This commit is contained in:
Paul Eggert
2020-12-29 00:45:49 -08:00
parent 016c64236d
commit 69fda43b8d
4 changed files with 151 additions and 5 deletions

View File

@@ -3278,6 +3278,8 @@ __libc_free (void *mem)
*(volatile char *)mem;
#endif
int err = errno;
p = mem2chunk (mem);
/* Mark the chunk as belonging to the library again. */
@@ -3298,13 +3300,16 @@ __libc_free (void *mem)
mp_.mmap_threshold, mp_.trim_threshold);
}
munmap_chunk (p);
return;
}
else
{
MAYBE_INIT_TCACHE ();
ar_ptr = arena_for_chunk (p);
_int_free (ar_ptr, p, 0);
}
MAYBE_INIT_TCACHE ();
ar_ptr = arena_for_chunk (p);
_int_free (ar_ptr, p, 0);
__set_errno (err);
}
libc_hidden_def (__libc_free)