Fix a "thread.arena" mallctl bug.

Fix a variable reversal bug in mallctl("thread.arena", ...).
This commit is contained in:
Jason Evans 2011-03-14 11:39:49 -07:00
parent 814b9bda7f
commit a7153a0d7d
2 changed files with 26 additions and 16 deletions

View File

@ -1114,8 +1114,8 @@ thread_arena_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
unsigned newind, oldind; unsigned newind, oldind;
newind = oldind = choose_arena()->ind; newind = oldind = choose_arena()->ind;
WRITE(oldind, unsigned); WRITE(newind, unsigned);
READ(newind, unsigned); READ(oldind, unsigned);
if (newind != oldind) { if (newind != oldind) {
arena_t *arena; arena_t *arena;

View File

@ -2,10 +2,13 @@
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h> #include <pthread.h>
#include <string.h> #include <string.h>
#include <assert.h>
#define JEMALLOC_MANGLE #define JEMALLOC_MANGLE
#include "jemalloc_test.h" #include "jemalloc_test.h"
#define NTHREADS 10
void * void *
thread_start(void *arg) thread_start(void *arg)
{ {
@ -29,6 +32,15 @@ thread_start(void *arg)
return (void *)1; return (void *)1;
} }
size = sizeof(arena_ind);
if ((err = JEMALLOC_P(mallctl)("thread.arena", &arena_ind, &size, NULL,
0))) {
fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__,
strerror(err));
return (void *)1;
}
assert(arena_ind == main_arena_ind);
return (NULL); return (NULL);
} }
@ -40,7 +52,8 @@ main(void)
unsigned arena_ind; unsigned arena_ind;
size_t size; size_t size;
int err; int err;
pthread_t thread; pthread_t threads[NTHREADS];
unsigned i;
fprintf(stderr, "Test begin\n"); fprintf(stderr, "Test begin\n");
@ -60,21 +73,18 @@ main(void)
goto RETURN; goto RETURN;
} }
if (pthread_create(&thread, NULL, thread_start, (void *)&arena_ind) for (i = 0; i < NTHREADS; i++) {
!= 0) { if (pthread_create(&threads[i], NULL, thread_start,
fprintf(stderr, "%s(): Error in pthread_create()\n", __func__); (void *)&arena_ind) != 0) {
ret = 1; fprintf(stderr, "%s(): Error in pthread_create()\n",
goto RETURN; __func__);
ret = 1;
goto RETURN;
}
} }
pthread_join(thread, (void *)&ret);
if (pthread_create(&thread, NULL, thread_start, (void *)&arena_ind) for (i = 0; i < NTHREADS; i++)
!= 0) { pthread_join(threads[i], (void *)&ret);
fprintf(stderr, "%s(): Error in pthread_create()\n", __func__);
ret = 1;
goto RETURN;
}
pthread_join(thread, (void *)&ret);
RETURN: RETURN:
fprintf(stderr, "Test end\n"); fprintf(stderr, "Test end\n");