Loading...
src/malloc_exclaves.c libmalloc-646.40.3 libmalloc-657.80.3
--- libmalloc/libmalloc-646.40.3/src/malloc_exclaves.c
+++ libmalloc/libmalloc-657.80.3/src/malloc_exclaves.c
@@ -511,7 +511,12 @@
 	void *ptr = realloc(in_ptr, new_size);
 
 	if (!ptr && in_ptr && new_size != 0) {
+		// Save and restore `errno`, because `realloc` will set it to ENOMEM
+		// on allocation failure, but it could be overwritten if `free` calls
+		// into a library function that also modifies `errno`
+		errno_t error = errno;
 		free(in_ptr);
+		errno = error;
 	}
 
 	return ptr;