[trafficserver] branch 9.0.x updated: Fixed build issues on macOS after 0-RTT merge

2020-01-17 Thread zwoop
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 81f0c9d  Fixed build issues on macOS after 0-RTT merge
81f0c9d is described below

commit 81f0c9d22da659f7a97a544bbc4186b915fcb982
Author: Bryan Call 
AuthorDate: Thu Jan 16 09:57:03 2020 -0800

Fixed build issues on macOS after 0-RTT merge

(cherry picked from commit 3418938eddaf0005b8c8af882819041a59d7)
---
 iocore/net/SSLUtils.cc| 4 ++--
 proxy/http/Http1ClientSession.cc  | 2 +-
 proxy/http2/Http2ClientSession.cc | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/iocore/net/SSLUtils.cc b/iocore/net/SSLUtils.cc
index 8255221..812fd49 100644
--- a/iocore/net/SSLUtils.cc
+++ b/iocore/net/SSLUtils.cc
@@ -1797,9 +1797,9 @@ SSLReadBuffer(SSL *ssl, void *buf, int64_t nbytes, 
int64_t )
 
 if (ret == SSL_READ_EARLY_DATA_FINISH) {
   netvc->early_data_finish = true;
-  Debug("ssl_early_data", "SSL_READ_EARLY_DATA_FINISH: size = %lu", 
nread);
+  Debug("ssl_early_data", "SSL_READ_EARLY_DATA_FINISH: size = %" 
PRId64, nread);
 } else {
-  Debug("ssl_early_data", "SSL_READ_EARLY_DATA_SUCCESS: size = %lu", 
nread);
+  Debug("ssl_early_data", "SSL_READ_EARLY_DATA_SUCCESS: size = %" 
PRId64, nread);
 }
   }
 
diff --git a/proxy/http/Http1ClientSession.cc b/proxy/http/Http1ClientSession.cc
index 1196b3d..e7e8809 100644
--- a/proxy/http/Http1ClientSession.cc
+++ b/proxy/http/Http1ClientSession.cc
@@ -142,7 +142,7 @@ Http1ClientSession::new_connection(NetVConnection *new_vc, 
MIOBuffer *iobuf, IOB
   SSLNetVConnection *ssl_vc = dynamic_cast(new_vc);
   if (ssl_vc != nullptr) {
 read_from_early_data = ssl_vc->read_from_early_data;
-Debug("ssl_early_data", "read_from_early_data = %ld", 
read_from_early_data);
+Debug("ssl_early_data", "read_from_early_data = %" PRId64, 
read_from_early_data);
   }
 
   MUTEX_TRY_LOCK(lock, mutex, this_ethread());
diff --git a/proxy/http2/Http2ClientSession.cc 
b/proxy/http2/Http2ClientSession.cc
index e2fdcdb..10378c7 100644
--- a/proxy/http2/Http2ClientSession.cc
+++ b/proxy/http2/Http2ClientSession.cc
@@ -202,7 +202,7 @@ Http2ClientSession::new_connection(NetVConnection *new_vc, 
MIOBuffer *iobuf, IOB
   SSLNetVConnection *ssl_vc = dynamic_cast(new_vc);
   if (ssl_vc != nullptr) {
 this->read_from_early_data = ssl_vc->read_from_early_data;
-Debug("ssl_early_data", "read_from_early_data = %ld", 
this->read_from_early_data);
+Debug("ssl_early_data", "read_from_early_data = %" PRId64, 
this->read_from_early_data);
   }
 
   Http2SsnDebug("session born, netvc %p", this->client_vc);



[trafficserver] branch 9.0.x updated (d5c40ad -> a3dfab9)

2020-01-17 Thread calavera
This is an automated email from the ASF dual-hosted git repository.

calavera pushed a change to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git.


 discard d5c40ad  Fix problems with "Probe" option for X-Debug MIME header 
field. (#6197)
 discard 571819b  Fix some long lines and reduntant plugin_config SO additions.
 discard b87a3a1  remap_stats: restore handling of remap/hostname to remove 
memory leak
 discard 5da57c1  Updated ChangeLog
 discard 0ac0d0d  Adding max line length configuration documentation.
 discard 67890c3  Fixes typo in TLS Bridge illustration
 discard 597b383  Fixed build issues on macOS after 0-RTT merge

This update removed existing revisions from the reference, leaving the
reference pointing at a previous point in the repository history.

 * -- * -- N   refs/heads/9.0.x (a3dfab9)
\
 O -- O -- O   (d5c40ad)

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

No new revisions were added by this update.

Summary of changes:
 CHANGELOG-9.0.0|   3 -
 doc/admin-guide/logging/formatting.en.rst  |  32 ---
 doc/uml/TLS-Bridge-Messages.uml|   2 +-
 iocore/net/SSLUtils.cc |   4 +-
 plugins/experimental/remap_stats/remap_stats.cc|  75 +++--
 plugins/xdebug/Cleanup.h   | 186 
 plugins/xdebug/Makefile.inc|   4 +-
 plugins/xdebug/xdebug.cc   |  69 ++---
 plugins/xdebug/xdebug_transforms.cc|  44 ++-
 proxy/http/Http1ClientSession.cc   |   2 +-
 proxy/http2/Http2ClientSession.cc  |   2 +-
 tests/gold_tests/headers/syntax.test.py|  10 +-
 .../pluginTest/cert_update/cert_update.test.py |   4 +
 tests/gold_tests/pluginTest/xdebug/x_remap/four.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd1.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd2.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd3.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd4.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd5.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/none.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/one.in  |   3 +-
 .../gold_tests/pluginTest/xdebug/x_remap/out.gold  | 315 +
 .../gold_tests/pluginTest/xdebug/x_remap/three.in  |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/two.in  |   3 +-
 .../pluginTest/xdebug/x_remap/x_remap.gold |   6 +-
 .../pluginTest/xdebug/x_remap/x_remap.test.py  |   5 +-
 tests/gold_tests/remap/remap_http.test.py  |  12 +-
 tests/gold_tests/remap/remap_https.test.py |   6 +-
 tests/gold_tests/slow_post/slow_post.test.py   |   3 +
 29 files changed, 136 insertions(+), 678 deletions(-)
 delete mode 100644 plugins/xdebug/Cleanup.h



[trafficserver] 02/02: Fix problems with "Probe" option for X-Debug MIME header field. (#6197)

2020-01-17 Thread zwoop
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

commit d5c40adefa7fac772dadc28844bfb3b2df347688
Author: Walt Karas 
AuthorDate: Fri Jan 17 14:16:57 2020 -0600

Fix problems with "Probe" option for X-Debug MIME header field. (#6197)

Fix problems with "Probe" option for X-Debug MIME header field.
- Adds exercise of "Probe" to the existing x_remap Au test.
- Remove memory leaks and risk of double deletion in xdebug plugin.

(cherry picked from commit 473e0549cbb7bda763340b842d447d9db0d49879)
---
 plugins/xdebug/Cleanup.h   | 186 
 plugins/xdebug/Makefile.inc|   4 +-
 plugins/xdebug/xdebug.cc   |  69 +++--
 plugins/xdebug/xdebug_transforms.cc|  44 +--
 tests/gold_tests/pluginTest/xdebug/x_remap/four.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd1.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd2.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd3.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd4.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd5.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/none.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/one.in  |   3 +-
 .../gold_tests/pluginTest/xdebug/x_remap/out.gold  | 315 -
 .../gold_tests/pluginTest/xdebug/x_remap/three.in  |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/two.in  |   3 +-
 .../pluginTest/xdebug/x_remap/x_remap.gold |   6 +-
 .../pluginTest/xdebug/x_remap/x_remap.test.py  |   4 +-
 17 files changed, 577 insertions(+), 81 deletions(-)

diff --git a/plugins/xdebug/Cleanup.h b/plugins/xdebug/Cleanup.h
new file mode 100644
index 000..453903c
--- /dev/null
+++ b/plugins/xdebug/Cleanup.h
@@ -0,0 +1,186 @@
+/**
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+/**
+ * @file Cleanup.h
+ * @brief Easy-to-use utilities to avoid resource leaks or double-releases of 
resources.  Independent of the rest
+ *of the CPPAPI.
+ */
+
+#pragma once
+
+#include 
+#include 
+
+#include 
+
+namespace atscppapi
+{
+// For TS API types TSXxx with a TSXxxDestroy function, define standard 
deleter TSXxxDeleter, and use it to
+// define TSXxxUniqPtr (specialization of std::unique_ptr).  X() is used when 
the destroy function returns void,
+// Y() is used when the destroy function returns TSReturnCode.
+
+#if defined(X)
+#error "X defined as preprocessor symbol"
+#endif
+
+#define X(NAME_SEGMENT)   \
+  struct TS##NAME_SEGMENT##Deleter {  \
+void  \
+operator()(TS##NAME_SEGMENT ptr)  \
+{ \
+  TS##NAME_SEGMENT##Destroy(ptr); \
+} \
+  };  \
+  using TS##NAME_SEGMENT##UniqPtr = 
std::unique_ptr, 
TS##NAME_SEGMENT##Deleter>;
+
+#if defined(Y)
+#error "Y defined as preprocessor symbol"
+#endif
+
+#define Y(NAME_SEGMENT)   \
+  struct TS##NAME_SEGMENT##Deleter {  \
+void  \
+operator()(TS##NAME_SEGMENT ptr)  \
+{ \
+  TSAssert(TS##NAME_SEGMENT##Destroy(ptr) == TS_SUCCESS); \
+} \
+  };  \
+  using TS##NAME_SEGMENT##UniqPtr = 
std::unique_ptr, 
TS##NAME_SEGMENT##Deleter>;
+
+Y(MBuffer)   // Defines TSMBufferDeleter and TSMBufferUniqPtr.
+X(MimeParser)// Defines TSMimeParserDeleter and TSMimeParserUniqPtr.
+X(Thread)// Defines TSThreadDeleter and TSThreadUniqPtr.
+X(Mutex) // Defines TSMutexDeleter and TSMutexUniqPtr.
+Y(CacheKey)  // Defines TSCacheKeyDeleter and TSCacheKeyUniqPtr.
+X(Cont)  // Defines TSContDeleter and TSContUniqPtr.
+X(SslContext)// Defines TSSslContextDeleter and TSSslContextUniqPtr.
+X(IOBuffer)  // Defines TSIOBufferDeleter and 

[trafficserver] branch 9.0.x updated (b87a3a1 -> d5c40ad)

2020-01-17 Thread zwoop
This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a change to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git.


from b87a3a1  remap_stats: restore handling of remap/hostname to remove 
memory leak
 new 571819b  Fix some long lines and reduntant plugin_config SO additions.
 new d5c40ad  Fix problems with "Probe" option for X-Debug MIME header 
field. (#6197)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 plugins/xdebug/Cleanup.h   | 186 
 plugins/xdebug/Makefile.inc|   4 +-
 plugins/xdebug/xdebug.cc   |  69 +++--
 plugins/xdebug/xdebug_transforms.cc|  44 +--
 tests/gold_tests/headers/syntax.test.py|  10 +-
 .../pluginTest/cert_update/cert_update.test.py |   4 -
 tests/gold_tests/pluginTest/xdebug/x_remap/four.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd1.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd2.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd3.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd4.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd5.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/none.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/one.in  |   3 +-
 .../gold_tests/pluginTest/xdebug/x_remap/out.gold  | 315 -
 .../gold_tests/pluginTest/xdebug/x_remap/three.in  |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/two.in  |   3 +-
 .../pluginTest/xdebug/x_remap/x_remap.gold |   6 +-
 .../pluginTest/xdebug/x_remap/x_remap.test.py  |   5 +-
 tests/gold_tests/remap/remap_http.test.py  |  12 +-
 tests/gold_tests/remap/remap_https.test.py |   6 +-
 tests/gold_tests/slow_post/slow_post.test.py   |   3 -
 22 files changed, 595 insertions(+), 99 deletions(-)
 create mode 100644 plugins/xdebug/Cleanup.h



[trafficserver] 01/02: Fix some long lines and reduntant plugin_config SO additions.

2020-01-17 Thread zwoop
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

commit 571819b1f45d5462ba6315ed65d722368335e297
Author: bneradt 
AuthorDate: Fri Oct 18 15:26:43 2019 +

Fix some long lines and reduntant plugin_config SO additions.

(cherry picked from commit 15b0051fa2230bb60922943f4207b4a811f65430)
---
 tests/gold_tests/headers/syntax.test.py | 10 +-
 tests/gold_tests/pluginTest/cert_update/cert_update.test.py |  4 
 tests/gold_tests/pluginTest/xdebug/x_remap/x_remap.test.py  |  5 +++--
 tests/gold_tests/remap/remap_http.test.py   | 12 
 tests/gold_tests/remap/remap_https.test.py  |  6 --
 tests/gold_tests/slow_post/slow_post.test.py|  3 ---
 6 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/tests/gold_tests/headers/syntax.test.py 
b/tests/gold_tests/headers/syntax.test.py
index d6a6929..0fc79db 100644
--- a/tests/gold_tests/headers/syntax.test.py
+++ b/tests/gold_tests/headers/syntax.test.py
@@ -37,7 +37,7 @@ ts.Disk.remap_config.AddLine(
 'map http://www.example.com 
http://127.0.0.1:{0}'.format(server.Variables.Port)
 )
 
-# Test 1 - 200 Response
+# Test 0 - 200 Response
 tr = Test.AddTestRun()
 tr.Processes.Default.StartBefore(server, 
ready=When.PortOpen(server.Variables.Port))
 tr.Processes.Default.StartBefore(Test.Processes.ts, 
ready=When.PortOpen(ts.Variables.port))
@@ -46,21 +46,21 @@ tr.Processes.Default.ReturnCode = 0
 tr.Processes.Default.Streams.stdout = "syntax.200.gold"
 tr.StillRunningAfter = ts
 
-# Test 2 - 400 Response - Single space after field name
+# Test 1 - 400 Response - Single space after field name
 tr = Test.AddTestRun()
 tr.Processes.Default.Command = 'curl -s -D - -v --ipv4 --http1.1 -H "foo : 
bar" -H "Host: www.example.com" http://localhost:{0}/'.format(ts.Variables.port)
 tr.Processes.Default.ReturnCode = 0
 tr.Processes.Default.Streams.stdout = "syntax.400.gold"
 tr.StillRunningAfter = ts
 
-# Test 3 - 400 Response - Double space after field name
+# Test 2 - 400 Response - Double space after field name
 tr = Test.AddTestRun()
 tr.Processes.Default.Command = 'curl -s -D - -v --ipv4 --http1.1 -H "foo  : 
bar" -H "Host: www.example.com" http://localhost:{0}/'.format(ts.Variables.port)
 tr.Processes.Default.ReturnCode = 0
 tr.Processes.Default.Streams.stdout = "syntax.400.gold"
 tr.StillRunningAfter = ts
 
-# Test 4 - 400 Response - Three different Content-Length headers
+# Test 3 - 400 Response - Three different Content-Length headers
 tr = Test.AddTestRun()
 tr.Processes.Default.Command = 'curl -s -D - -v --ipv4 --http1.1 -d "hello 
world" -H "Content-Length: 11" -H "Content-Length: 10" -H "Content-Length: 9" 
-H "Host: www.example.com" http://localhost:{0}/'.format(ts.Variables.port)
 tr.Processes.Default.ReturnCode = 0
@@ -74,7 +74,7 @@ tr.Processes.Default.ReturnCode = 0
 tr.Processes.Default.Streams.stdout = "syntax.200.gold"
 tr.StillRunningAfter = ts
 
-# Test 4 - 200 Response - Three different Content-Length headers with a 
Transfer ecoding header
+# Test 5 - 200 Response - Three different Content-Length headers with a 
Transfer encoding header
 tr = Test.AddTestRun()
 tr.Processes.Default.Command = 'curl -s -D - -v --ipv4 --http1.1 -d "hello 
world" -H "Transfer-Encoding: chunked" -H "Content-Length: 11" -H 
"Content-Length: 10" -H "Content-Length: 9" -H "Host: www.example.com" 
http://localhost:{0}/'.format(ts.Variables.port)
 tr.Processes.Default.ReturnCode = 0
diff --git a/tests/gold_tests/pluginTest/cert_update/cert_update.test.py 
b/tests/gold_tests/pluginTest/cert_update/cert_update.test.py
index 642c328..0e2beb4 100644
--- a/tests/gold_tests/pluginTest/cert_update/cert_update.test.py
+++ b/tests/gold_tests/pluginTest/cert_update/cert_update.test.py
@@ -75,10 +75,6 @@ ts.Disk.sni_yaml.AddLines([
 # Set up plugin
 Test.PreparePlugin(Test.Variables.AtsExampleDir + 
'/plugins/c-api/cert_update/cert_update.cc', ts)
 
-ts.Disk.plugin_config.AddLine(
-'cert_update.so'
-)
-
 # Server-Cert-Pre
 # curl should see that Traffic Server presents bar.com cert from alice
 tr = Test.AddTestRun("Server-Cert-Pre")
diff --git a/tests/gold_tests/pluginTest/xdebug/x_remap/x_remap.test.py 
b/tests/gold_tests/pluginTest/xdebug/x_remap/x_remap.test.py
index fb070d0..89db82a 100644
--- a/tests/gold_tests/pluginTest/xdebug/x_remap/x_remap.test.py
+++ b/tests/gold_tests/pluginTest/xdebug/x_remap/x_remap.test.py
@@ -21,8 +21,9 @@ Test xdebug plugin X-Remap and fwd headers
 server = Test.MakeOriginServer("server", options={'--load': 
(Test.TestDirectory + '/x_remap-observer.py')})
 
 request_header = {
-"headers": "GET /argh HTTP/1.1\r\nHost: doesnotmatter\r\n\r\n", 
"timestamp": "1469733493.993", "body": "" }
-response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", 
"timestamp": "1469733493.993", "body": "" }
+

[trafficserver] branch master updated: Fix problems with "Probe" option for X-Debug MIME header field. (#6197)

2020-01-17 Thread bcall
This is an automated email from the ASF dual-hosted git repository.

bcall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
 new 473e054  Fix problems with "Probe" option for X-Debug MIME header 
field. (#6197)
473e054 is described below

commit 473e0549cbb7bda763340b842d447d9db0d49879
Author: Walt Karas 
AuthorDate: Fri Jan 17 14:16:57 2020 -0600

Fix problems with "Probe" option for X-Debug MIME header field. (#6197)

Fix problems with "Probe" option for X-Debug MIME header field.
- Adds exercise of "Probe" to the existing x_remap Au test.
- Remove memory leaks and risk of double deletion in xdebug plugin.
---
 plugins/xdebug/Cleanup.h   | 186 
 plugins/xdebug/Makefile.inc|   4 +-
 plugins/xdebug/xdebug.cc   |  69 +++--
 plugins/xdebug/xdebug_transforms.cc|  44 +--
 tests/gold_tests/pluginTest/xdebug/x_remap/four.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd1.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd2.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd3.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd4.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/fwd5.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/none.in |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/one.in  |   3 +-
 .../gold_tests/pluginTest/xdebug/x_remap/out.gold  | 315 -
 .../gold_tests/pluginTest/xdebug/x_remap/three.in  |   3 +-
 tests/gold_tests/pluginTest/xdebug/x_remap/two.in  |   3 +-
 .../pluginTest/xdebug/x_remap/x_remap.gold |   6 +-
 .../pluginTest/xdebug/x_remap/x_remap.test.py  |   4 +-
 17 files changed, 577 insertions(+), 81 deletions(-)

diff --git a/plugins/xdebug/Cleanup.h b/plugins/xdebug/Cleanup.h
new file mode 100644
index 000..453903c
--- /dev/null
+++ b/plugins/xdebug/Cleanup.h
@@ -0,0 +1,186 @@
+/**
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+/**
+ * @file Cleanup.h
+ * @brief Easy-to-use utilities to avoid resource leaks or double-releases of 
resources.  Independent of the rest
+ *of the CPPAPI.
+ */
+
+#pragma once
+
+#include 
+#include 
+
+#include 
+
+namespace atscppapi
+{
+// For TS API types TSXxx with a TSXxxDestroy function, define standard 
deleter TSXxxDeleter, and use it to
+// define TSXxxUniqPtr (specialization of std::unique_ptr).  X() is used when 
the destroy function returns void,
+// Y() is used when the destroy function returns TSReturnCode.
+
+#if defined(X)
+#error "X defined as preprocessor symbol"
+#endif
+
+#define X(NAME_SEGMENT)   \
+  struct TS##NAME_SEGMENT##Deleter {  \
+void  \
+operator()(TS##NAME_SEGMENT ptr)  \
+{ \
+  TS##NAME_SEGMENT##Destroy(ptr); \
+} \
+  };  \
+  using TS##NAME_SEGMENT##UniqPtr = 
std::unique_ptr, 
TS##NAME_SEGMENT##Deleter>;
+
+#if defined(Y)
+#error "Y defined as preprocessor symbol"
+#endif
+
+#define Y(NAME_SEGMENT)   \
+  struct TS##NAME_SEGMENT##Deleter {  \
+void  \
+operator()(TS##NAME_SEGMENT ptr)  \
+{ \
+  TSAssert(TS##NAME_SEGMENT##Destroy(ptr) == TS_SUCCESS); \
+} \
+  };  \
+  using TS##NAME_SEGMENT##UniqPtr = 
std::unique_ptr, 
TS##NAME_SEGMENT##Deleter>;
+
+Y(MBuffer)   // Defines TSMBufferDeleter and TSMBufferUniqPtr.
+X(MimeParser)// Defines TSMimeParserDeleter and TSMimeParserUniqPtr.
+X(Thread)// Defines TSThreadDeleter and TSThreadUniqPtr.
+X(Mutex) // Defines TSMutexDeleter and TSMutexUniqPtr.
+Y(CacheKey)  // Defines TSCacheKeyDeleter and TSCacheKeyUniqPtr.
+X(Cont)  // Defines TSContDeleter and TSContUniqPtr.
+X(SslContext)// 

[trafficserver] branch 9.0.x updated: remap_stats: restore handling of remap/hostname to remove memory leak

2020-01-17 Thread zwoop
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 b87a3a1  remap_stats: restore handling of remap/hostname to remove 
memory leak
b87a3a1 is described below

commit b87a3a1aae00f702d4f24570588be44c257d82d6
Author: Brian Olsen 
AuthorDate: Mon Dec 2 21:09:35 2019 +

remap_stats: restore handling of remap/hostname to remove memory leak

(cherry picked from commit e622ae26bf1bb4a3dd815c066bd547d97e2e9185)
---
 plugins/experimental/remap_stats/remap_stats.cc | 75 ++---
 1 file changed, 43 insertions(+), 32 deletions(-)

diff --git a/plugins/experimental/remap_stats/remap_stats.cc 
b/plugins/experimental/remap_stats/remap_stats.cc
index 6b4751f..df252d3 100644
--- a/plugins/experimental/remap_stats/remap_stats.cc
+++ b/plugins/experimental/remap_stats/remap_stats.cc
@@ -44,11 +44,13 @@ struct config_t {
 // From "core" sigh, but we need it for now at least.
 extern int max_records_entries;
 
-static void
+namespace
+{
+void
 stat_add(const char *name, TSMgmtInt amount, TSStatPersistence persist_type, 
TSMutex create_mutex)
 {
-  int stat_id = -1;
   static thread_local std::unordered_map hash;
+  int stat_id = -1;
 
   if (unlikely(hash.find(name) == hash.cend())) {
 // This is an unlikely path because we most likely have the stat cached
@@ -80,7 +82,7 @@ stat_add(const char *name, TSMgmtInt amount, 
TSStatPersistence persist_type, TSM
   }
 }
 
-static char *
+char *
 get_effective_host(TSHttpTxn txn)
 {
   char *effective_url, *tmp;
@@ -93,7 +95,7 @@ get_effective_host(TSHttpTxn txn)
   if (TS_SUCCESS != TSUrlCreate(buf, _loc)) {
 TSDebug(DEBUG_TAG, "unable to create url");
 TSMBufferDestroy(buf);
-return NULL;
+return nullptr;
   }
   tmp = effective_url = TSHttpTxnEffectiveUrlStringGet(txn, );
   TSUrlParse(buf, url_loc, (const char **)(), (const char *)(effective_url 
+ len));
@@ -105,7 +107,7 @@ get_effective_host(TSHttpTxn txn)
   return tmp;
 }
 
-static int
+int
 handle_read_req_hdr(TSCont cont, TSEvent event ATS_UNUSED, void *edata)
 {
   TSHttpTxn txn = (TSHttpTxn)edata;
@@ -121,7 +123,7 @@ handle_read_req_hdr(TSCont cont, TSEvent event ATS_UNUSED, 
void *edata)
   return 0;
 }
 
-static int
+int
 handle_post_remap(TSCont cont, TSEvent event ATS_UNUSED, void *edata)
 {
   TSHttpTxn txn = static_cast(edata);
@@ -142,7 +144,7 @@ handle_post_remap(TSCont cont, TSEvent event ATS_UNUSED, 
void *edata)
   return 0;
 }
 
-static void
+void
 create_stat_name(ts::FixedBufferWriter _name, std::string_view h, 
std::string_view b)
 {
   stat_name.reset().clip(1);
@@ -150,52 +152,53 @@ create_stat_name(ts::FixedBufferWriter _name, 
std::string_view h, std::stri
   stat_name.extend(1).write('\0');
 }
 
-static int
+int
 handle_txn_close(TSCont cont, TSEvent event ATS_UNUSED, void *edata)
 {
-  TSHttpTxn txn = static_cast(edata);
-  config_t *config;
-  void *txnd;
-  int status_code = 0;
-  TSMBuffer buf;
-  TSMLoc hdr_loc;
-  uint64_t out_bytes, in_bytes;
-  std::string_view remap, hostname;
-  std::string_view unknown("unknown");
-  ts::LocalBufferWriter stat_name;
+  TSHttpTxn const txn  = static_cast(edata);
+  char const *remap= nullptr;
+  char *hostname   = nullptr;
+  char *effective_hostname = nullptr;
 
-  config = static_cast(TSContDataGet(cont));
-  txnd   = TSHttpTxnArgGet(txn, config->txn_slot);
+  static char const *const unknown = "unknown";
 
-  hostname = std::string_view(reinterpret_cast(reinterpret_cast(txnd) & ~0x01)); // Get hostname
+  config_t const *const config = static_cast(TSContDataGet(cont));
+  void const *const txnd   = TSHttpTxnArgGet(txn, config->txn_slot);
 
-  if (txnd) {
+  hostname = reinterpret_cast(reinterpret_cast(txnd) & 
~0x01); // Get hostname
+
+  if (nullptr != txnd) {
 if (reinterpret_cast(txnd) & 0x01) // remap succeeded?
 {
   if (!config->post_remap_host) {
 remap = hostname;
   } else {
-remap = get_effective_host(txn);
+effective_hostname = get_effective_host(txn);
+remap  = effective_hostname;
   }
 
-  if (remap.empty()) {
+  if (nullptr == remap) {
 remap = unknown;
   }
 
-  in_bytes = TSHttpTxnClientReqHdrBytesGet(txn);
+  uint64_t in_bytes = TSHttpTxnClientReqHdrBytesGet(txn);
   in_bytes += TSHttpTxnClientReqBodyBytesGet(txn);
 
+  ts::LocalBufferWriter stat_name;
+
   create_stat_name(stat_name, remap, "in_bytes");
   stat_add(stat_name.data(), static_cast(in_bytes), 
config->persist_type, config->stat_creation_mutex);
 
-  out_bytes = TSHttpTxnClientRespHdrBytesGet(txn);
+  uint64_t out_bytes = TSHttpTxnClientRespHdrBytesGet(txn);
   out_bytes += TSHttpTxnClientRespBodyBytesGet(txn);
 
   create_stat_name(stat_name, remap, "out_bytes");