BIND 10 trac2088, updated. 25cc38bbd45cca618c0f073b743882865ebc1d64 [2088] Handle NULL deallocate as a nop

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Jul 12 08:16:13 UTC 2012


The branch, trac2088 has been updated
       via  25cc38bbd45cca618c0f073b743882865ebc1d64 (commit)
      from  3e70efc345f40ae6b6e0310bae46dc4167fd4fbc (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 25cc38bbd45cca618c0f073b743882865ebc1d64
Author: Mukund Sivaraman <muks at isc.org>
Date:   Thu Jul 12 13:45:49 2012 +0530

    [2088] Handle NULL deallocate as a nop

-----------------------------------------------------------------------

Summary of changes:
 src/lib/util/memory_segment_local.cc               |    6 ++++++
 .../util/tests/memory_segment_local_unittest.cc    |   13 +++++++++++++
 2 files changed, 19 insertions(+)

-----------------------------------------------------------------------
diff --git a/src/lib/util/memory_segment_local.cc b/src/lib/util/memory_segment_local.cc
index 468c499..9c345c9 100644
--- a/src/lib/util/memory_segment_local.cc
+++ b/src/lib/util/memory_segment_local.cc
@@ -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_);
diff --git a/src/lib/util/tests/memory_segment_local_unittest.cc b/src/lib/util/tests/memory_segment_local_unittest.cc
index e8ee110..08787ad 100644
--- a/src/lib/util/tests/memory_segment_local_unittest.cc
+++ b/src/lib/util/tests/memory_segment_local_unittest.cc
@@ -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



More information about the bind10-changes mailing list