File tree Expand file tree Collapse file tree 2 files changed +22
-14
lines changed
livekit-android-sdk/src/main/java/io/livekit/android/room/datastream/outgoing Expand file tree Collapse file tree 2 files changed +22
-14
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " client-sdk-android " : patch
3+ ---
4+
5+ Fixed file descriptor leak in ByteStreamSender where Source was not closed after reading.
Original file line number Diff line number Diff line change @@ -86,25 +86,28 @@ suspend fun ByteStreamSender.write(input: InputStream): Result<Unit> {
8686
8787/* *
8888 * Reads the source and sends it to the data stream.
89+ *
90+ * The source will be closed when this function completes, whether it succeeds or fails.
8991 */
9092@CheckResult
9193suspend fun ByteStreamSender.write (source : Source ): Result <Unit > {
92- val buffer = Buffer ()
93- while (true ) {
94- try {
95- val readLen = source.read(buffer, 4096 )
96- if (readLen == - 1L ) {
97- break
98- }
94+ return try {
95+ source.use { src ->
96+ val buffer = Buffer ()
97+ while (true ) {
98+ val readLen = src.read(buffer, 4096 )
99+ if (readLen == - 1L ) {
100+ break
101+ }
99102
100- val result = write(buffer.readByteArray())
101- if (result.isFailure) {
102- return result
103+ val result = write(buffer.readByteArray())
104+ if (result.isFailure) {
105+ return @use result
106+ }
103107 }
104- } catch (e: Exception ) {
105- return Result .failure(e)
108+ Result .success(Unit )
106109 }
110+ } catch (e: Exception ) {
111+ Result .failure(e)
107112 }
108-
109- return Result .success(Unit )
110113}
You can’t perform that action at this time.
0 commit comments