From 56988944b59cea5e431e39d15deb27ad8976ceb2 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 12 Nov 2021 01:54:48 -0800 Subject: [PATCH] No need to dup fd --- native/jni/zygisk/main.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/native/jni/zygisk/main.cpp b/native/jni/zygisk/main.cpp index b46f8dab4..9ab2fbda8 100644 --- a/native/jni/zygisk/main.cpp +++ b/native/jni/zygisk/main.cpp @@ -149,20 +149,18 @@ static void zygiskd(int socket) { int module_id = read_int(client); if (module_id >= 0 && module_id < modules.size() && modules[module_id]) { exec_task([=, entry = modules[module_id]] { - int dup = fcntl(client, F_DUPFD_CLOEXEC); + struct stat s1; + fstat(client, &s1); entry(client); - // Only close client if it is the same as dup so we don't + // Only close client if it is the same file so we don't // accidentally close a re-used file descriptor. // This check is required because the module companion // handler could've closed the file descriptor already. - if (struct stat s1; fstat(client, &s1) == 0) { - struct stat s2{}; - fstat(dup, &s2); + if (struct stat s2; fstat(client, &s2) == 0) { if (s1.st_dev == s2.st_dev && s1.st_ino == s2.st_ino) { close(client); } } - close(dup); }); } else { close(client);