aboutsummaryrefslogtreecommitdiffstats
path: root/src/slibc-alloc.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@member.fsf.org>2016-01-01 17:55:37 +0100
committerMattias Andrée <maandree@member.fsf.org>2016-01-01 17:55:37 +0100
commit868abdea9811937039a1df84b15ad17f9b9c7a27 (patch)
treea7b98560d5eb155724663c4345283afbd68faa79 /src/slibc-alloc.c
parentm (diff)
downloadslibc-868abdea9811937039a1df84b15ad17f9b9c7a27.tar.gz
slibc-868abdea9811937039a1df84b15ad17f9b9c7a27.tar.bz2
slibc-868abdea9811937039a1df84b15ad17f9b9c7a27.tar.xz
extension: free will perserve errno
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
Diffstat (limited to 'src/slibc-alloc.c')
-rw-r--r--src/slibc-alloc.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/slibc-alloc.c b/src/slibc-alloc.c
index 2f51603..f93a4b5 100644
--- a/src/slibc-alloc.c
+++ b/src/slibc-alloc.c
@@ -58,15 +58,19 @@
* This function is identical to `free`, except it is guaranteed not to
* override the memory segment with zeroes before freeing the allocation.
*
+ * `errno` is guaranteed not to be set.
+ *
* @param segment The memory segment to free.
*
* @since Always.
*/
void fast_free(void* segment)
{
+ int saved_errno = errno;
if (segment == NULL)
return;
munmap(PURE_ALLOC(segment), PURE_SIZE(segment));
+ errno = saved_errno;
}
@@ -74,16 +78,20 @@ void fast_free(void* segment)
* This function is identical to `free`, except it is guaranteed to
* override the memory segment with zeroes before freeing the allocation.
*
+ * `errno` is guaranteed not to be set.
+ *
* @param segment The memory segment to free.
*
* @since Always.
*/
void secure_free(void* segment)
{
+ int saved_errno = errno;
if (segment == NULL)
return;
explicit_bzero(PURE_ALLOC(segment), PURE_SIZE(segment));
fast_free(segment);
+ errno = saved_errno;
}