LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > AIX
User Name
Password
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.

Notices

Reply
 
LinkBack Search this Thread
Old 03-05-2010, 04:39 AM   #1
visionofarun
LQ Newbie
 
Registered: Mar 2010
Posts: 1

Rep: Reputation: 0
valgrind - pthread memory leaks on AIX


Hi all,

I have written a small code just to invoke main and return immediately. When built with libpthread on AIX box, valgrind throws lots of memory leak errors. But when built without libpthread, no issues at all.

Here is the sample run for your look. Any idea where I might be going wrong?

Code:
On IBM AIX UNIX 5.1
03:23:36 ~/Arun$ cat dummy.c
int main()
{
        return 0;
}
03:23:36 ~/Arun$ gcc -o dummy dummy.c -Wall
03:23:23 ~/Arun$ valgrind --leak-check=full --show-reachable=yes ./dummy
==473082== Memcheck, a memory error detector.
==473082== Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward et al.
==473082== Using LibVEX rev 1884, a library for dynamic binary translation.
==473082== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
==473082== Using valgrind-3.4.1, a dynamic binary instrumentation framework.
==473082== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.
==473082== For more details, rerun with: -v
==473082==
==473082==
==473082== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==473082== malloc/free: in use at exit: 0 bytes in 0 blocks.
==473082== malloc/free: 0 allocs, 0 frees, 0 bytes allocated.
==473082== For counts of detected errors, rerun with: -v
==473082== All heap blocks were freed -- no leaks are possible.

Absolutely no leaks in the above run. But when built with -lpthread, valgrind throws a big list of memory leak for the same dummy.c. See the following.

03:24:50 ~/Arun$ gcc -o dummy dummy.c -Wall -lpthread
03:27:30 ~/Arun$ valgrind --leak-check=full --show-reachable=yes ./dummy
==172006== Memcheck, a memory error detector.
==172006== Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward et al.
==172006== Using LibVEX rev 1884, a library for dynamic binary translation.
==172006== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
==172006== Using valgrind-3.4.1, a dynamic binary instrumentation framework.
==172006== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.
==172006== For more details, rerun with: -v
==172006==
==172006==
==172006== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 272 from 4)
==172006== malloc/free: in use at exit: 32,260 bytes in 73 blocks.
==172006== malloc/free: 75 allocs, 2 frees, 37,292 bytes allocated.
==172006== For counts of detected errors, rerun with: -v
==172006== searching for pointers to 73 not-freed blocks.
==172006== checked 9,271,124 bytes.
==172006==
==172006== 12 bytes in 1 blocks are still reachable in loss record 1 of 9
==172006==    at 0xD0E2B5B0: malloc (vg_replace_malloc.c:207)
==172006==    by 0xD005276F: _cleanup_push_72_6 (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0xD0050E5B: pthread_once (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0xD02E7D67: __getpwent_tsd_callback (in /usr/lib/libc.a(shr.o))
==172006==    by 0xD02E7893: _libc_inline_callbacks (in /usr/lib/libc.a(shr.o))
==172006==    by 0xD02E7827: _libc_declare_data_functions (in /usr/lib/libc.a(shr.o))
==172006==    by 0xD006AA4F: _pth_init_libc (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0xD004A0FB: __pth_init (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0x10000353: call_pth_init (in /proc/172006/object/a.out)
==172006==    by 0x1000026B: __threads_init (in /proc/172006/object/a.out)
==172006==    by 0xD02E6EFF: __modinit (in /usr/lib/libc.a(shr.o))
==172006==    by 0x100001AB: (below main) (in /proc/172006/object/a.out)
==172006==
==172006==
==172006== 56 bytes in 2 blocks are still reachable in loss record 2 of 9
==172006==    at 0xD0E2B5B0: malloc (vg_replace_malloc.c:207)
==172006==    by 0xD0068E7B: pthread_atfork (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0xD004A0AB: __pth_init (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0x10000353: call_pth_init (in /proc/172006/object/a.out)
==172006==    by 0x1000026B: __threads_init (in /proc/172006/object/a.out)
==172006==    by 0xD02E6EFF: __modinit (in /usr/lib/libc.a(shr.o))
==172006==    by 0x100001AB: (below main) (in /proc/172006/object/a.out)
==172006==
==172006==
==172006== 208 bytes in 1 blocks are still reachable in loss record 3 of 9
==172006==    at 0xD0E2B5B0: malloc (vg_replace_malloc.c:207)
==172006==    by 0xD006C08B: _lib_rwlock_init (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0xD0297E5F: _rec_rwlock_init_21_7 (in /usr/lib/libc.a(shr.o))
==172006==    by 0xD029DDEB: _libc_locks_init (in /usr/lib/libc.a(shr.o))
==172006==    by 0xD02975A7: _libc_declare_lock_functions (in /usr/lib/libc.a(shr.o))
==172006==    by 0xD006AA43: _pth_init_libc (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0xD004A0FB: __pth_init (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0x10000353: call_pth_init (in /proc/172006/object/a.out)
==172006==    by 0x1000026B: __threads_init (in /proc/172006/object/a.out)
==172006==    by 0xD02E6EFF: __modinit (in /usr/lib/libc.a(shr.o))
==172006==    by 0x100001AB: (below main) (in /proc/172006/object/a.out)
==172006==
==172006==
==172006== 1,800 bytes in 1 blocks are still reachable in loss record 4 of 9
==172006==    at 0xD0E2B5B0: malloc (vg_replace_malloc.c:207)
==172006==    by 0xD006962F: _pth_init_key (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0xD004A07F: __pth_init (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0x10000353: call_pth_init (in /proc/172006/object/a.out)
==172006==    by 0x1000026B: __threads_init (in /proc/172006/object/a.out)
==172006==    by 0xD02E6EFF: __modinit (in /usr/lib/libc.a(shr.o))
==172006==    by 0x100001AB: (below main) (in /proc/172006/object/a.out)
==172006==
==172006==
==172006== 4,096 bytes in 1 blocks are still reachable in loss record 5 of 9
==172006==    at 0xD0E2B5B0: malloc (vg_replace_malloc.c:207)
==172006==    by 0xD00695EB: _pth_init_key (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0xD004A07F: __pth_init (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0x10000353: call_pth_init (in /proc/172006/object/a.out)
==172006==    by 0x1000026B: __threads_init (in /proc/172006/object/a.out)
==172006==    by 0xD02E6EFF: __modinit (in /usr/lib/libc.a(shr.o))
==172006==    by 0x100001AB: (below main) (in /proc/172006/object/a.out)
==172006==
==172006==
==172006== 5,224 bytes in 1 blocks are still reachable in loss record 6 of 9
==172006==    at 0xD0E2B5B0: malloc (vg_replace_malloc.c:207)
==172006==    by 0xD004BFAF: _alloc_initial_pthread (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0xD004A067: __pth_init (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0x10000353: call_pth_init (in /proc/172006/object/a.out)
==172006==    by 0x1000026B: __threads_init (in /proc/172006/object/a.out)
==172006==    by 0xD02E6EFF: __modinit (in /usr/lib/libc.a(shr.o))
==172006==    by 0x100001AB: (below main) (in /proc/172006/object/a.out)
==172006==
==172006==
==172006== 5,376 bytes in 8 blocks are still reachable in loss record 7 of 9
==172006==    at 0xD0E2B5B0: malloc (vg_replace_malloc.c:207)
==172006==    by 0xD0049DDF: __pth_init (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0x10000353: call_pth_init (in /proc/172006/object/a.out)
==172006==    by 0x1000026B: __threads_init (in /proc/172006/object/a.out)
==172006==    by 0xD02E6EFF: __modinit (in /usr/lib/libc.a(shr.o))
==172006==    by 0x100001AB: (below main) (in /proc/172006/object/a.out)
==172006==
==172006==
==172006== 7,296 bytes in 57 blocks are still reachable in loss record 8 of 9
==172006==    at 0xD0E2B5B0: malloc (vg_replace_malloc.c:207)
==172006==    by 0xD0047F73: _lib_spinlock_create (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0xD029DE13: _libc_locks_init (in /usr/lib/libc.a(shr.o))
==172006==    by 0xD02975A7: _libc_declare_lock_functions (in /usr/lib/libc.a(shr.o))
==172006==    by 0xD006AA43: _pth_init_libc (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0xD004A0FB: __pth_init (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0x10000353: call_pth_init (in /proc/172006/object/a.out)
==172006==    by 0x1000026B: __threads_init (in /proc/172006/object/a.out)
==172006==    by 0xD02E6EFF: __modinit (in /usr/lib/libc.a(shr.o))
==172006==    by 0x100001AB: (below main) (in /proc/172006/object/a.out)
==172006==
==172006==
==172006== 8,192 bytes in 1 blocks are still reachable in loss record 9 of 9
==172006==    at 0xD0E2B5B0: malloc (vg_replace_malloc.c:207)
==172006==    by 0xD005B847: _vp_create_locked (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0xD005BAEF: _vp_create (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0xD004C1CF: _alloc_initial_pthread (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0xD004A067: __pth_init (in /usr/lib/libpthread.a(shr_xpg5.o))
==172006==    by 0x10000353: call_pth_init (in /proc/172006/object/a.out)
==172006==    by 0x1000026B: __threads_init (in /proc/172006/object/a.out)
==172006==    by 0xD02E6EFF: __modinit (in /usr/lib/libc.a(shr.o))
==172006==    by 0x100001AB: (below main) (in /proc/172006/object/a.out)
==172006==
==172006== LEAK SUMMARY:
==172006==    definitely lost: 0 bytes in 0 blocks.
==172006==      possibly lost: 0 bytes in 0 blocks.
==172006==    still reachable: 32,260 bytes in 73 blocks.
==172006==         suppressed: 0 bytes in 0 blocks.
03:27:38 ~/Arun$

What is going wrong?! Same is the case with any multithreaded application that I wrote on this AIX box!
Thanks
Arun

Last edited by visionofarun; 03-15-2010 at 06:11 AM.
 
Old 04-23-2010, 06:20 AM   #2
anubhuti_k
LQ Newbie
 
Registered: Oct 2004
Location: India
Distribution: Suse 9.1
Posts: 29

Rep: Reputation: 15
Hi Arun,

As far as I know, pthread library on AIX does some pre allocations for efficiency purposes.
They preallocate the resources, and keep a pool of them. They use objects from that pool as and when needed and then return that back to the pool. This strategy is efficient in scenarios where resources are frequently allocated and freed, because they dont go thru the hazzles of malloc and free every time.

Thats why u r seeing leaks, but as such they are not leaks just pooled resources being reported
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
valgrind only output leaks? c0uchm0nster Linux - Software 0 10-24-2007 03:44 AM
LXer: Isolate and resolve memory leaks using MALLOCDEBUG on AIX Version 5.3 LXer Syndicated Linux News 0 12-13-2006 04:21 AM


All times are GMT -5. The time now is 07:34 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration