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_writer.h b/quic/core/quic_packet_writer.h
index ab29e15..6efdb60 100644
--- a/quic/core/quic_packet_writer.h
+++ b/quic/core/quic_packet_writer.h
@@ -125,17 +125,22 @@
// True=Batch mode. False=PassThrough mode.
virtual bool IsBatchMode() const = 0;
- // PassThrough mode: Return nullptr.
+ // PassThrough mode: Return {nullptr, nullptr}
//
// Batch mode:
- // Return the starting address for the next packet's data. A minimum of
+ // Return the QuicPacketBuffer for the next packet. A minimum of
// kMaxOutgoingPacketSize is guaranteed to be available from the returned
- // address. If the internal buffer does not have enough space, nullptr is
- // returned. All arguments should be identical to the follow-up call to
- // |WritePacket|, they are here to allow advanced packet memory management in
- // packet writers, e.g. one packet buffer pool per |peer_address|.
- virtual char* GetNextWriteLocation(const QuicIpAddress& self_address,
- const QuicSocketAddress& peer_address) = 0;
+ // address. If the internal buffer does not have enough space,
+ // {nullptr, nullptr} is returned. All arguments should be identical to the
+ // follow-up call to |WritePacket|, they are here to allow advanced packet
+ // memory management in packet writers, e.g. one packet buffer pool per
+ // |peer_address|.
+ //
+ // If QuicPacketBuffer.release_buffer is !nullptr, it should be called iff
+ // the caller does not call WritePacket for the returned buffer.
+ virtual QuicPacketBuffer GetNextWriteLocation(
+ const QuicIpAddress& self_address,
+ const QuicSocketAddress& peer_address) = 0;
// PassThrough mode: Return WriteResult(WRITE_STATUS_OK, 0).
//