This is an automated email from the ASF dual-hosted git repository.

chengpan pushed a commit to branch branch-0.3
in repository https://gitbox.apache.org/repos/asf/incubator-celeborn.git


The following commit(s) were added to refs/heads/branch-0.3 by this push:
     new f368b8c0f [CELEBORN-964] Simplify read process output to prevent leak
f368b8c0f is described below

commit f368b8c0feb92d5275a9822619b776c0056bb860
Author: sychen <[email protected]>
AuthorDate: Mon Sep 11 16:46:13 2023 +0800

    [CELEBORN-964] Simplify read process output to prevent leak
    
    ### What changes were proposed in this pull request?
    close InputStream
    
    ### Why are the changes needed?
    
    ### Does this PR introduce _any_ user-facing change?
    
    ### How was this patch tested?
    
    Closes #1897 from cxzl25/CELEBORN-964.
    
    Authored-by: sychen <[email protected]>
    Signed-off-by: Cheng Pan <[email protected]>
    (cherry picked from commit 0aaffe6f970a386b97a632d78382aa29b2e09488)
    Signed-off-by: Cheng Pan <[email protected]>
---
 .../main/scala/org/apache/celeborn/common/util/Utils.scala   | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/common/src/main/scala/org/apache/celeborn/common/util/Utils.scala 
b/common/src/main/scala/org/apache/celeborn/common/util/Utils.scala
index 1b5717bbf..2d55bd227 100644
--- a/common/src/main/scala/org/apache/celeborn/common/util/Utils.scala
+++ b/common/src/main/scala/org/apache/celeborn/common/util/Utils.scala
@@ -649,14 +649,12 @@ object Utils extends Logging {
   }
 
   private def readProcessStdout(process: Process): String = {
-    val stream = process.getInputStream
-    val sb = new StringBuilder
-    var res = stream.read()
-    while (res != -1) {
-      sb.append(res.toChar)
-      res = stream.read()
+    val source = Source.fromInputStream(process.getInputStream)
+    try {
+      source.mkString
+    } finally {
+      source.close()
     }
-    sb.toString()
   }
 
   def runCommand(cmd: String): String = {

Reply via email to