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;
newind = oldind = choose_arena()->ind;
WRITE(oldind, unsigned);
READ(newind, unsigned);
WRITE(newind, unsigned);
READ(oldind, unsigned);
if (newind != oldind) {
arena_t *arena;

View File

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