Change quicpacketwriter::getnextwritelocation to return a release function used to free a writer-allocated buffer. use this release function to avoid buffer leak if a writer buffer is allocated but writer->writepacket is not called. protected by --gfe2_reloadable_flag_quic_avoid_leak_writer_buffer.
This is needed to fix a buffer leak when the new PigeonWriter is used.
PiperOrigin-RevId: 312369772
Change-Id: I0d12327b58989ec69e401b03f7b9ebb4d8ce22fd
diff --git a/quic/core/quic_packet_creator.h b/quic/core/quic_packet_creator.h
index 7695587..c25d8f6 100644
--- a/quic/core/quic_packet_creator.h
+++ b/quic/core/quic_packet_creator.h
@@ -41,9 +41,9 @@
public:
virtual ~DelegateInterface() {}
// Get a buffer of kMaxOutgoingPacketSize bytes to serialize the next
- // packet. If return nullptr, QuicPacketCreator will serialize on a stack
- // buffer.
- virtual char* GetPacketBuffer() = 0;
+ // packet. If the return value's buffer is nullptr, QuicPacketCreator will
+ // serialize on a stack buffer.
+ virtual QuicPacketBuffer GetPacketBuffer() = 0;
// Called when a packet is serialized. Delegate take the ownership of
// |serialized_packet|.
virtual void OnSerializedPacket(SerializedPacket serialized_packet) = 0;
@@ -459,7 +459,8 @@
// retransmitted to packet_.retransmittable_frames. All frames must fit into
// a single packet.
// Fails if |encrypted_buffer_len| isn't long enough for the encrypted packet.
- void SerializePacket(char* encrypted_buffer, size_t encrypted_buffer_len);
+ void SerializePacket(QuicOwnedPacketBuffer encrypted_buffer,
+ size_t encrypted_buffer_len);
// Called after a new SerialiedPacket is created to call the delegate's
// OnSerializedPacket and reset state.
@@ -597,6 +598,9 @@
// accept. There is no limit for QUIC_CRYPTO connections, but QUIC+TLS
// negotiates this during the handshake.
QuicByteCount max_datagram_frame_size_;
+
+ const bool avoid_leak_writer_buffer_ =
+ GetQuicReloadableFlag(quic_avoid_leak_writer_buffer);
};
} // namespace quic