test showing address space leak in glibc 2.3.2 !!
Bruce Korb
bruce.korb@gmail.com
Thu Apr 10 22:51:00 GMT 2008
On Thu, Apr 10, 2008 at 1:55 PM, Ulrich Drepper <drepper@redhat.com> wrote:
> Take this elsewhere. It has nothing to do with glibc development.
Who else is doing the malloc code in glibc?
Here is a short program that shows the problem. I'm done now.
You can either fix it or not, but it is a malloc bug. Don't reply to me.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <pthread.h>
typedef void * (thread_base_fn_t)(void *);
pthread_mutex_t startmutex = PTHREAD_MUTEX_INITIALIZER;
int thdct = 0;
int thdno = 0;
static thread_base_fn_t get_mem, toss_mem;
int
main(int argc, char ** argv)
{
srand((int) time(NULL));
for (;;) {
pthread_t dummy;
if (pthread_create(&dummy, NULL, get_mem, NULL) != 0) {
fprintf(stderr, "pthread_create FAILED on thread #%d\n", thdno);
exit(1);
}
if (pthread_mutex_lock(&startmutex) != 0) abort();
thdct++;
pthread_mutex_unlock(&startmutex);
while (thdct >= 4)
sleep(1);
}
}
static void *
get_mem(void * arg)
{
pthread_t dummy;
unsigned int * mem = malloc(0x100);
int ct = 0x100 / sizeof(unsigned int);
unsigned int val = rand();
if (mem == NULL) {
fprintf(stderr, "MALLOC FAILED on thread #%d\n", thdno);
exit(1);
}
while (--ct >= 0)
mem[ct] = val;
if (pthread_create(&dummy, NULL, toss_mem, mem) != 0) {
fprintf(stderr, "PTHREAD_CREATE FAILED on thread #%d\n", thdno);
exit(1);
}
return NULL;
}
static void *
toss_mem(void * arg)
{
unsigned int * mem = arg;
unsigned int val = *mem;
free(arg);
if (pthread_mutex_lock(&startmutex) != 0) abort();
thdno++;
printf("th %5d %d -- 0x%08X\n", thdno, thdct, val);
thdct--;
pthread_mutex_unlock(&startmutex);
}
More information about the Libc-alpha
mailing list