summaryrefslogtreecommitdiff
path: root/src/gmalloc.c
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-08-19 16:48:59 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-08-19 16:48:59 -0700
commit07fcbb558d797272b9f43547da60beda485873a3 (patch)
tree77d5da14e9f9d9d8b1d877c70c01296fd3893796 /src/gmalloc.c
parentc9bdeff3e45a7ac84a74a81bb048046f82dddc91 (diff)
parentfb81c8c3adf8633f2f617c82f6019aef630860c7 (diff)
downloademacs-07fcbb558d797272b9f43547da60beda485873a3.tar.gz
Merge remote-tracking branch 'origin/master' into athena/unstable
Diffstat (limited to 'src/gmalloc.c')
-rw-r--r--src/gmalloc.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/gmalloc.c b/src/gmalloc.c
index 66008ea69b2..55ae7365d99 100644
--- a/src/gmalloc.c
+++ b/src/gmalloc.c
@@ -1690,16 +1690,6 @@ valloc (size_t size)
#undef free
#ifdef HYBRID_MALLOC
-/* Declare system malloc and friends. */
-extern void *malloc (size_t size);
-extern void *realloc (void *ptr, size_t size);
-extern void *calloc (size_t nmemb, size_t size);
-extern void free (void *ptr);
-#ifdef HAVE_ALIGNED_ALLOC
-extern void *aligned_alloc (size_t alignment, size_t size);
-#elif defined HAVE_POSIX_MEMALIGN
-extern int posix_memalign (void **memptr, size_t alignment, size_t size);
-#endif
/* Assuming PTR was allocated via the hybrid malloc, return true if
PTR was allocated via gmalloc, not the system malloc. Also, return
@@ -1736,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);
@@ -1745,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)