Both free(NULL)
and ::operator delete(NULL)
are allowed. Does the allocator concept (e.g. std::allocator also allow deallocate(NULL,1)
, or is it required to put your own guard around it?
Asked
Active
Viewed 483 times
7

JasonMArcher
- 14,195
- 22
- 56
- 52

Jonathan Graehl
- 9,182
- 36
- 40
1 Answers
10
You'll need to add your own check.
According to §20.4.1.1/8, deallocate
requires:
p shall be a pointer value obtained from allocate(). n shall equal the value passed as the first argument to the invocation of allocate which returned p.
allocate
throws an exception when storage can't be given (§20.4.1.1/7). In other words, allocate
never returns 0, and therefore deallocate
should never get a 0. Passing a 0 would lead to undefined behavior.

GManNickG
- 494,350
- 52
- 494
- 543
-
Thanks, that's what I was afraid of. – Jonathan Graehl Jun 24 '10 at 16:19