Skip to content

Commit

Permalink
Fix race in qsort_r initialization.
Browse files Browse the repository at this point in the history
(cherry picked from commit fb88ac7)
  • Loading branch information
Ulrich Drepper authored and Andreas Schwab committed Dec 13, 2010
1 parent 9796df9 commit 04d5ab1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2010-12-09 Ulrich Drepper <drepper@gmail.com>

[BZ #11655]
* stdlib/msort.c (qsort_r): Make sure both phys_pages and pagesize
are initialized.

2010-12-09 Jakub Jelinek <jakub@redhat.com>

* string/bits/string3.h (memmove, bcopy): Remove __restrict.
Expand Down
6 changes: 5 additions & 1 deletion stdlib/msort.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <unistd.h>
#include <memcopy.h>
#include <errno.h>
#include <atomic.h>

struct msort_param
{
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}

Expand Down

0 comments on commit 04d5ab1

Please sign in to comment.