Copilot commented on code in PR #13293:
URL: https://github.com/apache/trafficserver/pull/13293#discussion_r3431813937


##########
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);

Review Comment:
   `reset()` hard-codes the container types (`std::string` / 
`std::unordered_map<uint8_t, std::string_view>`). Using `decltype(...)` avoids 
duplication and keeps this correct if the member types (e.g., 
allocator/hasher/value type) change later. It also lets you clear `tlv` before 
releasing `additional_data`, preserving the `string_view` lifetime relationship 
while the map exists.



-- 
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]

Reply via email to