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.
views:
54answers:
3Is there a more global solution?
Steven Behnke
2010-03-11 18:41:11
inline void operator delete(void* memblock) { //you custom stuff } would override the global. The different methods for testing for memory leaks or even for security follow this methodology. From the security standpoint, they zero out that region of memory before freeing it.
Digicoder
2010-03-11 18:55:49
@Digicoder - I'd suggest posting this as its own answer.
Douglas Leeder
2010-03-12 07:37:07
@Douglas - Will do, it at least makes it easier to read.
Digicoder
2010-03-12 14:10:30
+3
A:
I'd suggesting running with valgrind - that'll tell you if you're accessing memory after freeing it.
Douglas Leeder
2010-03-11 18:45:34
Well - that might be due to the memory corruption you are trying to trace. Have you fixed all errors it reports before crashing?
Douglas Leeder
2010-03-12 07:35:02
+1
A:
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.
Digicoder
2010-03-12 14:09:42