You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2012/03/17 23:53:20 UTC
[2/2] git commit: Header heap fixes.
Header heap fixes.
Authors and reviews: amc, bcall, igalic, jplevyak, jpeach, leif
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/019b503b
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/019b503b
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/019b503b
Branch: refs/heads/3.0.x
Commit: 019b503bf7345102d6425bc29b40ffde403784e6
Parents: dcb7c6b
Author: Leif Hedstrom <le...@ogre.com>
Authored: Sat Mar 17 16:48:08 2012 -0600
Committer: Leif Hedstrom <le...@ogre.com>
Committed: Sat Mar 17 16:51:57 2012 -0600
----------------------------------------------------------------------
proxy/hdrs/HdrHeap.cc | 2 ++
proxy/hdrs/HdrHeap.h | 29 ++++++++++++++++++++++++++++-
2 files changed, 30 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/019b503b/proxy/hdrs/HdrHeap.cc
----------------------------------------------------------------------
diff --git a/proxy/hdrs/HdrHeap.cc b/proxy/hdrs/HdrHeap.cc
index f72e5f0..c489388 100644
--- a/proxy/hdrs/HdrHeap.cc
+++ b/proxy/hdrs/HdrHeap.cc
@@ -338,7 +338,9 @@ HdrHeap::expand_str(const char *old_str, int old_len, int new_len)
char *
HdrHeap::duplicate_str(const char *str, int nbytes)
{
+ ProtectHeaps protect(this); // Don't let the source get de-allocated.
char *new_str = allocate_str(nbytes);
+
memcpy(new_str, str, nbytes);
return (new_str);
}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/019b503b/proxy/hdrs/HdrHeap.h
----------------------------------------------------------------------
diff --git a/proxy/hdrs/HdrHeap.h b/proxy/hdrs/HdrHeap.h
index 77d7a36..4d76f6b 100644
--- a/proxy/hdrs/HdrHeap.h
+++ b/proxy/hdrs/HdrHeap.h
@@ -251,11 +251,38 @@ public:
void evacuate_from_str_heaps(HdrStrHeap * new_heap);
int attach_str_heap(char *h_start, int h_len, RefCountObj * h_ref_obj, int *index);
+ /** Struct to prevent garbage collection on heaps.
+ This bumps the reference count to the heaps while the
+ instance of this class exists. When it goes out of scope
+ the references are dropped. This is useful inside a method or
+ block to keep all the heap data around until leaving the scope.
+ */
+ struct ProtectHeaps {
+ /// Construct the protection.
+ ProtectHeaps(HdrHeap* heap)
+ : m_read_write_heap(heap->m_read_write_heap)
+ {
+ for (int i=0; i < HDR_BUF_RONLY_HEAPS; ++i)
+ m_ronly_heap[i] = heap->m_ronly_heap[i].m_ref_count_ptr;
+ }
+
+ /// Drop the protection.
+ ~ProtectHeaps()
+ {
+ // The default destructor takes care of the rw-heap
+ for (int i=0; i < HDR_BUF_RONLY_HEAPS; ++i)
+ m_ronly_heap[i] = NULL;
+ }
+
+ Ptr<HdrStrHeap> m_read_write_heap; ///< Reference to RW heap.
+ /// References to string heaps.
+ Ptr<RefCountObj> m_ronly_heap[HDR_BUF_RONLY_HEAPS];
+ };
+
// String Heap access
Ptr<HdrStrHeap> m_read_write_heap;
StrHeapDesc m_ronly_heap[HDR_BUF_RONLY_HEAPS];
int m_lost_string_space;
-
};
inline void