moonchen commented on code in PR #13292:
URL: https://github.com/apache/trafficserver/pull/13292#discussion_r3431787849
##########
include/iocore/net/ProxyProtocol.h:
##########
@@ -82,6 +82,25 @@ class ProxyProtocol
other.tlv.clear();
}
~ProxyProtocol() = default;
+
+ /** Release owned heap and reset to the default-constructed state.
+ *
+ * Swap rather than clear() the containers: clear() retains capacity, which
would be abandoned
+ * (leaked) when the slot is reused, since the NetVConnection allocators are
Destruct_on_free=false
+ * and so never run ~ProxyProtocol.
+ */
+ void
+ reset()
+ {
+ std::string{}.swap(additional_data);
+ std::unordered_map<uint8_t, std::string_view>{}.swap(tlv);
+ version = ProxyProtocolVersion::UNDEFINED;
+ ip_family = AF_UNSPEC;
+ type = 0;
+ src_addr = {};
+ dst_addr = {};
+ }
Review Comment:
Added a `TEST_CASE("ProxyProtocol reset")` in `test_ProxyProtocol.cc`
(commit 98c0183): it parses a PROXY v2 header carrying TLVs into `pp_info`,
calls `reset()`, and asserts `version == UNDEFINED`, `ip_family == AF_UNSPEC`,
`type == 0`, both addresses cleared, `tlv.empty()`, and `get_tlv(PP2_TYPE_ALPN)
== nullopt`, plus an idempotent second `reset()`. Verified locally: `All tests
passed (14 assertions)`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]