Precise Detection of Memory Leaks - PowerPoint PPT Presentation

About This Presentation
Title:

Precise Detection of Memory Leaks

Description:

False positives. Evaluation. Future Work. Physical Leaks. What ... False Positives (2) Every memory block gets a usecount. usecount is increased at stores ... – PowerPoint PPT presentation

Number of Views:47
Avg rating:3.0/5.0
Slides: 22
Provided by: Jon76
Category:

less

Transcript and Presenter's Notes

Title: Precise Detection of Memory Leaks


1
Precise Detection of Memory Leaks
  • Jonas Maebe, Michiel Ronsse, Koen De Bosschere

Dammit, Jim. Im an Eiffel Tower, not a Star Trek
logo
WODA2004
25 May 2004
2
Memory leaks
  • What
  • Allocating memory without releasing later
  • Why bad
  • Reduce performance
  • May cause crashes
  • How to solve
  • Find out where exactly memory is leaked

3
Overview
  • Kinds of memory leaks
  • Existing tools
  • Our solution
  • False positives
  • Evaluation
  • Future Work

4
Physical Leaks
  • What
  • Last pointer to a block of memory is destroyed
  • Causes
  • Pointer overwrite
  • Free block containing pointer
  • Stack shrinks

5
Physical Leaks (2)
  • Important information
  • Allocation site of block
  • Location where last pointer is lost
  • Assignment location of last pointer

6
Logical Leaks
  • What
  • Reachable pointer available, but block never
    freed
  • Important information
  • Allocation site of block
  • Where are these pointers?

7
Existing Tools
  • Most where was leaked block allocated
  • Pro simple, very fast
  • Con may not be enough information
  • Insure also where last pointer lost
  • Pro more information for physical leaks
  • Con not more info for logical leaks, source code
    instrumentation, no description of technique,
    expensive

8
Our solution
  • Keep track of allocated blocks
  • Physical leak reference count of block becomes
    zero
  • Logical leak unfreed blocks which are not
    physical leaks

9
DIOTA principle
Original program
Generated code (clone)
  • To configure
  • Use backends
  • Here
  • Memory instrumentation
  • Replace calls to memory management functions

heap
Stack (shared)
10
Overview Leak Detection
Memory Blocks

BlockInfo1
BlockInfo4
  • Hashtable
  • Only random access necessary

11
Allocations
Memory Blocks

BlockInfo1

void a malloc(32)
  • Reserved blocks
  • Intercept memory management functions
  • Have reference count

12
References
Memory Blocks

BlockInfo1

void a malloc(32)
  • Reference Detection
  • Results of stores
  • Begin addresses of blocks

13
Leaks
Memory Blocks

Blockinfo1

Leaks
LeakInfo1
void a malloc(32) a NULL
14
Stale References
Memory Blocks

BlockInfo1
  • Two possibilities
  • Search all references and destroy them
  • Make sure we can detect that block has been freed

!!!
void a malloc(32) free(a) a NULL
15
Stale References (2)
  • All BlockInfos get a unique ID
  • References get copy of ID
  • When freeing a block, give it a new ID
  • BlockInfos come from dedicated pool
  • Can be reused as soon as block is freed
  • Direct pointer to BlockInfo from Reference

16
False Positives
Memory Blocks

Blockinfo1

Leaks
Need way to detect that leak info is out of date
L1
void a malloc(32) a 2sizeof(void) ... vo
id b a-2sizeof(void) ...
17
False Positives (2)
  • Every memory block gets a usecount
  • usecount is increased at stores
  • current usecount is copied to leakinfo
  • Delay reporting of leaks
  • BlockIDs dont match block freed
  • usecounts dont match block still addressed later

18
Other issues
  • C pointers to BlockStartsizeof(void)
  • False negatives (random value ptr)
  • Circular structures

19
Evaluation
  • Slowdown 250 - 350 times in real world programs
  • Example bug found using implementation

1 for(int i0iltexp1i) setltmaplt..gt gt
new_terms find_terms(...) // fix memory
leak found by DIOTA value_clear(result-gtarri
.d) 5 value_clear(result-gtarri.x.n)
result-gtarri translate_one_term(...)
20
Future work
  • Report information about logical memory leaks
  • Detect usage of stale pointers
  • Speed up implementation
  • Post-write memory instrumentation
  • Stack change interception

21
Questions?
Write a Comment
User Comments (0)
About PowerShow.com