Update zygisk API to avoid mem leak

This commit is contained in:
LoveSy 2023-04-01 17:33:01 +08:00 committed by John Wu
parent b696dae808
commit 97731a519a

View File

@ -346,12 +346,13 @@ struct api_table {
template <class T> template <class T>
void entry_impl(api_table *table, JNIEnv *env) { void entry_impl(api_table *table, JNIEnv *env) {
ModuleBase *module = new T(); static Api api;
if (!table->registerModule(table, new module_abi(module))) api.tbl = table;
return; static T module;
auto api = new Api(); ModuleBase *m = &module;
api->tbl = table; static module_abi abi(m);
module->onLoad(api, env); if (!table->registerModule(table, &abi)) return;
m->onLoad(&api, env);
} }
} // namespace internal } // namespace internal
@ -385,10 +386,10 @@ inline bool Api::pltHookCommit() {
extern "C" { extern "C" {
[[gnu::visibility("default")]] [[gnu::used]] [[gnu::visibility("default"), maybe_unused]]
void zygisk_module_entry(zygisk::internal::api_table *, JNIEnv *); void zygisk_module_entry(zygisk::internal::api_table *, JNIEnv *);
[[gnu::visibility("default")]] [[gnu::used]] [[gnu::visibility("default"), maybe_unused]]
void zygisk_companion_entry(int); void zygisk_companion_entry(int);
} // extern "C" } // extern "C"