CS377 Discussion Outline - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

CS377 Discussion Outline

Description:

CS377 Discussion Outline. Questions? demo of Valgrind ('val-grinned'): Useful for Project #3 ... Compile your program with g debugging info. Call with: ... – PowerPoint PPT presentation

Number of Views:80
Avg rating:3.0/5.0
Slides: 10
Provided by: jimpa1
Category:

less

Transcript and Presenter's Notes

Title: CS377 Discussion Outline


1
CS377 Discussion Outline
  • Questions?
  • demo of Valgrind (val-grinned)
  • Useful for Project 3
  • Find memory leaks
  • Find bad/mismatched deletes
  • See valgrind.org
  • Basic usage
  • Compile your program with g debugging info
  • Call with
  • valgrind --leak-checkfull your_program

2
Example 1 Memory Leak
  • void example1(void)
  • int x new int100 // memory leak no
    delete
  • main() example1()

400 bytes in 1 blocks def. lost in loss record 1
of 1 at 0x4005E1E operator new(unsigned)

(vg_replace_malloc.c268) by 0x8048AC4
example1() (example7.cc41) by 0x8048C0C
main (example7.cc144) LEAK SUMMARY
definitely lost 400 bytes in 1 blocks.
3
Ex. 2 Access past end of array
  • void example2(void)
  • int x new int100
  • x100 37 // access past end of
    array
  • delete x

Invalid write of size 4 at 0x8048A9A
example2() (example7.cc49) by 0x8048C16
main (example7.cc145)
4
Ex. 3 uninitialized variable
  • void example3(void)
  • int x,y // uninitialized
  • x 2y

Conditional jump or move depends on
uninitialised value(s) by 0x80488A7
example3() (example7.cc61) by 0x8048C20
main (example7.cc146)
5
Ex. 7 delete without new
  • void example7(void)
  • int x
  • delete x // delete without
    new

Invalid free() / delete / delete at
0x4004F6A operator delete(void)
(vg_replace_malloc.c364) by 0x8048A0D
example7() (example7.cc90) by 0x8048C42
main (example7.cc150) Address 0x8ddff4 is not
stack'd, malloc'd or (recently)
free'd
6
Example 8 extra delete
  • void example8(void)
  • int x new int100
  • delete x
  • delete x // extra
    delete

Invalid free() / delete / delete at
0x4004F6A operator delete(void) by
0x8048A7A example8() (example7.cc97) by
0x8048C49 main (example7.cc151) Address
0x402b028 is 0 bytes inside a block of
size 400 free'd at 0x4004F6A operator
delete(void) by 0x8048A69 example8()
(example7.cc96) by 0x8048C49 main
(example7.cc151)
7
Example 9 write to freed mem.
  • void example9(void)
  • int x new int100
  • delete x
  • x17 37 // writing to
    freed memory

Invalid write of size 4 at 0x8048A3C
example9() (example7.cc104) by 0x8048C50
main (example7.cc152) Address 0x402b06c is 68
bytes inside a block of size 400
free'd at 0x4004F6A operator delete(void)
by 0x8048A35 example9() (example7.cc103)
by 0x8048C50 main (example7.cc152)
8
Ex. 10 wrong delete/delete
  • void example10(void)
  • int x new int100
  • delete x // should use
    delete

Mismatched free() / delete / delete at
0x40054AA operator delete(void) by
0x8048AF2 example10() (example7.cc110) by
0x8048C57 main (example7.cc153) Address
0x402b028 is 0 bytes inside a block of size
400 alloc'd at 0x4005E1E
operator new(unsigned) by 0x8048AE4
example10() (example7.cc109) by 0x8048C57
main (example7.cc153)
9
Ex. 13/14 stack/global errors
  • int x_global100
  • void example14(void)
  • int x_stack100
  • x_stack100 37 // writing past
    end
  • x_global100 37 // of stackglobal
    vars.

ERROR SUMMARY 0 errors from 0 contexts
Write a Comment
User Comments (0)
About PowerShow.com