diff options
author | Eli Zaretskii <eliz@gnu.org> | 2021-05-20 11:44:54 +0300 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2021-05-20 11:44:54 +0300 |
commit | 328efb47d04e3aa996bb8cd387d01c1a66ec29f5 (patch) | |
tree | af1c147167f2f02896209d3a439bb6589387a16c /src/gmalloc.c | |
parent | b2eed2ae568b53ac910f4a3b8458eedf8d8c67ec (diff) | |
download | emacs-328efb47d04e3aa996bb8cd387d01c1a66ec29f5.tar.gz |
Make sure gmalloc's hybrid_free preserves errno
* src/gmalloc.c (hybrid_free_1): New function, with the body of
the previous 'hybrid_free'.
(hybrid_free): Call 'hybrid_free_1' while preserving the value of
'errno'. Suggested by Paul Eggert <eggert@cs.ucla.edu>.
Diffstat (limited to 'src/gmalloc.c')
-rw-r--r-- | src/gmalloc.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/gmalloc.c b/src/gmalloc.c index dedd25fa22f..55ae7365d99 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c @@ -1726,8 +1726,8 @@ hybrid_calloc (size_t nmemb, size_t size) return gcalloc (nmemb, size); } -void -hybrid_free (void *ptr) +static void +hybrid_free_1 (void *ptr) { if (allocated_via_gmalloc (ptr)) gfree (ptr); @@ -1735,6 +1735,24 @@ hybrid_free (void *ptr) free (ptr); } +void +hybrid_free (void *ptr) +{ + /* Stolen from Gnulib, to make sure we preserve errno. */ +#if defined __GNUC__ && !defined __clang__ + int err[2]; + err[0] = errno; + err[1] = errno; + errno = 0; + hybrid_free_1 (ptr); + errno = err[errno == 0]; +#else + int err = errno; + hybrid_free_1 (ptr); + errno = err; +#endif +} + #if defined HAVE_ALIGNED_ALLOC || defined HAVE_POSIX_MEMALIGN void * hybrid_aligned_alloc (size_t alignment, size_t size) |