BIND 10 trac2088, updated. aa584b6a81609f94620b538329977d1f62ad702a [2088] Throw bad_alloc when MemorySegment cannot allocate the required space
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Jul 12 04:48:44 UTC 2012
The branch, trac2088 has been updated
via aa584b6a81609f94620b538329977d1f62ad702a (commit)
via fb9bdb9bd4f34364475ca1d0472ce0975affec73 (commit)
via 96c432de789212c35a4089a46ba551e36547e797 (commit)
from 16f7c0656669ebe1e93ba9f88a35072311bb2f03 (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 aa584b6a81609f94620b538329977d1f62ad702a
Author: Mukund Sivaraman <muks at isc.org>
Date: Thu Jul 12 10:17:53 2012 +0530
[2088] Throw bad_alloc when MemorySegment cannot allocate the required space
commit fb9bdb9bd4f34364475ca1d0472ce0975affec73
Author: Mukund Sivaraman <muks at isc.org>
Date: Thu Jul 12 10:06:39 2012 +0530
[2088] Mark virtual methods as virtual even in derived classes
commit 96c432de789212c35a4089a46ba551e36547e797
Author: Mukund Sivaraman <muks at isc.org>
Date: Thu Jul 12 10:04:40 2012 +0530
[2088] Add virtual destructor to MemorySegment
-----------------------------------------------------------------------
Summary of changes:
src/lib/util/memory_segment.h | 6 ++++++
src/lib/util/memory_segment_local.cc | 7 ++++---
src/lib/util/memory_segment_local.h | 12 +++++++++---
.../util/tests/memory_segment_local_unittest.cc | 6 ++++++
4 files changed, 25 insertions(+), 6 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/util/memory_segment.h b/src/lib/util/memory_segment.h
index d1f4f4a..523fc76 100644
--- a/src/lib/util/memory_segment.h
+++ b/src/lib/util/memory_segment.h
@@ -28,9 +28,15 @@ namespace util {
/// in code.
class MemorySegment {
public:
+ /// \brief Destructor
+ virtual ~MemorySegment() {}
+
/// \brief Allocate/acquire a segment of memory. The source of the
/// memory is dependent on the implementation used.
///
+ /// Throws <code>std::bad_alloc</code> if the implementation cannot
+ /// allocate the requested storage.
+ ///
/// \param size The size of the memory requested in bytes.
/// \return Returns pointer to the memory allocated.
virtual void* allocate(size_t size) = 0;
diff --git a/src/lib/util/memory_segment_local.cc b/src/lib/util/memory_segment_local.cc
index a7fbacd..8e89d74 100644
--- a/src/lib/util/memory_segment_local.cc
+++ b/src/lib/util/memory_segment_local.cc
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
#include "memory_segment_local.h"
+#include <new>
namespace isc {
namespace util {
@@ -20,11 +21,11 @@ namespace util {
void*
MemorySegmentLocal::allocate(size_t size) {
void* ptr = malloc(size);
-
- if (ptr != NULL) {
- allocated_size_ += size;
+ if (ptr == NULL) {
+ throw std::bad_alloc();
}
+ allocated_size_ += size;
return (ptr);
}
diff --git a/src/lib/util/memory_segment_local.h b/src/lib/util/memory_segment_local.h
index 87be0fc..7833545 100644
--- a/src/lib/util/memory_segment_local.h
+++ b/src/lib/util/memory_segment_local.h
@@ -33,12 +33,18 @@ public:
MemorySegmentLocal() : allocated_size_(0) {
}
+ /// \brief Destructor
+ virtual ~MemorySegmentLocal() {}
+
/// \brief Allocate/acquire a segment of memory. The source of the
/// memory is libc's malloc().
///
+ /// Throws <code>std::bad_alloc</code> if the implementation cannot
+ /// allocate the requested storage.
+ ///
/// \param size The size of the memory requested in bytes.
/// \return Returns pointer to the memory allocated.
- void* allocate(size_t size);
+ virtual void* allocate(size_t size);
/// \brief Free/release a segment of memory.
///
@@ -46,13 +52,13 @@ public:
/// should be equal to a value returned by <code>allocate()</code>.
/// \param size The size of the memory to be freed in bytes. This
/// should be equal to the number of bytes originally allocated.
- void deallocate(void* ptr, size_t size);
+ virtual void deallocate(void* ptr, size_t size);
/// \brief Check if all allocated memory was deallocated.
///
/// \return Returns <code>true</code> if all allocated memory was
/// deallocated, <code>false</code> otherwise.
- bool allMemoryDeallocated() const;
+ virtual bool allMemoryDeallocated() const;
private:
// allocated_size_ can underflow, wrap around to max size_t (which
diff --git a/src/lib/util/tests/memory_segment_local_unittest.cc b/src/lib/util/tests/memory_segment_local_unittest.cc
index dcc42e8..8875c3a 100644
--- a/src/lib/util/tests/memory_segment_local_unittest.cc
+++ b/src/lib/util/tests/memory_segment_local_unittest.cc
@@ -52,4 +52,10 @@ TEST(MemorySegmentLocal, TestLocal) {
EXPECT_TRUE(segment->allMemoryDeallocated());
}
+TEST(MemorySegmentLocal, TestTooMuchMemory) {
+ auto_ptr<MemorySegment> segment(new MemorySegmentLocal());
+
+ EXPECT_THROW(segment->allocate(0x7fffffffffffffff), bad_alloc);
+}
+
} // anonymous namespace
More information about the bind10-changes
mailing list