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