h>
int main() {
int *p, a;
p = malloc(10 * sizeof(int));
p[10] = 1; /* invalid write error */
a = p[10]; /* invalid read error */
free(p);
return 0;
}
This time valgrind reports errors for an invalid write and read outside of allocated
memory space. Additionally, summary statistics report on the number of bytes of memory
dynamically allocated and released during program execution. This feature makes it
very easy to recognize memory leaks within programs.
==16571== Invalid write of size 4
==16571== at 0x80483A2: main (in valgrind_2)
==16571== by 0x398BBE: __libc_start_main (in /lib/libc-2.3.2.so)
==16571== by 0x80482EC: (within valgrind_2)
==16571== Address 0x52A304C is 0 bytes after a block of size 40 alloc'd
==16571== at 0x90068E: malloc (vg_replace_malloc.c:153)
==16571== by 0x8048395: main (in valgrind_2)
==16571== by 0x398BBE: __libc_start_main (in /lib/libc-2.3.2.so)
==16571== by 0x80482EC: (within valgrind_2)
==16571==
==16571== Invalid read of size 4
==16571== at 0x80483AE: main (in valgrind_2)
==16571== by 0x398BBE: __libc_start_main (in /lib/libc-2.3.2.so)
==16571== by 0x80482EC: (within valgrind_2)
==16571== Address 0x52A304C is 0 bytes after a block of size 40 alloc'd
==16571== at 0x90068E: malloc (vg_replace_malloc.
Pages:
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624