Skip to content

android: Fix crashes when unloading active Java hooks - #415

Open
LanceaKing wants to merge 8 commits into
frida-packages:mainfrom
LanceaKing:fix/7.0.13-art-teardown
Open

LanceaKing wants to merge 8 commits into
frida-packages:mainfrom
LanceaKing:fix/7.0.13-art-teardown

Conversation

@LanceaKing

Copy link
Copy Markdown

Unloading a script while Java hooks are running can free callbacks, cloned ArtMethods, and JNI handles before those calls finish. This can crash the app during or after unload.

Restore the original methods first, then keep those resources alive until active callbacks and ART frames finish. Release JNI handles before detaching from the VM. Suspend ART threads while restoring inline patches.

On Android 13 arm64, 50 concurrent unloads passed with four Java threads and object-return hooks. Another 30 attach/detach sessions, 22 spawns, and two canceled spawns also passed. No new crashes. These tests used official Python bindings and a patched Frida 17.26.2 server. Other Android versions and architectures remain untested. npm run lint and node --check index.js also pass.

Related: frida/frida#545 and #370.

@LanceaKing
LanceaKing marked this pull request as ready for review November 11, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant