内存问题集锦
目录
1 典型内存问题
泄漏, 跑飞(释放后使用, double free), 段错误(空指针, 野指针, 栈溢出, 访问越界), 分配失败.
1.1 泄露
内存泄漏(memory leak)一般是堆内存管理导致的问题. C主要是malloc/free, c++是 new/delete.
2 工具示例
2.1 mtrace
2.2 valgrind
2.3 sanitizer
2.4 Google Heap Profiler
2.5 core analysis
3 防范
3.1 magic
3.2 list poison
3.3 memory bomb
3.4 asan
野指针.
3.5 libunwind stack
3.6 gdb extend
4 References
- 使用mtrace分析内存泄漏
- https://zhuanlan.zhihu.com/p/83547768
- How debugger work part1
- https://eli.thegreenplace.net/2011/01/23/how-debuggers-work-part-1/
- How debugger work part2
- https://eli.thegreenplace.net/2011/01/27/how-debuggers-work-part-2-breakpoints
- How debugger work part2
- https://eli.thegreenplace.net/2011/02/07/how-debuggers-work-part-3-debugging-information