05-24-2010 01:03 PM
I got the file compiled and I can run it on a VM of RedHat with a usb-gpib converter. I currently have no instruments to talk to, but i'm assuming this problem still shows up even with an ipwrt failed status?
I'm unfamiliar with valgrind could you let me know how you used it to pinpoint that function call?
05-24-2010 03:06 PM
Hey snowman,
I'm assuming valgrind is already installed on your system. If not you should be able to install it with yum.
To run valgrind first "cd" to where the "leak" executable is. Run the following command, which assumes that valgrind is in your path:
valgrind --tool=memcheck --leakcheck=full --show-reachable=yes --error-limit=no --log-file=dump ./leak <gpib device> <gpib address>
You should start to see the normal output of the application. Let it run for a few seconds (30 seconds or so) and then hit CTRL-C. The application should write a line of text that reads "Going down. The count is n". Make note of "n".
In your directory you should now have a plain-text file called dummy.<pid>. Open it up using your favorite editor. It takes a bit to understand what valgrind is telling you but the part you are interested in is near the bottom. It should look something like this:
==3097== 1,736 bytes in 62 blocks are definitely lost in loss record 9 of 9
==3097== at 0x4004405: malloc (vg_replace_malloc.c:149)
==3097== by 0x40BD412: (within /usr/local/natinst/nipal/lib/libnipalu.so.1.11.0)
==3097== by 0x4118C24: _memNewUsingCRT(unsigned long, tMemAllocationFlags, long*) (in /usr/local/natinst/nipal/lib/libnipalu.so.1.11.0)
==3097== by 0x402FB17: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1)
==3097== by 0x402F9EE: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1)
==3097== by 0x402F8F8: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1)
==3097== by 0x402D930: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1)
==3097== by 0x40280F7: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1)
==3097== by 0x4061D1C: ibdev (in /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1)
==3097== by 0x80487C1: proc(void*) (in /home/jmay/driver/leak/leak)
==3097== by 0x5943CB: start_thread (in /lib/tls/libpthread-2.3.4.so)
==3097== by 0x3FC1AD: clone (in /lib/tls/libc-2.3.4.so)
What this block is telling you is that 1736 bytes were allocated by "malloc" but never free'd. You can follow the functions by going backwards. "malloc" was called by "_memNewUsingCRT" which was called by a function at 0x402FB17, etc. If you track back you can see that the chain was started by a call to "ibdev" in the function "proc".
If you
divide the bytes allocated (1736) by 28 you should get "n".
With minimal effort you should be able to modify the leak application so that it doesn't use threads and then re-run valgrind. You'll notice that the you won't see leak then.
Here's a link I found that does a way better job explaining valgrind's output which may helpful.
Again, I do appreciate you taking the time and if I can help in any way let me know.
--twotymz
05-25-2010 10:49 AM
To let you know, it looks like this issue reproduces on my machine
==15608== 14,616 bytes in 522 blocks are definitely lost in loss record 8 of 8 ==15608== at 0x4004405: malloc (vg_replace_malloc.c:149) ==15608== by 0x40B9412: (within /usr/local/natinst/nipal/lib/libnipalu.so.1.11.0) ==15608== by 0x4114C24: _memNewUsingCRT(unsigned long, tMemAllocationFlags, long*) (in /usr/local/natinst/nipal/lib/libnipalu.so.1.11.0) ==15608== by 0x402BB17: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1) ==15608== by 0x402B9EE: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1) ==15608== by 0x402B8F8: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1) ==15608== by 0x4029930: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1) ==15608== by 0x40240F7: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1) ==15608== by 0x405DD1C: ibdev (in /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1) ==15608== by 0x80487C1: proc(void*) (in /home/labview/Desktop/leak) ==15608== by 0xCE83CB: start_thread (in /lib/tls/libpthread-2.3.4.so) ==15608== by 0xB4F96D: clone (in /lib/tls/libc-2.3.4.so) ==15608== ==15608== LEAK SUMMARY: ==15608== definitely lost: 14,760 bytes in 523 blocks. ==15608== possibly lost: 0 bytes in 0 blocks. ==15608== still reachable: 867 bytes in 6 blocks. ==15608== suppressed: 0 bytes in 0 blocks.
also the command for valgrind should be:
valgrind --tool=memcheck --leak-check=full --show-reachable=yes --error-limit=no --log-file=dump ./leak <gpib device> <gpib address>
Where gpib-device and gpib-address are inputs I reproduced using a USB-HS GPIB with no device connected and called:
valgrind --tool=memcheck --leak-check=full --show-reachable=yes --error-limit=no --log-file=dump ./leak <gpib device> 0 test
05-25-2010 11:51 AM
I'm glad you got similar results. Can't wait to hear the response.
--twotymz
05-25-2010 02:49 PM
I realized that i'm using the unsupported version of the driver. If you are using 2.5.1 (http://joule.ni.com/nidu/cds/view/p/id/980/lang/en) on WS 4 it is a beta driver and does not support that version of Red Hat. Do you get this same behavior with a version of the driver that supports red hat ( http://joule.ni.com/nidu/cds/view/p/id/329/lang/en )?
05-25-2010 03:13 PM
Hey snowman,
I'm pretty sure I'm not using the beta version of the driver. Here's the first 30 lines or so from the README.txt from the driver I have which says it supports Redhat WS 4:
NI-488.2 for Linux/x86, Version 2.5.1 Copyright (c) 2006 National Instruments Corporation. All Rights Reserved. This file contains important information about the NI-488.2 software for Linux, including installation issues, compatibility issues, API changes from previous beta drivers, upgrade/downgrade instructions from/to Version 2.3.1, and a list of FAQs. Refer to the NI-488.2 for Linux Installation Guide in the Documentation directory on the NI-488.2 for Linux CD for information about installing the software. ----------------------------------------------------------------------------- This file supersedes any discrepant information presented in the NI-488.2 for Linux Installation Guide. Refer to www.ni.com/linux for the most recent information about Linux support at National Instruments. ----------------------------------------------------------------------------- ------------------- System Requirements ------------------- NI-488.2 for Linux software for the Intel x86 (32-bit) architecture requires the following distributions: Mandrakelinux 10.1 Official Mandriva Linux 2006 SUSE Linux 10.0 SUSE Linux 10.1 Red Hat Enterprise Linux WS 3 Red Hat Enterprise Linux WS 4 An X Windows graphical environment to run graphical configuration and troubleshooting utilities is recommended.
Am I using the correct version of the driver?
--twotymz
05-27-2010 02:15 PM
06-02-2010 03:35 PM
I reproduced the Issue on another RedHat 5 machine. When i tried taking all the ib calls out of the file re-compiling and running valgrind it shows that it is still leaking (unless i did something wrong in the process) can you take a look at the modified code and tell me if you get the same result on your machine.
==20948== 15,512 bytes in 554 blocks are definitely lost in loss record 7 of 7 ==20948== at 0x40053C0: malloc (vg_replace_malloc.c:149) ==20948== by 0x40BBD6A: (within /usr/local/natinst/nipal/lib/libnipalu.so.2.0.0) ==20948== by 0x411BD08: _memNewUsingCRT(unsigned long, tMemAllocationFlags, long*) (in /usr/local/natinst/nipal/lib/libnipalu.so.2.0.0) ==20948== by 0x402DB17: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1) ==20948== by 0x402D9EE: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1) ==20948== by 0x402D8F8: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1) ==20948== by 0x402B930: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1) ==20948== by 0x40260F7: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1) ==20948== by 0x405FD1C: ibdev (in /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1) ==20948== by 0x80488D5: proc(void*) (in /home/labview/Desktop/leak) ==20948== by 0x55343A: start_thread (in /lib/libpthread-2.5.so) ==20948== by 0x4AAFDD: clone (in /lib/libc-2.5.so) ==20948== ==20948== LEAK SUMMARY: ==20948== definitely lost: 15,512 bytes in 554 blocks. ==20948== possibly lost: 0 bytes in 0 blocks. ==20948== still reachable: 883 bytes in 6 blocks. ==20948== suppressed: 0 bytes in 0 blocks.
06-07-2010 09:10 AM
Hey snowman,
Sorry it took a bit to respond. I downloaded leak-no-gpib.cpp and compiled it. I did not get the same results as you though:
==7713== 144 bytes in 1 blocks are possibly lost in loss record 5 of 7 ==7713== at 0x40056BF: calloc (vg_replace_malloc.c:279) ==7713== by 0x327C0A: _dl_allocate_tls (in /lib/ld-2.3.4.so) ==7713== by 0x5949FD: pthread_create@@GLIBC_2.1 (in /lib/tls/libpthread-2.3.4.so) ==7713== by 0x804881E: main (in /home/jmay/driver/leak/leak) ==7713== ==7713== ==7713== 144 bytes in 1 blocks are still reachable in loss record 6 of 7 ==7713== at 0x40056BF: calloc (vg_replace_malloc.c:279) ==7713== by 0x326A2F: _dl_check_map_versions (in /lib/ld-2.3.4.so) ==7713== by 0x4305DB: dl_open_worker (in /lib/tls/libc-2.3.4.so) ==7713== by 0x3255ED: _dl_catch_error (in /lib/ld-2.3.4.so) ==7713== by 0x430D47: _dl_open (in /lib/tls/libc-2.3.4.so) ==7713== by 0x487807: dlopen_doit (in /lib/libdl-2.3.4.so) ==7713== by 0x3255ED: _dl_catch_error (in /lib/ld-2.3.4.so) ==7713== by 0x4872BA: _dlerror_run (in /lib/libdl-2.3.4.so) ==7713== by 0x48786D: dlopen@GLIBC_2.0 (in /lib/libdl-2.3.4.so) ==7713== by 0x405CE07: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1) ==7713== by 0x405D3FD: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1) ==7713== by 0x4059A67: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1) ==7713== ==7713== ==7713== 603 bytes in 1 blocks are still reachable in loss record 7 of 7 ==7713== at 0x40056BF: calloc (vg_replace_malloc.c:279) ==7713== by 0x3226E0: _dl_new_object (in /lib/ld-2.3.4.so) ==7713== by 0x31E968: _dl_map_object_from_fd (in /lib/ld-2.3.4.so) ==7713== by 0x32046B: _dl_map_object (in /lib/ld-2.3.4.so) ==7713== by 0x430507: dl_open_worker (in /lib/tls/libc-2.3.4.so) ==7713== by 0x3255ED: _dl_catch_error (in /lib/ld-2.3.4.so) ==7713== by 0x430D47: _dl_open (in /lib/tls/libc-2.3.4.so) ==7713== by 0x487807: dlopen_doit (in /lib/libdl-2.3.4.so) ==7713== by 0x3255ED: _dl_catch_error (in /lib/ld-2.3.4.so) ==7713== by 0x4872BA: _dlerror_run (in /lib/libdl-2.3.4.so) ==7713== by 0x48786D: dlopen@GLIBC_2.0 (in /lib/libdl-2.3.4.so) ==7713== by 0x405CE07: (within /usr/local/natinst/ni4882/lib/libgpibapi.so.2.5.1) ==7713== ==7713== LEAK SUMMARY: ==7713== definitely lost: 0 bytes in 0 blocks. ==7713== possibly lost: 144 bytes in 1 blocks. ==7713== still reachable: 867 bytes in 6 blocks. ==7713== suppressed: 0 bytes in 0 blocks.
Here's the command line I used:
g++ leak-no-gpib.cpp -lgpibapi -lpthread -o leak
--twotymz
06-08-2010 09:38 AM