From df29b7fe3ac149674027b61ee3664bdc8a3af1c7 Mon Sep 17 00:00:00 2001 From: hangl Date: Tue, 4 Jun 2024 17:58:31 +0800 Subject: Fix pipe fds leak in copyInternalSpliceSocket This method used a temporarily pipe to copy data but forget to close it before exiting, which will cause fd leak. As the number of times this method is called increases, the process may abort since the fd reaches its limit. So close the pipe before exiting. Bug: 344767008 Change-Id: I2028bf2e36e9dde9b6aaea1f7c758169e6842cc7 --- core/java/android/os/FileUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/java/android/os/FileUtils.java b/core/java/android/os/FileUtils.java index 4dc32d5039b6..f3d743d51e4a 100644 --- a/core/java/android/os/FileUtils.java +++ b/core/java/android/os/FileUtils.java @@ -580,6 +580,8 @@ public final class FileUtils { ", copied:" + progress + ", read:" + (count - countToRead) + ", in pipe: " + countInPipe); + Os.close(pipes[0]); + Os.close(pipes[1]); throw new ErrnoException("splice, pipe --> fdOut", EIO); } else { progress += t; @@ -607,6 +609,8 @@ public final class FileUtils { listener.onProgress(progressSnapshot); }); } + Os.close(pipes[0]); + Os.close(pipes[1]); return progress; } -- cgit v1.2.3-59-g8ed1b