dmalloc flags unfreed pthread mem

This is a discussion on dmalloc flags unfreed pthread mem within the C Programming forums, part of the General Programming Boards category; hi, i'm currently checking my pthreaded c code for memory leaks using dmalloc. it finds 8160 bytes of unfreed memory ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    351

    dmalloc flags unfreed pthread mem

    hi,

    i'm currently checking my pthreaded c code for memory leaks using dmalloc.

    it finds 8160 bytes of unfreed memory allocated by, it seems,
    pthread_initialize_manager.

    am i not cleaning up properly?

    i don't use pthread_attr_init - i use null in pthread_create.

    TIA rotis23

    note: i've removed error handling!

    i use pthread_exit(NULL); in thread_function when the thread has finished its work

    Code:
            pthread_t a_thread[5];
            void *thread_result;
    
            //add multiple threads
            for(lots_of_threads = 0; lots_of_threads < 5; lots_of_threads++)
            {
                    //threads are created and started
                    res = pthread_create(&(a_thread[lots_of_threads]), NULL, thread_function, (void *)lots_of_threads);
                    if (res != 0){}
            }
    
            //wait for threads to finish and clean up
            for(lots_of_threads = 5- 1; lots_of_threads >= 0; lots_of_threads--)
            {
                    res = pthread_join(a_thread[lots_of_threads], &thread_result);
                    if (res == 0)
                    {
                                    printf("Picked up a thread\n");
                    }
                    else{}
            }

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    its not allocated on a per thread basis according to the dmalloc log file.

    its sayes the memory address was only called once. (i.e. to malloc) hence initialisation manager name.

    looking at example code, i'm not aware of missing any cleanup.

    this is nothing compared to the leaks i've found with using the mysql c api library. to be fair its the libraries that IT links with. mainly elf stuff like dl-load.c, dl-version.c and naming stuff like nsswitch.c.

    it seems strange that these libraries are released with leaks. hence why i think its something i'm doing/not doing.

    at least its not overflows!!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21