This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: test showing address space leak in glibc 2.3.2 !!


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);
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]