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
This commit is contained in:
Mateus Azis
2023-03-27 13:16:34 -07:00
parent 2051907ae1
commit e7ae30f767

View File

@@ -238,6 +238,7 @@ import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
@@ -4221,18 +4222,20 @@ public final class ActivityThread extends ClientTransactionHandler
static void handleAttachStartupAgents(String dataDir) {
try {
Path code_cache = ContextImpl.getCodeCacheDirBeforeBind(new File(dataDir)).toPath();
if (!Files.exists(code_cache)) {
Path codeCache = ContextImpl.getCodeCacheDirBeforeBind(new File(dataDir)).toPath();
if (!Files.exists(codeCache)) {
return;
}
Path startup_path = code_cache.resolve("startup_agents");
if (Files.exists(startup_path)) {
for (Path p : Files.newDirectoryStream(startup_path)) {
handleAttachAgent(
p.toAbsolutePath().toString()
+ "="
+ dataDir,
null);
Path startupPath = codeCache.resolve("startup_agents");
if (Files.exists(startupPath)) {
try (DirectoryStream<Path> startupFiles = Files.newDirectoryStream(startupPath)) {
for (Path p : startupFiles) {
handleAttachAgent(
p.toAbsolutePath().toString()
+ "="
+ dataDir,
null);
}
}
}
} catch (Exception e) {