与 g++是否有运行时设置来通过删除来打乱释放的内存?
有谁知道我如何让 g++ 或 gcc 运行时打乱删除后对象所在的内存?我有一个理论,我在删除对象后使用它,但实际上它很少崩溃。
Does anyone know how I can for the g++ or gcc runtime to scramble the ram where an object was after delete? I have a theory that I'm using an object after it has been deleted but in practice it rarely crashes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议使用 valgrind 运行 - 它会告诉您释放内存后是否正在访问内存。
I'd suggesting running with valgrind - that'll tell you if you're accessing memory after freeing it.
inline void operator delete(void* memblock) { //you custom stuff }
将覆盖全局。我曾经使用它来确保安全,这样我们就可以将内存清零,这样就不太可能泄漏重要信息。inline void operator delete(void* memblock) { //you custom stuff }
would override the global. I used to use this for security so that we could zero out the memory so its less likely to leak important information.如果您愿意,可以为您的对象重载
delete
。You can overload
delete
for your object if you like.