You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2015/01/30 04:33:07 UTC
trafficserver git commit: TS-3287: fix a minor traffic_via memory leak
Repository: trafficserver
Updated Branches:
refs/heads/master 326bf1059 -> e7d02d92a
TS-3287: fix a minor traffic_via memory leak
Fix a minor traffic_via memory leak when given a bad Via string.
Add a simple set of golden-output tests.
Coverity CID #1226154, #1226155
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/e7d02d92
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/e7d02d92
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/e7d02d92
Branch: refs/heads/master
Commit: e7d02d92a8e55523043154129a3fccc5577105dd
Parents: 326bf10
Author: James Peach <jp...@apache.org>
Authored: Wed Jan 21 12:57:13 2015 -0800
Committer: James Peach <jp...@apache.org>
Committed: Thu Jan 29 19:25:29 2015 -0800
----------------------------------------------------------------------
cmd/traffic_via/Makefile.am | 3 ++
cmd/traffic_via/test_traffic_via | 30 ++++++++++++++++++++
.../tests/[u c s f p eS:tNc i p s ] | 14 +++++++++
.../tests/[uIcRs f p eN:t cCHi p s ] | 14 +++++++++
.../tests/[uIcRs f p eN:t cCNi p s ] | 14 +++++++++
.../tests/[uScMsSf pSeN:t cCMi p sS] | 14 +++++++++
.../tests/[uScRs f p eN:t cCHi p s ] | 14 +++++++++
cmd/traffic_via/tests/long rubbish via code 24 | 20 +++++++++++++
cmd/traffic_via/tests/rubbish | 4 +++
cmd/traffic_via/tests/short | 7 +++++
cmd/traffic_via/traffic_via.cc | 8 ++++--
11 files changed, 139 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e7d02d92/cmd/traffic_via/Makefile.am
----------------------------------------------------------------------
diff --git a/cmd/traffic_via/Makefile.am b/cmd/traffic_via/Makefile.am
index c9482e2..c7f0888 100644
--- a/cmd/traffic_via/Makefile.am
+++ b/cmd/traffic_via/Makefile.am
@@ -32,3 +32,6 @@ traffic_via_LDFLAGS = @EXTRA_CXX_LDFLAGS@ @LIBTOOL_LINK_FLAGS@
traffic_via_LDADD = \
$(top_builddir)/lib/ts/libtsutil.la \
@LIBTCL@
+
+TESTS = \
+ test_traffic_via
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e7d02d92/cmd/traffic_via/test_traffic_via
----------------------------------------------------------------------
diff --git a/cmd/traffic_via/test_traffic_via b/cmd/traffic_via/test_traffic_via
new file mode 100755
index 0000000..667fa02
--- /dev/null
+++ b/cmd/traffic_via/test_traffic_via
@@ -0,0 +1,30 @@
+#! /usr/bin/env bash
+#
+# 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.
+
+set -e # exit on error
+
+TMPDIR=${TMPDIR:-/tmp}
+tmpfile=$(mktemp "$TMPDIR/via.XXXXXX")
+srcdir=$(cd $srcdir && pwd)
+
+find $srcdir/tests -type f |
+while read f ; do
+ name=$(basename "$f")
+ ./traffic_via "$name" > "$tmpfile" 2>&1 || true
+ diff -u "$tmpfile" "$srcdir/tests/$name"
+done
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e7d02d92/cmd/traffic_via/tests/[u c s f p eS:tNc i p s ]
----------------------------------------------------------------------
diff --git a/cmd/traffic_via/tests/[u c s f p eS:tNc i p s ] b/cmd/traffic_via/tests/[u c s f p eS:tNc i p s ]
new file mode 100644
index 0000000..8195fd8
--- /dev/null
+++ b/cmd/traffic_via/tests/[u c s f p eS:tNc i p s ]
@@ -0,0 +1,14 @@
+Via header is [u c s f p eS:tNc i p s ], Length is 26
+Via Header Details:
+Request headers received from client :unknown
+Result of Traffic Server cache lookup for URL :no cache lookup
+Response information received from origin server :no server connection needed
+Result of document write-to-cache: :no cache write performed
+Proxy operation result :unknown
+Error codes (if any) :server related error
+Tunnel info :tunneling due to no forward
+Cache Type :unknown
+Cache Lookup Result :cache miss or no cache lookup
+ICP status :no icp
+Parent proxy connection status :no parent proxy or unknown
+Origin server connection status :no server connection needed
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e7d02d92/cmd/traffic_via/tests/[uIcRs f p eN:t cCHi p s ]
----------------------------------------------------------------------
diff --git a/cmd/traffic_via/tests/[uIcRs f p eN:t cCHi p s ] b/cmd/traffic_via/tests/[uIcRs f p eN:t cCHi p s ]
new file mode 100644
index 0000000..73a2f47
--- /dev/null
+++ b/cmd/traffic_via/tests/[uIcRs f p eN:t cCHi p s ]
@@ -0,0 +1,14 @@
+Via header is [uIcRs f p eN:t cCHi p s ], Length is 26
+Via Header Details:
+Request headers received from client :IMS
+Result of Traffic Server cache lookup for URL :in cache, fresh Ram hit (a cache "HIT")
+Response information received from origin server :no server connection needed
+Result of document write-to-cache: :no cache write performed
+Proxy operation result :unknown
+Error codes (if any) :no error
+Tunnel info :no tunneling
+Cache Type :cache
+Cache Lookup Result :cache hit
+ICP status :no icp
+Parent proxy connection status :no parent proxy or unknown
+Origin server connection status :no server connection needed
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e7d02d92/cmd/traffic_via/tests/[uIcRs f p eN:t cCNi p s ]
----------------------------------------------------------------------
diff --git a/cmd/traffic_via/tests/[uIcRs f p eN:t cCNi p s ] b/cmd/traffic_via/tests/[uIcRs f p eN:t cCNi p s ]
new file mode 100644
index 0000000..00a38f3
--- /dev/null
+++ b/cmd/traffic_via/tests/[uIcRs f p eN:t cCNi p s ]
@@ -0,0 +1,14 @@
+Via header is [uIcRs f p eN:t cCNi p s ], Length is 26
+Via Header Details:
+Request headers received from client :IMS
+Result of Traffic Server cache lookup for URL :in cache, fresh Ram hit (a cache "HIT")
+Response information received from origin server :no server connection needed
+Result of document write-to-cache: :no cache write performed
+Proxy operation result :unknown
+Error codes (if any) :no error
+Tunnel info :no tunneling
+Cache Type :cache
+Cache Lookup Result :conditional hit (client sent conditional, doc fresh in cache, returned 304)
+ICP status :no icp
+Parent proxy connection status :no parent proxy or unknown
+Origin server connection status :no server connection needed
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e7d02d92/cmd/traffic_via/tests/[uScMsSf pSeN:t cCMi p sS]
----------------------------------------------------------------------
diff --git a/cmd/traffic_via/tests/[uScMsSf pSeN:t cCMi p sS] b/cmd/traffic_via/tests/[uScMsSf pSeN:t cCMi p sS]
new file mode 100644
index 0000000..a69506f
--- /dev/null
+++ b/cmd/traffic_via/tests/[uScMsSf pSeN:t cCMi p sS]
@@ -0,0 +1,14 @@
+Via header is [uScMsSf pSeN:t cCMi p sS], Length is 26
+Via Header Details:
+Request headers received from client :simple request (not conditional)
+Result of Traffic Server cache lookup for URL :miss (a cache "MISS")
+Response information received from origin server :connection opened successfully
+Result of document write-to-cache: :no cache write performed
+Proxy operation result :served or connection opened successfully
+Error codes (if any) :no error
+Tunnel info :no tunneling
+Cache Type :cache
+Cache Lookup Result :cache miss (url not in cache)
+ICP status :no icp
+Parent proxy connection status :no parent proxy or unknown
+Origin server connection status :connection opened successfully
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e7d02d92/cmd/traffic_via/tests/[uScRs f p eN:t cCHi p s ]
----------------------------------------------------------------------
diff --git a/cmd/traffic_via/tests/[uScRs f p eN:t cCHi p s ] b/cmd/traffic_via/tests/[uScRs f p eN:t cCHi p s ]
new file mode 100644
index 0000000..ff62044
--- /dev/null
+++ b/cmd/traffic_via/tests/[uScRs f p eN:t cCHi p s ]
@@ -0,0 +1,14 @@
+Via header is [uScRs f p eN:t cCHi p s ], Length is 26
+Via Header Details:
+Request headers received from client :simple request (not conditional)
+Result of Traffic Server cache lookup for URL :in cache, fresh Ram hit (a cache "HIT")
+Response information received from origin server :no server connection needed
+Result of document write-to-cache: :no cache write performed
+Proxy operation result :unknown
+Error codes (if any) :no error
+Tunnel info :no tunneling
+Cache Type :cache
+Cache Lookup Result :cache hit
+ICP status :no icp
+Parent proxy connection status :no parent proxy or unknown
+Origin server connection status :no server connection needed
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e7d02d92/cmd/traffic_via/tests/long rubbish via code 24
----------------------------------------------------------------------
diff --git a/cmd/traffic_via/tests/long rubbish via code 24 b/cmd/traffic_via/tests/long rubbish via code 24
new file mode 100644
index 0000000..164f97e
--- /dev/null
+++ b/cmd/traffic_via/tests/long rubbish via code 24
@@ -0,0 +1,20 @@
+traffic_via: Invalid VIA header character: l
+traffic_via: Invalid VIA header character: o
+traffic_via: Invalid VIA header character: n
+traffic_via: Invalid VIA header character: g
+traffic_via: Invalid VIA header character: r
+traffic_via: Invalid VIA header character: b
+traffic_via: Invalid VIA header character: b
+traffic_via: Invalid VIA header character: i
+traffic_via: Invalid VIA header character: h
+traffic_via: Invalid VIA header character: v
+traffic_via: Invalid VIA header character: i
+traffic_via: Invalid VIA header character: a
+traffic_via: Invalid VIA header character: o
+traffic_via: Invalid VIA header character: d
+Via header is long rubbish via code 24, Length is 24
+Via Header Details:
+(null) :(null)
+(null) :no server connection needed
+(null) :no server connection needed
+Error codes (if any) :unknown
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e7d02d92/cmd/traffic_via/tests/rubbish
----------------------------------------------------------------------
diff --git a/cmd/traffic_via/tests/rubbish b/cmd/traffic_via/tests/rubbish
new file mode 100644
index 0000000..f3de8e9
--- /dev/null
+++ b/cmd/traffic_via/tests/rubbish
@@ -0,0 +1,4 @@
+Via header is rubbish, Length is 7
+
+Invalid VIA header. VIA header length should be 6 or 24 characters
+Valid via header format is [u<client-stuff>c<cache-lookup-stuff>s<server-stuff>f<cache-fill-stuff>p<proxy-stuff>]e<error-codes>:t<tunneling-info>c<cache type><cache-lookup-result>i<icp-conn-info>p<parent-proxy-conn-info>s<server-conn-info>]
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e7d02d92/cmd/traffic_via/tests/short
----------------------------------------------------------------------
diff --git a/cmd/traffic_via/tests/short b/cmd/traffic_via/tests/short
new file mode 100644
index 0000000..9779b50
--- /dev/null
+++ b/cmd/traffic_via/tests/short
@@ -0,0 +1,7 @@
+traffic_via: Invalid VIA header character: h
+traffic_via: Invalid VIA header character: o
+traffic_via: Invalid VIA header character: r
+traffic_via: Invalid VIA header character: t
+Via header is short, Length is 5
+Via Header Details:
+(null) :no server connection needed
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e7d02d92/cmd/traffic_via/traffic_via.cc
----------------------------------------------------------------------
diff --git a/cmd/traffic_via/traffic_via.cc b/cmd/traffic_via/traffic_via.cc
index 1321f1e..4d99a6a 100644
--- a/cmd/traffic_via/traffic_via.cc
+++ b/cmd/traffic_via/traffic_via.cc
@@ -61,7 +61,7 @@ struct VIA
static VIA *
detailViaLookup(char flag)
{
- VIA * viaTable = new VIA();
+ VIA * viaTable;
//Detailed via codes after ":"
switch (flag) {
@@ -117,9 +117,11 @@ detailViaLookup(char flag)
viaTable->viaData[(unsigned char) 'F'] = "connection open failed";
break;
default:
+ viaTable = new VIA();
fprintf(stderr, "%s: %s: %c\n", appVersionInfo.AppStr, "Invalid VIA header character",flag);
break;
}
+
return viaTable;
}
@@ -129,8 +131,6 @@ standardViaLookup(char flag)
{
VIA * viaTable;
- viaTable = new VIA();
-
//Via codes before ":"
switch (flag) {
case 'u':
@@ -186,9 +186,11 @@ standardViaLookup(char flag)
viaTable->viaData[(unsigned char) ' '] = "unknown";
break;
default:
+ viaTable = new VIA();
fprintf(stderr, "%s: %s: %c\n", appVersionInfo.AppStr, "Invalid VIA header character",flag);
break;
}
+
return viaTable;
}