Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e7ae30f7 authored by Mateus Azis's avatar Mateus Azis
Browse files

Close DirectoryStream in ActivityThread after use.

Right now, the directory stream is never closed. This leads to confusing
"A resource failed to call close" errors. After some debugging, they
seem to be coming from sun.nio.fs.UnixSecureDirectoryStream objects and
reported here:
https://cs.android.com/android/platform/superproject/+/master:libcore/dalvik/src/main/java/dalvik/system/CloseGuard.java;l=340;drc=e32570b11273e703580b60fc9d59b96223f376da.

Test: m dist -j && acloud create --local-instance --local-image
Change-Id: Ie9fddc2eab505527985d8c6b2822623fe16c7f89
parent 2051907a
Loading
Loading
Loading
Loading
+13 −10
Original line number Original line Diff line number Diff line
@@ -238,6 +238,7 @@ import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.InetAddress;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardCopyOption;
@@ -4221,13 +4222,14 @@ public final class ActivityThread extends ClientTransactionHandler


    static void handleAttachStartupAgents(String dataDir) {
    static void handleAttachStartupAgents(String dataDir) {
        try {
        try {
            Path code_cache = ContextImpl.getCodeCacheDirBeforeBind(new File(dataDir)).toPath();
            Path codeCache = ContextImpl.getCodeCacheDirBeforeBind(new File(dataDir)).toPath();
            if (!Files.exists(code_cache)) {
            if (!Files.exists(codeCache)) {
                return;
                return;
            }
            }
            Path startup_path = code_cache.resolve("startup_agents");
            Path startupPath = codeCache.resolve("startup_agents");
            if (Files.exists(startup_path)) {
            if (Files.exists(startupPath)) {
                for (Path p : Files.newDirectoryStream(startup_path)) {
                try (DirectoryStream<Path> startupFiles = Files.newDirectoryStream(startupPath)) {
                    for (Path p : startupFiles) {
                        handleAttachAgent(
                        handleAttachAgent(
                                p.toAbsolutePath().toString()
                                p.toAbsolutePath().toString()
                                        + "="
                                        + "="
@@ -4235,6 +4237,7 @@ public final class ActivityThread extends ClientTransactionHandler
                                null);
                                null);
                    }
                    }
                }
                }
            }
        } catch (Exception e) {
        } catch (Exception e) {
            // Ignored.
            // Ignored.
        }
        }