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{}
}