diff options
author | Ulrich Drepper <drepper@gmail.com> | 2010-12-09 12:12:58 -0500 |
---|---|---|
committer | Petr Baudis <pasky@suse.cz> | 2011-02-03 16:38:57 +0100 |
commit | b6995df5132e877faf6a7c48e77561c92c60f011 (patch) | |
tree | d1d57db00d70fb79f1638917e4c891edbcb9cfb6 /stdlib | |
parent | 2796cd94a85e1d6a5acb2a86e2c6cc41abc33efa (diff) | |
download | glibc-b6995df5132e877faf6a7c48e77561c92c60f011.tar.gz glibc-b6995df5132e877faf6a7c48e77561c92c60f011.tar.xz glibc-b6995df5132e877faf6a7c48e77561c92c60f011.zip |
Fix race in qsort_r initialization.
(cherry picked from commit fb88ac72c2dcbbd979c8798e4ea497818bb3e171)
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/msort.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/stdlib/msort.c b/stdlib/msort.c index 35cd4d0311..fc58f0d417 100644 --- a/stdlib/msort.c +++ b/stdlib/msort.c @@ -25,6 +25,7 @@ #include <unistd.h> #include <memcopy.h> #include <errno.h> +#include <atomic.h> struct msort_param { @@ -182,7 +183,7 @@ qsort_r (void *b, size_t n, size_t s, __compar_d_fn_t cmp, void *arg) static long int phys_pages; static int pagesize; - if (phys_pages == 0) + if (pagesize == 0) { phys_pages = __sysconf (_SC_PHYS_PAGES); @@ -197,6 +198,9 @@ qsort_r (void *b, size_t n, size_t s, __compar_d_fn_t cmp, void *arg) a quarter of the physical memory. */ phys_pages /= 4; + /* Make sure phys_pages is written to memory. */ + atomic_write_barrier (); + pagesize = __sysconf (_SC_PAGESIZE); } |