OSDN Git Service

Fix socket descriptor leak from Zygote to child app
authorDave Platt <dplatt@google.com>
Thu, 12 Dec 2013 23:45:49 +0000 (15:45 -0800)
committerdcashman <dcashman@google.com>
Mon, 6 Jan 2014 21:59:20 +0000 (13:59 -0800)
Due to an API change in LocalSocket, Zygote must now
manually close the FileDescriptor it created when it
registered a LocalServerSocket.  The LocalSocket.close()
routine will no longer do so.

Bug: 12114500

(cherry picked from commit 70ef29b04ee4ef7d7acfec79041dbe800961195e)

Change-Id: Ief23a3c99e007dc4aa6f94dfb47a1b2b6c854dad

core/java/com/android/internal/os/ZygoteInit.java

index c44afae..1548f1b 100644 (file)
@@ -192,10 +192,16 @@ public class ZygoteInit {
     static void closeServerSocket() {
         try {
             if (sServerSocket != null) {
+                FileDescriptor fd = sServerSocket.getFileDescriptor();
                 sServerSocket.close();
+                if (fd != null) {
+                    Libcore.os.close(fd);
+                }
             }
         } catch (IOException ex) {
             Log.e(TAG, "Zygote:  error closing sockets", ex);
+        } catch (libcore.io.ErrnoException ex) {
+            Log.e(TAG, "Zygote:  error closing descriptor", ex);
         }
 
         sServerSocket = null;