mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 12:47:45 +00:00
UserspaceEmulator: Improve detection of memory leaks
Previous a mallocation was marked as 'reachable' when any other mallocation or memory region had a pointer to that mallocation. However there could be the situation that two mallocations have pointers to each other while still being unreachable from anywhere else. They would be marked as 'reachable' regardless. This patch replaces the old way of detemining whether a mallocation is reachable by analyzing the dependencies of the different mallocations using a graph-approach. Now mallocations are only reachable if pointed to by other reachable mallocations or other memory regions. A nice bonus is that this gets rid of a nested for_each_mallocation, so the complexity of leak finding becomes linear instead of quadratic.
This commit is contained in:
parent
86290c0e4e
commit
c4a9f0db82
2 changed files with 83 additions and 28 deletions
|
@ -39,6 +39,14 @@ namespace UserspaceEmulator {
|
|||
class Emulator;
|
||||
class SoftCPU;
|
||||
|
||||
struct GraphNode {
|
||||
Vector<FlatPtr> edges_from_node {};
|
||||
|
||||
bool is_reachable { false };
|
||||
};
|
||||
|
||||
using MemoryGraph = HashMap<FlatPtr, GraphNode>;
|
||||
|
||||
struct Mallocation {
|
||||
bool contains(FlatPtr a) const
|
||||
{
|
||||
|
@ -87,10 +95,14 @@ private:
|
|||
Mallocation* find_mallocation(FlatPtr);
|
||||
Mallocation* find_mallocation_before(FlatPtr);
|
||||
Mallocation* find_mallocation_after(FlatPtr);
|
||||
bool is_reachable(const Mallocation&) const;
|
||||
|
||||
void dump_memory_graph();
|
||||
void populate_memory_graph();
|
||||
|
||||
Emulator& m_emulator;
|
||||
|
||||
MemoryGraph m_memory_graph {};
|
||||
|
||||
bool m_auditing_enabled { true };
|
||||
};
|
||||
|
||||
|
@ -112,5 +124,4 @@ ALWAYS_INLINE Mallocation* MallocTracer::find_mallocation(const Region& region,
|
|||
return nullptr;
|
||||
return mallocation;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue