From 6a6079ae3702c75e959d6f9a469a446bfd84d84c Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 17 Oct 2024 08:31:02 -0700 Subject: [PATCH] Fix a bug where toNSInputStream would leak if the stream is closed before being fully read (#1663) --- pkgs/objective_c/lib/src/ns_input_stream.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/objective_c/lib/src/ns_input_stream.dart b/pkgs/objective_c/lib/src/ns_input_stream.dart index cc0e3ad5c..e8945c253 100644 --- a/pkgs/objective_c/lib/src/ns_input_stream.dart +++ b/pkgs/objective_c/lib/src/ns_input_stream.dart @@ -43,8 +43,12 @@ extension NSInputStreamStreamExtension on Stream> { port.listen((count) { // -1 indicates that the `NSInputStream` is closed. All other values // indicate that the `NSInputStream` needs more data. + // + // If [DartInputStreamAdapter.setError_] or + // [DartInputStreamAdapter.setDone] is called then the close message (-1) + // will not be sent when the input stream is closed. if (count == -1) { - dataSubscription.cancel(); + port.close(); } else { dataSubscription.resume(); }