It’s not an easy job, careful design and consideration is needed to make memory allocation and free robust and efficiency. Here just go through the way Open SSL conducting memory leak. Here just give the brief instruction and architecture.
1, re-implement the memory allocate function,
2, use a hash table to record every allocation, restored in node mem_st.
3, use a trigger flag to control if monitors all the memory allocation. Such as CRYPTO_MEM_CHECK_ON and CRYPTO_MEM_CHECK_OFF.
4, have to use a memory lock to separate the inner and outer allocation. MemCheck_off() and MemCheck_on(), still it’s not very clear to meL.
5, the callback function CRYPTO_mem_leaks_cb() can be used to cleanup all the leak memory.
Why the OPEN SSL only have the function to printout all the leak memory, and don’t have the standard function to free them? Maybe it has to be implement by the users themselves.

本文介绍了OpenSSL中如何实现内存分配及泄漏检测机制。主要内容包括:重新实现内存分配函数、使用哈希表记录每次分配、设置标记控制内存监控、利用锁隔离内外分配过程以及提供回调函数清理泄露内存。
5901

被折叠的 条评论
为什么被折叠?



