BIND 10 trac2836, updated. 8b47d98c888f29facede10aecc8bf4d39d8f21ce [2836] Call resetHeader at better times
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu May 16 14:39:20 UTC 2013
The branch, trac2836 has been updated
via 8b47d98c888f29facede10aecc8bf4d39d8f21ce (commit)
via 8da51f50f03d1b84d9be0bb73d4091ddf32149fb (commit)
via 52588836afbc4f6d66fd93d30bc37867bfeb2eb8 (commit)
via 02fb830f3e15239a263d109e8bda0256418401bb (commit)
via a5eb53f5b3fcf01e6df58325e11269e62e259197 (commit)
from 929f85f8deb68ba58610354c8161c0e1c0806006 (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 8b47d98c888f29facede10aecc8bf4d39d8f21ce
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu May 16 16:21:31 2013 +0200
[2836] Call resetHeader at better times
commit 8da51f50f03d1b84d9be0bb73d4091ddf32149fb
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu May 16 16:18:24 2013 +0200
[2936] Handle rare relocation
commit 52588836afbc4f6d66fd93d30bc37867bfeb2eb8
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu May 16 16:15:36 2013 +0200
[2836] Remove deprecated hack
The create now throws on relocation, so the whole operation is tried
again. No need to worry about object being relocated.
commit 02fb830f3e15239a263d109e8bda0256418401bb
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu May 16 16:14:06 2013 +0200
[2836] Clarify how to use the segment object holder
commit a5eb53f5b3fcf01e6df58325e11269e62e259197
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu May 16 16:06:52 2013 +0200
[2836] Clarify some Grown exceptions
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/memory/rdataset.h | 9 ++++++++
src/lib/datasrc/memory/segment_object_holder.h | 13 ++++++++++++
src/lib/datasrc/memory/zone_data.h | 27 ++++++++++++++++++++++++
src/lib/datasrc/memory/zone_data_updater.cc | 6 ------
src/lib/datasrc/memory/zone_data_updater.h | 8 ++++++-
src/lib/datasrc/memory/zone_table.h | 20 ++++++++++++++++--
src/lib/datasrc/memory/zone_writer.cc | 10 ++++-----
7 files changed, 78 insertions(+), 15 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/memory/rdataset.h b/src/lib/datasrc/memory/rdataset.h
index 58201b1..caef551 100644
--- a/src/lib/datasrc/memory/rdataset.h
+++ b/src/lib/datasrc/memory/rdataset.h
@@ -176,6 +176,15 @@ public:
/// it cannot contain more than 65535 RRSIGs. If the given RRset(s) fail
/// to meet this condition, an \c RdataSetError exception will be thrown.
///
+ /// This method ensures there'll be no memory leak on exception.
+ /// But addresses allocated from \c mem_sgmt could be relocated if
+ /// \c util::MemorySegmentGrown is thrown; the caller or its upper layer
+ /// must be aware of that possibility and update any such addresses
+ /// accordingly. On successful return, this method ensures there's no
+ /// address relocation.
+ ///
+ /// \throw util::MemorySegmentGrown The memory segment has grown, possibly
+ /// relocating data.
/// \throw isc::BadValue Given RRset(s) are invalid (see the description)
/// \throw RdataSetError Number of RDATAs exceed the limits
/// \throw std::bad_alloc Memory allocation fails.
diff --git a/src/lib/datasrc/memory/segment_object_holder.h b/src/lib/datasrc/memory/segment_object_holder.h
index 62b5a1c..a716d4a 100644
--- a/src/lib/datasrc/memory/segment_object_holder.h
+++ b/src/lib/datasrc/memory/segment_object_holder.h
@@ -37,6 +37,19 @@ getNextHolderName();
// A simple holder to create and use some objects in this implementation
// in an exception safe manner. It works like std::auto_ptr but much
// more simplified.
+//
+// Note, however, that it doesn't take the pointer to hold on construction.
+// This is because the constructor itself can throw or cause address
+// reallocation inside the memory segment. If that happens various
+// undesirable effects can happen, such as memory leak or unintentional access
+// to the pre-reallocated address. To make it safer, we use a separate
+// \c set() method, which is exception free and doesn't cause address
+// reallocation. So the typical usage is to first construct the holder
+// object, then the object to be held, immediately followed by a call to \c
+// set(). Subsequent access to the held address should be done via the \c get()
+// method. get() ensures the address is always valid in the memory segment
+// even if address reallocation happens between set() and get().
+//
// template parameter T is the type of object allocated by mem_sgmt.
// template parameter ARG_T is the type that will be passed to destroy()
// (deleter functor, etc). It must be copyable.
diff --git a/src/lib/datasrc/memory/zone_data.h b/src/lib/datasrc/memory/zone_data.h
index c6b3dcc..d511e47 100644
--- a/src/lib/datasrc/memory/zone_data.h
+++ b/src/lib/datasrc/memory/zone_data.h
@@ -86,6 +86,15 @@ public:
/// The NSEC3 parameters are extracted and stored within the created
/// \c NSEC3Data object.
///
+ /// This method ensures there'll be no memory leak on exception.
+ /// But addresses allocated from \c mem_sgmt could be relocated if
+ /// \c util::MemorySegmentGrown is thrown; the caller or its upper layer
+ /// must be aware of that possibility and update any such addresses
+ /// accordingly. On successful return, this method ensures there's no
+ /// address relocation.
+ ///
+ /// \throw util::MemorySegmentGrown The memory segment has grown, possibly
+ /// relocating data.
/// \throw std::bad_alloc Memory allocation fails.
///
/// \param mem_sgmt A \c MemorySegment from which memory for the new
@@ -102,6 +111,15 @@ public:
/// The NSEC3 hash parameters are extracted and stored within the created
/// \c NSEC3Data object.
///
+ /// This method ensures there'll be no memory leak on exception.
+ /// But addresses allocated from \c mem_sgmt could be relocated if
+ /// \c util::MemorySegmentGrown is thrown; the caller or its upper layer
+ /// must be aware of that possibility and update any such addresses
+ /// accordingly. On successful return, this method ensures there's no
+ /// address relocation.
+ ///
+ /// \throw util::MemorySegmentGrown The memory segment has grown, possibly
+ /// relocating data.
/// \throw std::bad_alloc Memory allocation fails.
///
/// \param mem_sgmt A \c MemorySegment from which memory for the new
@@ -375,6 +393,15 @@ public:
public:
/// \brief Allocate and construct \c ZoneData.
///
+ /// This method ensures there'll be no memory leak on exception.
+ /// But addresses allocated from \c mem_sgmt could be relocated if
+ /// \c util::MemorySegmentGrown is thrown; the caller or its upper layer
+ /// must be aware of that possibility and update any such addresses
+ /// accordingly. On successful return, this method ensures there's no
+ /// address relocation.
+ ///
+ /// \throw util::MemorySegmentGrown The memory segment has grown, possibly
+ /// relocating data.
/// \throw std::bad_alloc Memory allocation fails.
///
/// \param mem_sgmt A \c MemorySegment from which memory for the new
diff --git a/src/lib/datasrc/memory/zone_data_updater.cc b/src/lib/datasrc/memory/zone_data_updater.cc
index 734d40e..a8a88e6 100644
--- a/src/lib/datasrc/memory/zone_data_updater.cc
+++ b/src/lib/datasrc/memory/zone_data_updater.cc
@@ -234,12 +234,6 @@ ZoneDataUpdater::setupNSEC3(const ConstRRsetPtr rrset) {
NSEC3Data* nsec3_data = zone_data_->getNSEC3Data();
if (nsec3_data == NULL) {
nsec3_data = NSEC3Data::create(mem_sgmt_, zone_name_, nsec3_rdata);
- // The create above might have relocated data. So get it again,
- // just to make sure.
- zone_data_ =
- static_cast<ZoneData*>(mem_sgmt_.
- getNamedAddress("updater_zone_data").
- second);
zone_data_->setNSEC3Data(nsec3_data);
zone_data_->setSigned(true);
} else {
diff --git a/src/lib/datasrc/memory/zone_data_updater.h b/src/lib/datasrc/memory/zone_data_updater.h
index d802234..43da9f9 100644
--- a/src/lib/datasrc/memory/zone_data_updater.h
+++ b/src/lib/datasrc/memory/zone_data_updater.h
@@ -80,7 +80,13 @@ public:
isc_throw(isc::InvalidOperation, "A ZoneDataUpdater already exists"
" on this memory segment. Destroy it first.");
}
- mem_sgmt_.setNamedAddress("updater_zone_data", zone_data_);
+ if (mem_sgmt_.setNamedAddress("updater_zone_data", zone_data_)) {
+ // It might have relocated during the set
+ zone_data_ =
+ static_cast<ZoneData*>(mem_sgmt_.getNamedAddress("updater_zone_data").
+ second);
+ }
+ assert(zone_data_);
}
/// The destructor.
diff --git a/src/lib/datasrc/memory/zone_table.h b/src/lib/datasrc/memory/zone_table.h
index 9acbb92..d3bf903 100644
--- a/src/lib/datasrc/memory/zone_table.h
+++ b/src/lib/datasrc/memory/zone_table.h
@@ -115,6 +115,15 @@ public:
/// from the given memory segment, constructs the object, and returns
/// a pointer to it.
///
+ /// This method ensures there'll be no memory leak on exception.
+ /// But addresses allocated from \c mem_sgmt could be relocated if
+ /// \c util::MemorySegmentGrown is thrown; the caller or its upper layer
+ /// must be aware of that possibility and update any such addresses
+ /// accordingly. On successful return, this method ensures there's no
+ /// address relocation.
+ ///
+ /// \throw util::MemorySegmentGrown The memory segment has grown, possibly
+ /// relocating data.
/// \throw std::bad_alloc Memory allocation fails.
///
/// \param mem_sgmt A \c MemorySegment from which memory for the new
@@ -149,9 +158,16 @@ public:
///
/// This method adds a given zone data to the internal table.
///
+ /// This method ensures there'll be no memory leak on exception.
+ /// But addresses allocated from \c mem_sgmt could be relocated if
+ /// \c util::MemorySegmentGrown is thrown; the caller or its upper layer
+ /// must be aware of that possibility and update any such addresses
+ /// accordingly. On successful return, this method ensures there's no
+ /// address relocation.
+ ///
+ /// \throw util::MemorySegmentGrown The memory segment has grown, possibly
+ /// relocating data.
/// \throw std::bad_alloc Internal resource allocation fails.
- /// \throw MemorySegmentGrown when the memory segment grown and
- /// possibly relocated.
///
/// \param mem_sgmt The \c MemorySegment to allocate zone data to be
/// created. It must be the same segment that was used to create
diff --git a/src/lib/datasrc/memory/zone_writer.cc b/src/lib/datasrc/memory/zone_writer.cc
index e3c9039..a2b1ac7 100644
--- a/src/lib/datasrc/memory/zone_writer.cc
+++ b/src/lib/datasrc/memory/zone_writer.cc
@@ -54,14 +54,13 @@ ZoneWriter::load() {
}
zone_data_ = load_action_(segment_.getMemorySegment());
+ segment_.resetHeader();
if (!zone_data_) {
// Bug inside load_action_.
isc_throw(isc::InvalidOperation, "No data returned from load action");
}
- segment_.resetHeader();
-
state_ = ZW_LOADED;
}
@@ -86,11 +85,10 @@ ZoneWriter::install() {
zone_data_));
state_ = ZW_INSTALLED;
zone_data_ = result.zone_data;
- } catch (const isc::util::MemorySegmentGrown&) {
- }
- }
+ } catch (const isc::util::MemorySegmentGrown&) {}
- segment_.resetHeader();
+ segment_.resetHeader();
+ }
}
void
More information about the bind10-changes
mailing list