[SOLVED] still reachable: 28 bytes in 1 blocks- valgrind error
Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
still reachable: 28 bytes in 1 blocks- valgrind error
I am using valgrind 3.6.0 for finding memory leak in my application.
this is one sample code i tested in Valgrind. This is similar to my actual application.
==22589== HEAP SUMMARY:
==22589== in use at exit: 28 bytes in 1 blocks
==22589== total heap usage: 3 allocs, 2 frees, 524 bytes allocated
==22589==
==22589== 28 bytes in 1 blocks are still reachable in loss record 1 of 1
==22589== at 0x4023CBE: malloc (vg_replace_malloc.c:236)
==22589== by 0x400CE43: _dl_map_object_deps (in /lib/ld-2.5.so)
==22589== by 0x4011E34: dl_open_worker (in /lib/ld-2.5.so)
==22589== by 0x400E025: _dl_catch_error (in /lib/ld-2.5.so)
==22589== by 0x4011928: _dl_open (in /lib/ld-2.5.so)
==22589== by 0x4449F01: do_dlopen (in /lib/libc-2.5.so)
==22589== by 0x400E025: _dl_catch_error (in /lib/ld-2.5.so)
==22589== by 0x444A000: dlerror_run (in /lib/libc-2.5.so)
==22589== by 0x444A12A: __libc_dlopen_mode (in /lib/libc-2.5.so)
==22589== by 0x405AE66: pthread_cancel_init (in /lib/libpthread-2.5.so)
==22589== by 0x405AF90: _Unwind_ForcedUnwind (in /lib/libpthread-2.5.so)
==22589== by 0x4058950: __pthread_unwind (in /lib/libpthread-2.5.so)
==22589==
==22589== LEAK SUMMARY:
==22589== definitely lost: 0 bytes in 0 blocks
==22589== indirectly lost: 0 bytes in 0 blocks
==22589== possibly lost: 0 bytes in 0 blocks
==22589== still reachable: 28 bytes in 1 blocks
==22589== suppressed: 0 bytes in 0 blocks
==22589==
==22589== For counts of detected and suppressed errors, rerun with: -v
==22589== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 3 from 3)
emmys0126:/opt/mdas # valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./mdas-pc
==24173== Memcheck, a memory error detector
==24173== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==24173== Using Valgrind-3.6.0 and LibVEX; rerun with -h for copyright info
==24173== Command: ./mdas-pc
In our application also we are getting the same message in Valgrind. And when we run the application 24x7 , there is a reduction in RAM size (In our embedded board, total available RAM is 64 MB). And after few hours, it is reducing to 1.3MB and board communication fails.
Is this problem has any relation with the Valgrind error "still reachable: 28 bytes in 1 blocks" ? Usually what will be the cause of RAM reduction?
The output of valgrind could be misleading in this case, because you are exiting the program immediately after cancelling the thread; you can easily end up reporting on the state of the heap before the thread has had a chance to exit. Try putting a small delay after the pthread_cancel, I think you will find that this will make the 'leak' vanish from your example code.
If your real code is using pthread_cancel to kill threads and you are having problems with losing RAM, it is possible that your threads are opening/allocating something that is not being cleaned up (for example, shared process resources such as handles).The pthread_cancel should be used with caution; it is often better if one can come up with a way of signalling a thread to terminate itself rather than to kill it, so that the exit is more structured. If you must use pthread_cancel, then pthread_cleanup_push is a way of supplying resource recovery code.
Last edited by neonsignal; 12-09-2010 at 06:48 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.