Is there any method to safe handle twice freeing memory by delete-expression?

  • A+
Category:Languages

If in theory imagine a situation where, by chance or by mistake (either through carelessness, or due to lack of experience, etc.), the memory was freed twice using delete-exprssion (yes, a good developer will not allow this, in well-designed architectural solutions, but howewer) how to (can we, or is there any method to) safty handle the situation so that the application does not crash?

 


so that the application does not crash

This is just a side-effect, an implementation detail of the real problem. Double deleting causes undefined behavior according to the standard.

There is no way to turn a program exhibiting undefined behavior back into one defined so no, there is no way to handle it safely.


Ideally you shouldn't be using new or delete at all.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: