diff --git a/native/jni/zygisk/hook.cpp b/native/jni/zygisk/hook.cpp index 2a541eda5..0959d9385 100644 --- a/native/jni/zygisk/hook.cpp +++ b/native/jni/zygisk/hook.cpp @@ -331,6 +331,11 @@ void ZygiskModule::setOption(zygisk::Option opt) { void HookContext::run_modules_pre(const vector &fds) { char buf[256]; + + // Since we directly use the pointer to elements in the vector, in order to prevent dangling + // pointers, the vector has to be pre-allocated to ensure reallocation does not occur + modules.reserve(fds.size()); + for (int i = 0; i < fds.size(); ++i) { snprintf(buf, sizeof(buf), "/proc/self/fd/%d", fds[i]); if (void *h = dlopen(buf, RTLD_LAZY)) {