|
From: <sf...@ge...> - 2003-10-29 18:13:59
|
After reading the doc and writing a test program, it looks to me
like there can be a lot of memory leak bugs that won't be
caught. The basic problem is that a block will be considered
reachable even if it is only pointed to by memory which itself
is not reachable. For example, a circular-linked or doubly-linked
list that is leaked will not be detected. (I may try my hand at
fixing this by constructing non-circular graphs.)
My question has to do with pointers to blocks that are stored on the
stack. I thought that valgrind would NOT detect leaks if the ptrs
were stored on the stack, but it DOES detect them! The program
below makes sure that a pointer to the malloc done in z() is in
memory in unused stack space. But valgrind reports the block
as lost.
Does valgrind intentionally skip the stack when looking for lost
blocks?
-----
/* x.c */
#include <stdio.h>
struct x_s { struct x_s *xp; };
void z(char *cp)
{
char d1[64];
struct x_s *z;
char d2[64];
/* this code prevents optimizer from getting rid of d1 & d2 */
d1[0] = *cp; d2[0] = *cp;
printf("addr of stack-based arrays d1=%p, d2=%p\n", d1, d2);
z = (struct x_s *)malloc(sizeof(struct x_s));
z->xp = NULL;
/* this code prevents optimizer from keeping z in a register */
printf("addr of stack-based var z=%p, malloc=%p\n", &z, z);
/* look for malloc ptr in the stack dump at the end of main() */
}
void y(char *a, char *b)
{
char c[128]; /* allocate a bunch of stack so that z's pointer won't be
overwritten by subsequent calls */
/* code to prevent c from being optimized away */
c[0] = 0;
z(c);
*a = c[0]; *b = c[0];
}
int main(int argc, char **argv)
{
char d1[64];
struct x_s *x;
char d2[64];
struct x_s **p;
int i;
/* I think the following leak should not be detected by valgrind, but
somehow it does detect it. Why??? */
y(d1, d2);
/* leak (x loses scope when main returns) */
x = (struct x_s *)malloc(sizeof(struct x_s));
x->xp = NULL;
/* prevent optimizer from keeping x in a register */
printf("addr of stack var x=%p\n", &x);
/* print unused stack dump */
p = &x;
for (i = 0; i < 100; ++i) {
/* ignore the uninitialized accesses */
printf("stack[%p]=%p\n", p, *p);
--p;
}
} /* main */
|
|
From: Test V. <am...@in...> - 2003-11-14 11:39:30
|
Hi All, I downloaded the valgrind sources (both Valgrind version 20031012 and valgrind-2.0) from http://valgrind.kde.org. As per the README, used the following commands ./configure --prefix /usr/local/bin make make install I guess both the times the valgrind was compiled and installed correctly. I also tried once with ./configure only (i.e. without giving prefix option). Also tried using the setting up specific paths. But still all the time I am getting the segmentation fault whenever I run "./valgrind ls -al". Can anybody tell me what could be the problem? Any information/steps about this issues is welcome! Best regards AMOLAK |
|
From: Dimitri Papadopoulos-O. <pap...@sh...> - 2003-11-14 12:58:49
|
Hi, > I downloaded the valgrind sources (both Valgrind version 20031012 and > valgrind-2.0) from http://valgrind.kde.org. > > As per the README, used the following commands > > ./configure --prefix /usr/local/bin I think you mean: ./configure --prefix=/usr/local > make > make install > > I guess both the times the valgrind was compiled and installed > correctly. I also tried once with ./configure only (i.e. without giving > prefix option). Also tried using the setting up specific paths. But > still all the time I am getting the segmentation fault whenever I run > "./valgrind ls -al". This works for me: valgrind ls -al In which directory does this happen? > Can anybody tell me what could be the problem? Any information/steps > about this issues is welcome! Could you describe the system the segfault happens on? -- Dimitri |
|
From: Amol K. <am...@in...> - 2003-11-14 14:37:38
|
Hi Dimitri Thanks for the quick answer. I am getting the error in all the directories. I am using Red Hat Linux release 7.1 (Seawolf) Kernel 2.4.2-2. Yes I forgot to mention the "=" sign ..i.e. I tried ./configure --prefix=/usr/local/bin option as well. Any clues? Amolak -----Original Message----- From: Dimitri Papadopoulos-Orfanos [mailto:pap...@sh...] Sent: Friday, November 14, 2003 1:01 PM To: am...@in... Cc: val...@li... Subject: Re: [Valgrind-users] running valgrind on Red Hat Linux release 7.1 (Seawolf) Kernel 2.4.2-2 Hi, > I downloaded the valgrind sources (both Valgrind version 20031012 and > valgrind-2.0) from http://valgrind.kde.org. > > As per the README, used the following commands > > ./configure --prefix /usr/local/bin I think you mean: ./configure --prefix=/usr/local > make > make install > > I guess both the times the valgrind was compiled and installed > correctly. I also tried once with ./configure only (i.e. without giving > prefix option). Also tried using the setting up specific paths. But > still all the time I am getting the segmentation fault whenever I run > "./valgrind ls -al". This works for me: valgrind ls -al In which directory does this happen? > Can anybody tell me what could be the problem? Any information/steps > about this issues is welcome! Could you describe the system the segfault happens on? -- Dimitri |
|
From: Nicholas N. <nj...@ca...> - 2003-11-14 16:51:13
|
On Fri, 14 Nov 2003, Test Valgrind wrote: > I downloaded the valgrind sources (both Valgrind version 20031012 and > valgrind-2.0) from http://valgrind.kde.org. > > As per the README, used the following commands > > ./configure --prefix /usr/local/bin > make > make install > > I guess both the times the valgrind was compiled and installed > correctly. I also tried once with ./configure only (i.e. without giving > prefix option). Also tried using the setting up specific paths. But > still all the time I am getting the segmentation fault whenever I run > "./valgrind ls -al". Can you send the entire output of "./valgrind -v ls -al"? Thanks. N |
|
From: Amol K. <am...@in...> - 2003-11-14 17:33:44
|
Hi Attched is the output of ./valgrind -v ls -al [test@mmsc bin]$ ./valgrind -v ls -al ==5684== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux. ==5684== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward. ==5684== Using valgrind-2.0.0, a program supervision framework for x86-linux. ==5684== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward. ==5684== Command line: ==5684== ls ==5684== -al ==5684== Startup, with flags: ==5684== --suppressions=/usr/local/bin/valgrind-2.0.0//lib/valgrind/d efault.s upp ==5684== -v ==5684== Reading syms from /bin/ls ==5684== object doesn't have a symbol table ==5684== object doesn't have any debug info ==5684== Reading syms from /lib/ld-2.2.2.so ==5684== Reading syms from /usr/local/bin/valgrind-2.0.0/lib/valgrind/vgskin_mem check.so ==5684== Reading syms from /usr/local/bin/valgrind-2.0.0/lib/valgrind/valgrind.s o ==5684== Reading syms from /lib/libtermcap.so.2.0.8 ==5684== object doesn't have a symbol table ==5684== object doesn't have any debug info ==5684== Reading syms from /lib/i686/libc-2.2.2.so ==5684== Reading suppressions file: /usr/local/bin/valgrind-2.0.0//lib/valgrind/ default.supp ==5684== Estimated CPU clock rate is 751 MHz ==5684== ==5684== Reading syms from /lib/libnss_files-2.2.2.so total 1336 drwxrwxr-x 2 root root 4096 Nov 14 18:35 . drwxrwxr-x 17 root root 4096 Nov 14 13:12 .. -rwxrwxrwx 1 root root 31885 Nov 14 12:13 cg_annotate -rw------- 1 root root 2637824 Nov 14 18:34 core -rwxrwxrwx 1 root root 0 Nov 14 18:37 test.log -rwxrwxrwx 1 root root 5610 Nov 14 12:13 valgrind -rwxrwxrwx 1 root root 61561 Nov 14 12:13 valgrind-listener ==5684== Invalid read of size 4 ==5684== at 0x40262C83: _nl_unload_locale (loadlocale.c:237) ==5684== by 0x4026279C: free_mem (findlocale.c:257) ==5684== by 0x402C1961: __libc_freeres (set-freeres.c:34) ==5684== by 0x40186E43: vgPlain___libc_freeres_wrapper (vg_intercept.c:873) ==5684== Address 0x40C95050 is 12 bytes inside a block of size 380 free'd ==5684== at 0x4002BEA7: free (vg_replace_malloc.c:231) ==5684== by 0x40262CB9: _nl_unload_locale (loadlocale.c:245) ==5684== by 0x40262217: free_mem (setlocale.c:460) ==5684== by 0x402C1961: __libc_freeres (set-freeres.c:34) ==5684== ==5684== Invalid read of size 4 ==5684== at 0x40262C8A: _nl_unload_locale (loadlocale.c:238) ==5684== by 0x4026279C: free_mem (findlocale.c:257) ==5684== by 0x402C1961: __libc_freeres (set-freeres.c:34) ==5684== by 0x40186E43: vgPlain___libc_freeres_wrapper (vg_intercept.c:873) ==5684== Address 0x40C9504C is 8 bytes inside a block of size 380 free'd ==5684== at 0x4002BEA7: free (vg_replace_malloc.c:231) ==5684== by 0x40262CB9: _nl_unload_locale (loadlocale.c:245) ==5684== by 0x40262217: free_mem (setlocale.c:460) ==5684== by 0x402C1961: __libc_freeres (set-freeres.c:34) ==5684== ==5684== Invalid read of size 4 ==5684== at 0x40262C91: _nl_unload_locale (loadlocale.c:238) ==5684== by 0x4026279C: free_mem (findlocale.c:257) ==5684== by 0x402C1961: __libc_freeres (set-freeres.c:34) ==5684== by 0x40186E43: vgPlain___libc_freeres_wrapper (vg_intercept.c:873) ==5684== Address 0x40C95048 is 4 bytes inside a block of size 380 free'd ==5684== at 0x4002BEA7: free (vg_replace_malloc.c:231) ==5684== by 0x40262CB9: _nl_unload_locale (loadlocale.c:245) ==5684== by 0x40262217: free_mem (setlocale.c:460) ==5684== by 0x402C1961: __libc_freeres (set-freeres.c:34) [amol@mmsc bin]$ ./valgrind -v ls -al ==5691== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux. ==5691== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward. ==5691== Using valgrind-2.0.0, a program supervision framework for x86-linux. ==5691== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward. ==5691== Command line: ==5691== ls ==5691== -al ==5691== Startup, with flags: ==5691== --suppressions=/usr/local/bin/valgrind-2.0.0//lib/valgrind/d efault.s upp ==5691== -v ==5691== Reading syms from /bin/ls ==5691== object doesn't have a symbol table ==5691== object doesn't have any debug info ==5691== Reading syms from /lib/ld-2.2.2.so ==5691== Reading syms from /usr/local/bin/valgrind-2.0.0/lib/valgrind/vgskin_mem check.so ==5691== Reading syms from /usr/local/bin/valgrind-2.0.0/lib/valgrind/valgrind.s o ==5691== Reading syms from /lib/libtermcap.so.2.0.8 ==5691== object doesn't have a symbol table ==5691== object doesn't have any debug info ==5691== Reading syms from /lib/i686/libc-2.2.2.so ==5691== Reading suppressions file: /usr/local/bin/valgrind-2.0.0//lib/valgrind/ default.supp ==5691== Estimated CPU clock rate is 752 MHz ==5691== total 1336 ==5691== Reading syms from /lib/libnss_files-2.2.2.so drwxrwxr-x 2 root root 4096 Nov 14 18:35 . drwxrwxr-x 17 root root 4096 Nov 14 13:12 .. -rwxrwxrwx 1 root root 31885 Nov 14 12:13 cg_annotate -rw------- 1 root root 2637824 Nov 14 18:34 core -rwxrwxrwx 1 root root 0 Nov 14 18:37 test.log -rwxrwxrwx 1 root root 5610 Nov 14 12:13 valgrind -rwxrwxrwx 1 root root 61561 Nov 14 12:13 valgrind-listener ==5691== Invalid read of size 4 ==5691== at 0x40262C83: _nl_unload_locale (loadlocale.c:237) ==5691== by 0x4026279C: free_mem (findlocale.c:257) ==5691== by 0x402C1961: __libc_freeres (set-freeres.c:34) ==5691== by 0x40186E43: vgPlain___libc_freeres_wrapper (vg_intercept.c:873) ==5691== Address 0x40C95050 is 12 bytes inside a block of size 380 free'd ==5691== at 0x4002BEA7: free (vg_replace_malloc.c:231) ==5691== by 0x40262CB9: _nl_unload_locale (loadlocale.c:245) ==5691== by 0x40262217: free_mem (setlocale.c:460) ==5691== by 0x402C1961: __libc_freeres (set-freeres.c:34) ==5691== ==5691== Invalid read of size 4 ==5691== at 0x40262C8A: _nl_unload_locale (loadlocale.c:238) ==5691== by 0x4026279C: free_mem (findlocale.c:257) ==5691== by 0x402C1961: __libc_freeres (set-freeres.c:34) ==5691== by 0x40186E43: vgPlain___libc_freeres_wrapper (vg_intercept.c:873) ==5691== Address 0x40C9504C is 8 bytes inside a block of size 380 free'd ==5691== at 0x4002BEA7: free (vg_replace_malloc.c:231) ==5691== by 0x40262CB9: _nl_unload_locale (loadlocale.c:245) ==5691== by 0x40262217: free_mem (setlocale.c:460) ==5691== by 0x402C1961: __libc_freeres (set-freeres.c:34) ==5691== ==5691== Invalid read of size 4 ==5691== at 0x40262C91: _nl_unload_locale (loadlocale.c:238) ==5691== by 0x4026279C: free_mem (findlocale.c:257) ==5691== by 0x402C1961: __libc_freeres (set-freeres.c:34) ==5691== by 0x40186E43: vgPlain___libc_freeres_wrapper (vg_intercept.c:873) ==5691== Address 0x40C95048 is 4 bytes inside a block of size 380 free'd ==5691== at 0x4002BEA7: free (vg_replace_malloc.c:231) ==5691== by 0x40262CB9: _nl_unload_locale (loadlocale.c:245) ==5691== by 0x40262217: free_mem (setlocale.c:460) ==5691== by 0x402C1961: __libc_freeres (set-freeres.c:34) Segmentation fault [amol@mmsc bin]$ -----Original Message----- From: Nicholas Nethercote [mailto:nj...@he...]On Behalf Of Nicholas Nethercote Sent: Friday, November 14, 2003 4:51 PM To: Test Valgrind Cc: Valgrind Users Subject: Re: running valgrind on Red Hat Linux release 7.1 (Seawolf) Kernel 2.4.2-2 On Fri, 14 Nov 2003, Test Valgrind wrote: > I downloaded the valgrind sources (both Valgrind version 20031012 and > valgrind-2.0) from http://valgrind.kde.org. > > As per the README, used the following commands > > ./configure --prefix /usr/local/bin > make > make install > > I guess both the times the valgrind was compiled and installed > correctly. I also tried once with ./configure only (i.e. without giving > prefix option). Also tried using the setting up specific paths. But > still all the time I am getting the segmentation fault whenever I run > "./valgrind ls -al". Can you send the entire output of "./valgrind -v ls -al"? Thanks. N |
|
From: Nicholas N. <nj...@ca...> - 2003-11-14 17:39:21
|
On Fri, 14 Nov 2003, Amol Kulkarni wrote: > Hi Attched is the output of ./valgrind -v ls -al > > ==5684== Invalid read of size 4 > ==5684== at 0x40262C83: _nl_unload_locale (loadlocale.c:237) > ==5684== by 0x4026279C: free_mem (findlocale.c:257) > ==5684== by 0x402C1961: __libc_freeres (set-freeres.c:34) > ==5684== by 0x40186E43: vgPlain___libc_freeres_wrapper > (vg_intercept.c:873) Two suggestions that might help: 1. As Jeremy said, try not ./valgrind but /usr/local/bin/valgrind. 2. Try --run-libc-freeres=no, as per FAQ #1. You said you're running RH 7.1, so your glibc is probably old enough to still suffer that problem. HTH N |
|
From: Jeremy F. <je...@go...> - 2003-11-14 16:58:34
|
On Fri, 2003-11-14 at 03:39, Test Valgrind wrote: > I guess both the times the valgrind was compiled and installed > correctly. I also tried once with ./configure only (i.e. without giving > prefix option). Also tried using the setting up specific paths. But > still all the time I am getting the segmentation fault whenever I run > "./valgrind ls -al". Why "./valgrind"? If you're doing this in your build tree this won't run your freshly build version, but the one in <prefix>/lib/valgrind. You need to use "./valgrind --in-place=.." to make sure you get all-new bits running together. J |
|
From: Julian S. <js...@ac...> - 2003-11-14 19:19:27
|
See Q1/A1 in FAQ.txt. J On Friday 14 November 2003 11:39, Test Valgrind wrote: > Hi All, > > I downloaded the valgrind sources (both Valgrind version 20031012 and > valgrind-2.0) from http://valgrind.kde.org. > > As per the README, used the following commands > > /configure --prefix /usr/local/bin > make > make install > > I guess both the times the valgrind was compiled and installed > correctly. I also tried once with ./configure only (i.e. without giving > prefix option). Also tried using the setting up specific paths. But > still all the time I am getting the segmentation fault whenever I run > "./valgrind ls -al". > > Can anybody tell me what could be the problem? Any information/steps > about this issues is welcome! > > Best regards > > AMOLAK |