summaryrefslogtreecommitdiff
path: root/src/gmalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gmalloc.c')
-rw-r--r--src/gmalloc.c22
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)