Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
25cc38bb
Commit
25cc38bb
authored
Jul 12, 2012
by
Mukund Sivaraman
Browse files
[2088] Handle NULL deallocate as a nop
parent
3e70efc3
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lib/util/memory_segment_local.cc
View file @
25cc38bb
...
...
@@ -31,6 +31,12 @@ MemorySegmentLocal::allocate(size_t size) {
void
MemorySegmentLocal
::
deallocate
(
void
*
ptr
,
size_t
size
)
{
if
(
ptr
==
NULL
)
{
// Return early if NULL is passed to be deallocated (without
// modifying allocated_size, or comparing against it).
return
;
}
if
(
size
>
allocated_size_
)
{
isc_throw
(
OutOfRange
,
"Invalid size to deallocate: "
<<
size
<<
"; currently allocated size: "
<<
allocated_size_
);
...
...
src/lib/util/tests/memory_segment_local_unittest.cc
View file @
25cc38bb
...
...
@@ -86,4 +86,17 @@ TEST(MemorySegmentLocal, TestBadDeallocate) {
EXPECT_THROW
(
segment
->
deallocate
(
ptr
,
2048
),
isc
::
OutOfRange
);
}
TEST
(
MemorySegmentLocal
,
TestNullDeallocate
)
{
auto_ptr
<
MemorySegment
>
segment
(
new
MemorySegmentLocal
());
// By default, nothing is allocated.
EXPECT_TRUE
(
segment
->
allMemoryDeallocated
());
// NULL deallocation is a no-op.
EXPECT_NO_THROW
(
segment
->
deallocate
(
NULL
,
1024
));
// This should still return true.
EXPECT_TRUE
(
segment
->
allMemoryDeallocated
());
}
}
// anonymous namespace
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment