This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH,RFA] Ensure check_may_shrink_heap always returns the final value
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: libc-alpha at sourceware dot org
- Date: Tue, 17 Sep 2013 19:49:43 -0300
- Subject: [PATCH,RFA] Ensure check_may_shrink_heap always returns the final value
- Authentication-results: sourceware.org; auth=none
check_may_shrink_heap's initialization of may_shrink_heap was racy;
before computing the final value of may_shrink_heap, it would store a
value in it that other threads would mistake as final. Fixed by using
a temporary automatic variable.
for ChangeLog:
* sysdeps/unix/sysv/linux/sysdep-malloc.h
(check_may_shrink_heap): Fix race condition in initialization.
---
sysdeps/unix/sysv/linux/malloc-sysdep.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/sysdeps/unix/sysv/linux/malloc-sysdep.h b/sysdeps/unix/sysv/linux/malloc-sysdep.h
index 737ca0e..346c93c 100644
--- a/sysdeps/unix/sysv/linux/malloc-sysdep.h
+++ b/sysdeps/unix/sysv/linux/malloc-sysdep.h
@@ -33,7 +33,8 @@
static inline bool
check_may_shrink_heap (void)
{
- static int may_shrink_heap = -1;
+ static int global_may_shrink_heap = -1;
+ int may_shrink_heap = global_may_shrink_heap;
if (__builtin_expect (may_shrink_heap >= 0, 1))
return may_shrink_heap;
@@ -53,6 +54,7 @@ check_may_shrink_heap (void)
}
}
+ global_may_shrink_heap = may_shrink_heap;
return may_shrink_heap;
}
--
Alexandre Oliva, freedom fighter http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/ FSF Latin America board member
Free Software Evangelist Red Hat Brazil Compiler Engineer