Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Test Valgrind
- *
- * gcc -o test -std=c11 -Wall -ggdb3 test.c
- * valgrind --leak-check=full --show-leak-kinds=all ./test
- */
- #include <stdlib.h>
- void funcion(void)
- {
- int* x = malloc(10 * sizeof(int));//funcion (test.c:14)
- x[10] = 0; //Problema 1 desbordamiento, Invalid write of size 4 funcion (test.c:15)
- } // problema 2 fuga de memoria ; x no liberado "memory-leak " total heap usage: 1 allocs, 0 frees, 40 bytes allocated
- int main(void){
- funcion();//Invalid write of size 4 main (test.c:19)
- return 0;
- }
- /*
- ==4289== Invalid write of size 4
- ==4289== at 0x109153: funcion (test.c:15)
- ==4289== by 0x109164: main (test.c:19)
- ==4289== Address 0x4a42068 is 0 bytes after a block of size 40 alloc'd
- ==4289== at 0x483877F: malloc (vg_replace_malloc.c:307)
- ==4289== by 0x109146: funcion (test.c:14)
- ==4289== by 0x109164: main (test.c:19)
- ==4289==
- ==4289==
- ==4289== HEAP SUMMARY:
- ==4289== in use at exit: 40 bytes in 1 blocks
- ==4289== total heap usage: 1 allocs, 0 frees, 40 bytes allocated
- ==4289==
- ==4289== 40 bytes in 1 blocks are definitely lost in loss record 1 of 1
- ==4289== at 0x483877F: malloc (vg_replace_malloc.c:307)
- ==4289== by 0x109146: funcion (test.c:14)
- ==4289== by 0x109164: main (test.c:19)
- ==4289==
- ==4289== LEAK SUMMARY:
- ==4289== definitely lost: 40 bytes in 1 blocks
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement