From ec5cada58ce96124b15c2f71d0d2f58cfbf2d545 Mon Sep 17 00:00:00 2001 From: "hyung4.kim" Date: Thu, 12 Nov 2020 13:58:10 +0900 Subject: [PATCH] Fixed Handler Leak on WrapperInit Handler is not closed by IOException Detected by static analysis Test: Manual Signed-off-by: hyung4.kim Change-Id: I702387572dafbd6cbd3ed2c2ecb71760b2725fe8 --- core/java/com/android/internal/os/WrapperInit.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/java/com/android/internal/os/WrapperInit.java b/core/java/com/android/internal/os/WrapperInit.java index 790d7f7ab6946..6860759eea8ae 100644 --- a/core/java/com/android/internal/os/WrapperInit.java +++ b/core/java/com/android/internal/os/WrapperInit.java @@ -69,15 +69,16 @@ public class WrapperInit { // Tell the Zygote what our actual PID is (since it only knows about the // wrapper that it directly forked). if (fdNum != 0) { + FileDescriptor fd = new FileDescriptor(); try { - FileDescriptor fd = new FileDescriptor(); fd.setInt$(fdNum); DataOutputStream os = new DataOutputStream(new FileOutputStream(fd)); os.writeInt(Process.myPid()); os.close(); - IoUtils.closeQuietly(fd); } catch (IOException ex) { Slog.d(TAG, "Could not write pid of wrapped process to Zygote pipe.", ex); + } finally { + IoUtils.closeQuietly(fd); } }