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 2019/10/21 19:01:32 UTC
[trafficserver] branch 9.0.x updated: Destroy MIMEFieldBlockImpl
that doesn't have fields in use
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 08ed061 Destroy MIMEFieldBlockImpl that doesn't have fields in use
08ed061 is described below
commit 08ed0619e28f1b2aa396a7adf18792f56aad8409
Author: Masakazu Kitajo <ma...@apache.org>
AuthorDate: Fri Apr 19 17:06:37 2019 +0900
Destroy MIMEFieldBlockImpl that doesn't have fields in use
Because MIMEFieldBlocks are destroyed only when MIMEHdr is destroyed, the block
chain never be short. With this change, a block will be destroyed when all fields
in a block are deleted, and the block will be removed from a block chain.
(cherry picked from commit 482e30accbe2e755c73fd1f8dd7e4b2c40705171)
---
proxy/hdrs/MIME.cc | 40 +++++++++++++++++++++++++++-------------
proxy/hdrs/MIME.h | 3 +++
2 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/proxy/hdrs/MIME.cc b/proxy/hdrs/MIME.cc
index f37b95d..9f9c57c 100644
--- a/proxy/hdrs/MIME.cc
+++ b/proxy/hdrs/MIME.cc
@@ -1639,20 +1639,8 @@ mime_hdr_field_delete(HdrHeap *heap, MIMEHdrImpl *mh, MIMEField *field, bool del
{
if (delete_all_dups) {
while (field) {
- // NOTE: we pass zero to field_detach for detach_all_dups
- // since this loop will already detach each dup
MIMEField *next = field->m_next_dup;
-
- heap->free_string(field->m_ptr_name, field->m_len_name);
- heap->free_string(field->m_ptr_value, field->m_len_value);
-
- MIME_HDR_SANITY_CHECK(mh);
- mime_hdr_field_detach(mh, field, false);
-
- MIME_HDR_SANITY_CHECK(mh);
- mime_field_destroy(mh, field);
-
- MIME_HDR_SANITY_CHECK(mh);
+ mime_hdr_field_delete(heap, mh, field, false);
field = next;
}
} else {
@@ -1664,6 +1652,32 @@ mime_hdr_field_delete(HdrHeap *heap, MIMEHdrImpl *mh, MIMEField *field, bool del
MIME_HDR_SANITY_CHECK(mh);
mime_field_destroy(mh, field);
+
+ MIMEFieldBlockImpl *prev_block = nullptr;
+ bool can_destroy_block = true;
+ for (auto fblock = &(mh->m_first_fblock); fblock != nullptr; fblock = fblock->m_next) {
+ if (prev_block != nullptr) {
+ if (fblock->m_freetop == MIME_FIELD_BLOCK_SLOTS && fblock->contains(field)) {
+ // Check if fields in all slots are deleted
+ for (int i = 0; i < MIME_FIELD_BLOCK_SLOTS; ++i) {
+ if (fblock->m_field_slots[i].m_readiness != MIME_FIELD_SLOT_READINESS_DELETED) {
+ can_destroy_block = false;
+ break;
+ }
+ }
+ // Destroy a block and maintain the chain
+ if (can_destroy_block) {
+ prev_block->m_next = fblock->m_next;
+ _mime_field_block_destroy(heap, fblock);
+ if (prev_block->m_next == nullptr) {
+ mh->m_fblock_list_tail = prev_block;
+ }
+ }
+ break;
+ }
+ }
+ prev_block = fblock;
+ }
}
MIME_HDR_SANITY_CHECK(mh);
diff --git a/proxy/hdrs/MIME.h b/proxy/hdrs/MIME.h
index ebf1677..75a48f9 100644
--- a/proxy/hdrs/MIME.h
+++ b/proxy/hdrs/MIME.h
@@ -718,6 +718,9 @@ void mime_hdr_field_attach(MIMEHdrImpl *mh, MIMEField *field, int check_for_dups
void mime_hdr_field_detach(MIMEHdrImpl *mh, MIMEField *field, bool detach_all_dups = false);
void mime_hdr_field_delete(HdrHeap *heap, MIMEHdrImpl *mh, MIMEField *field, bool delete_all_dups = false);
+/**
+ * Returned slotnum is not a persistent value. A slotnum may refer a different field after making changes to a mime header.
+ */
int mime_hdr_field_slotnum(MIMEHdrImpl *mh, MIMEField *field);
inkcoreapi MIMEField *mime_hdr_prepare_for_value_set(HdrHeap *heap, MIMEHdrImpl *mh, const char *name, int name_length);