VRBrowser: Delete jstring local refs in string getters - #2042
Merged
svillar merged 1 commit intoAug 10, 2026
Conversation
Contributor
Author
|
@svillar PTAL !! |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a JNI local-reference leak in VRBrowser.cpp by explicitly deleting jstring local refs created on the long-lived render thread JNIEnv after converting them to std::string.
Changes:
- Add
sEnv->DeleteLocalRef(jStr);inVRBrowser::GetStorageAbsolutePath()after releasing UTF chars. - Add
sEnv->DeleteLocalRef(jStr);inVRBrowser::GetActiveEnvironment()after releasing UTF chars.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
svillar
approved these changes
Aug 10, 2026
svillar
left a comment
Member
There was a problem hiding this comment.
Good catch. I think local refs are automatically deleted anyway once the native method returns in JNI, but it's good hygiene.
Please include the Fixes # ... in the commit message
GetStorageAbsolutePath and GetActiveEnvironment released the UTF chars but never deleted the jstring local reference, unlike OnAppLink and AppendAppNotesToCrashLog in the same file. The render thread stays attached, so leaked locals are never reclaimed. Fixes Igalia#2041
NAME-ASHWANIYADAV
force-pushed
the
fix/vrbrowser-jstring-local-refs
branch
from
August 10, 2026 12:40
5ce88d1 to
cf296df
Compare
Contributor
Author
|
@svillar Thanks! Added the Fixes line to the commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2041
What
Adds
sEnv->DeleteLocalRef(jStr);afterReleaseStringUTFChars()inGetStorageAbsolutePath()andGetActiveEnvironment()- the twojstringlocal references inVRBrowser.cppthat were never deleted.Why
The file has exactly four local-reference sites.
OnAppLink()(:445-447) andAppendAppNotesToCrashLog()(:461-463) delete their local reference immediately after use; these two getters (:356,:399) did not.sEnvis the render thread'sJNIEnv(InitializeJava(),:128-136) and the render thread stays attached for the app's lifetime, so JNI local references there are reclaimed only by an explicitDeleteLocalRefor at thread detach. Each call permanently occupied a slot in the thread's local reference table. Both getters are on the environment/skybox load path (BrowserWorld.cpp:1366,:1369), so slots leaked on every environment load or change.Related observation (out of scope)
OpenXRSwapChain::InitAndroidSurface()(OpenXRSwapChain.cpp:48-51) overwrites thesurfacereference returned byxrCreateSwapchainAndroidSurfaceKHR()with aNewGlobalRefof it, without deleting the original - if the runtime returns a local reference there (as the KHR Android-surface extension implies), that local leaks once per swapchain creation. Happy to file separately if it looks worth tracking.Testing
./gradlew assembleNoapiArm64GeckoGenericDebug./gradlew testNoapiArm64GeckoGenericDebugUnitTest