Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens in a double delete?

Obj *op = new Obj; Obj *op2 = op; delete op; delete op2; // What happens here? 

What's the worst that can happen when you accidentally double delete? Does it matter? Is the compiler going to throw an error?

like image 577
purepureluck Avatar asked Feb 07 '12 01:02

purepureluck


1 Answers

It causes undefined behaviour. Anything can happen. In practice, a runtime crash is probably what I'd expect.

like image 170
Carl Norum Avatar answered Sep 19 '22 19:09

Carl Norum