diff --git a/bindings/gumjs/gumquickprocess.c b/bindings/gumjs/gumquickprocess.c index 595fba92f..9299d3eb9 100644 --- a/bindings/gumjs/gumquickprocess.c +++ b/bindings/gumjs/gumquickprocess.c @@ -654,7 +654,7 @@ GUMJS_DEFINE_FUNCTION (gumjs_process_run_on_thread) GumQuickScope scope = GUM_QUICK_SCOPE_INIT (core); GumThreadId thread_id; JSValue user_func; - GumQuickRunOnThreadContext context; + GumQuickRunOnThreadContext * context; gboolean run; if (!_gum_quick_args_parse (args, "ZF", &thread_id, &user_func)) @@ -662,14 +662,15 @@ GUMJS_DEFINE_FUNCTION (gumjs_process_run_on_thread) _gum_quick_scope_suspend (&scope); - context.core = core; - context.user_func = JS_DupValue (core->ctx, user_func); + context = g_slice_new (GumQuickRunOnThreadContext); + context->core = core; + context->user_func = JS_DupValue (core->ctx, user_func); if (self->stalker == NULL) self->stalker = gum_stalker_new (); run = gum_stalker_run_on_thread (self->stalker, thread_id, - gum_js_process_run_cb, &context); + gum_js_process_run_cb, context); _gum_quick_scope_resume (&scope); gum_quick_flush_stalker (self, &scope); @@ -680,6 +681,7 @@ GUMJS_DEFINE_FUNCTION (gumjs_process_run_on_thread) return JS_UNDEFINED; error: + g_slice_free (GumQuickRunOnThreadContext, context); _gum_quick_throw_literal (ctx, "failed to run on thread"); return JS_EXCEPTION; } @@ -701,6 +703,8 @@ gum_js_process_run_cb (const GumCpuContext * cpu_context, JS_FreeValue (core->ctx, user_func); _gum_quick_scope_leave (&scope); + + g_slice_free (GumQuickRunOnThreadContext, context); } static void diff --git a/bindings/gumjs/gumv8process.cpp b/bindings/gumjs/gumv8process.cpp index 54991b5fa..8a0ec0eff 100644 --- a/bindings/gumjs/gumv8process.cpp +++ b/bindings/gumjs/gumv8process.cpp @@ -67,7 +67,7 @@ struct GumV8FindModuleByNameContext struct GumV8RunOnThreadContext { GumV8Core * core; - Global user_func; + Global * user_func; }; GUMJS_DECLARE_GETTER (gumjs_process_get_main_module) @@ -536,8 +536,7 @@ GUMJS_DEFINE_FUNCTION (gumjs_process_run_on_thread) { GumThreadId thread_id; Local user_func; - GumV8RunOnThreadContext context; - gboolean run; + gboolean run; auto isolate = core->isolate; @@ -547,13 +546,14 @@ GUMJS_DEFINE_FUNCTION (gumjs_process_run_on_thread) if (module->stalker == NULL) module->stalker = gum_stalker_new (); - context.core = core; - context.user_func = Global (isolate, user_func); + auto context = g_slice_new (GumV8RunOnThreadContext); + context->core = core; + context->user_func = new Global (isolate, user_func); { ScriptUnlocker unlocker (core); run = gum_stalker_run_on_thread (module->stalker, thread_id, - gum_js_process_run_cb, &context); + gum_js_process_run_cb, context); } gum_v8_flush_stalker (module); @@ -577,11 +577,15 @@ gum_js_process_run_cb (const GumCpuContext * cpu_context, ScriptScope scope (core->script); auto isolate = core->isolate; - auto user_func = Local::New (isolate, context->user_func); + auto user_func = Local::New (isolate, *context->user_func); auto ctx = isolate->GetCurrentContext (); auto recv = Undefined (isolate); auto result = user_func->Call (ctx, recv, 0, nullptr); (void) result; + + delete context->user_func; + + g_slice_free (GumV8RunOnThreadContext, context); } static void