Advertisement
AntonioVillanueva

TEST FUGAS VALGRIND

Jul 20th, 2022
885
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1.  /*
  2.   * Test Valgrind
  3.   *
  4.   * gcc -o test -std=c11 -Wall -ggdb3 test.c
  5.   * valgrind --leak-check=full --show-leak-kinds=all ./test
  6.   */
  7.  #include <stdlib.h>
  8.  
  9. void funcion(void)
  10. {
  11.     int* x = malloc(10 * sizeof(int));//funcion (test.c:14)
  12.     x[10] = 0; //Problema 1 desbordamiento, Invalid write of size 4 funcion (test.c:15)
  13. } // problema 2 fuga de memoria ; x no liberado "memory-leak " total heap usage: 1 allocs, 0 frees, 40 bytes allocated
  14.  
  15. int main(void){
  16.     funcion();//Invalid write of size 4 main (test.c:19)
  17.     return 0;
  18. }
  19.  
  20. /*
  21.  ==4289== Invalid write of size 4
  22. ==4289==    at 0x109153: funcion (test.c:15)
  23. ==4289==    by 0x109164: main (test.c:19)
  24. ==4289==  Address 0x4a42068 is 0 bytes after a block of size 40 alloc'd
  25. ==4289==    at 0x483877F: malloc (vg_replace_malloc.c:307)
  26. ==4289==    by 0x109146: funcion (test.c:14)
  27. ==4289==    by 0x109164: main (test.c:19)
  28. ==4289==
  29. ==4289==
  30. ==4289== HEAP SUMMARY:
  31. ==4289==     in use at exit: 40 bytes in 1 blocks
  32. ==4289==   total heap usage: 1 allocs, 0 frees, 40 bytes allocated
  33. ==4289==
  34. ==4289== 40 bytes in 1 blocks are definitely lost in loss record 1 of 1
  35. ==4289==    at 0x483877F: malloc (vg_replace_malloc.c:307)
  36. ==4289==    by 0x109146: funcion (test.c:14)
  37. ==4289==    by 0x109164: main (test.c:19)
  38. ==4289==
  39. ==4289== LEAK SUMMARY:
  40. ==4289==    definitely lost: 40 bytes in 1 blocks
  41.  
  42. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement