From a2b89f459d8be4d57af4a3900819da90a2286235 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Wed, 16 Oct 2024 17:33:59 -0700 Subject: [PATCH] Fix a bug where toNSInputStream would leak if the stream is closed before being fully read --- pkgs/objective_c/lib/src/ns_input_stream.dart | 7 ++++++- 1 file changed, 6 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..06a7e174a 100644 --- a/pkgs/objective_c/lib/src/ns_input_stream.dart +++ b/pkgs/objective_c/lib/src/ns_input_stream.dart @@ -41,10 +41,15 @@ extension NSInputStreamStreamExtension on Stream> { dataSubscription.pause(); port.listen((count) { + print('Got $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(); }