LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-24-2004, 01:56 AM   #1
shy
Member
 
Registered: Dec 2002
Location: Russia
Distribution: ASP linux
Posts: 94

Rep: Reputation: 15
njamd shows leaks with pthreads


Hi.

Manpage for pthread_join() says
Quote:

When a joinable thread terminates, its memory resources
(thread descriptor and stack) are not deallocated until
another thread performs pthread_join on it. Therefore,
pthread_join must be called once for each joinable thread
created to avoid memory leaks.
However, I found that it does not deallocate the resources, at least in njamd's opinion (but I personally do beleive njamd). Does anyone know what it the reason and how to force the freeing?

The program:
Code:
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>

static void * test_thread (void * arg)
{
        printf ("thread started\n");
        pthread_exit(NULL);
}

int main (void)
{
        pthread_t thread_id;
        void * ptr;
        if (pthread_create (&thread_id, NULL, test_thread, NULL))
                goto thread_fail;
        pthread_join (thread_id, &ptr);
        printf ("good bye\n");
        return 0;

thread_fail:
        printf ("failed!!!\n");
        return 1;
}
That's how I run it:
Code:
LD_PRELOAD=libnjamd.so NJAMD_PROT=strict NJAMD_DUMP_LEAKS_ON_EXIT=3 ./a.out
And this is it's output:
Code:
thread started
good bye

0x4213c000-0x4213e000: Aligned len 68
   Allocation callstack:
        called from ./a.out(pthread_join+0x12e)[0x80484e2]
        called from /lib/tls/libc.so.6(__libc_start_main+0xe4)[0x420157a4]
        called from ./a.out(pthread_join+0x41)[0x80483f5]
   Not Freed

NJAMD totals:

        Allocation totals:              1 total, 1 leaked
        Leaked User Memory:             68 bytes
        Peak User Memory:               68 bytes
        NJAMD Overhead at peak:         7.934 kB
        Peak NJAMD Overhead:            7.934 kB
        Average NJAMD Overhead:         7.934 kB per alloc
        Address space used:             8.000 kB
        NJAMD Overhead at exit:         7.934 kB
 
Old 12-24-2004, 03:55 AM   #2
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
i guess it would be because of the manager thread that would be getting cleared after the main returns or calls exit.,..
 
Old 12-24-2004, 04:22 AM   #3
shy
Member
 
Registered: Dec 2002
Location: Russia
Distribution: ASP linux
Posts: 94

Original Poster
Rep: Reputation: 15
Well, it's obvious that exit() clears all the memory allocated by an application. But if you run an application that should run for a long time, and start/stop threads, eventually your application will eat all the available memory.
I would like to free all the allocation memory during the work of my program, not after it ends.
 
Old 12-24-2004, 04:46 AM   #4
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
what i am trying to say is memory is not being leaked as such...but maybe njamd is not being able to capture that piece of code and hence calls it a leak....if you see...try doing a malloc from a thread and free it...even then you'd see only one leak and two allocations.....if you are freeing all the memory that you have allocated..then you'd be fine...as you''ll see that 'your" threads arent leaking any memory...

i couild be wrong..but this is what i feel...it is just that the njamd might not be doing any check on the manager thread..and that is the memory i see getting "leaked"..it is the same amount of memory leaking no matter how many threads i run ...have you tried doing the same thing on 2.6 kernel? or on solaris perhaps...they dont have manager threads...maybe you'll get no leaks...

Last edited by shishir; 12-24-2004 at 04:58 AM.
 
Old 12-24-2004, 05:52 AM   #5
shy
Member
 
Registered: Dec 2002
Location: Russia
Distribution: ASP linux
Posts: 94

Original Poster
Rep: Reputation: 15
Thank you, I've checked, and it seems that only manager's memory leaks (because 68 leaked bytes don't depend on how many threads do I start).

Actually, I tested it on 2.6 kernel, but the kernel version alone isn't the case. I have old glibc without NPTL, so I get a manager thread and this leak.
 
Old 12-24-2004, 07:07 AM   #6
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
yeah you are right...nptl and glibc would be imp. and i am not sure that it is supported by 2.4 series..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to detect memory leaks abirami Linux - Networking 2 11-08-2004 05:35 AM
snmp staus shows it running but on trying MRTG, it shows public@ipaddr not giving res swati220781 Linux - Networking 3 07-08-2004 05:32 PM
desktop shows on TV but movie shows black screen litrelord Mandriva 6 07-05-2004 05:10 AM
Memmory Leaks? Evilone Linux - Software 4 04-27-2004 11:10 PM
Memory Leaks? stampede96 Linux - Software 3 02-20-2003 12:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration