Skip to content

VRBrowser: Delete jstring local refs in string getters - #2042

Merged
svillar merged 1 commit into
Igalia:mainfrom
NAME-ASHWANIYADAV:fix/vrbrowser-jstring-local-refs
Aug 10, 2026
Merged

VRBrowser: Delete jstring local refs in string getters#2042
svillar merged 1 commit into
Igalia:mainfrom
NAME-ASHWANIYADAV:fix/vrbrowser-jstring-local-refs

Conversation

@NAME-ASHWANIYADAV

@NAME-ASHWANIYADAV NAME-ASHWANIYADAV commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #2041

What

Adds sEnv->DeleteLocalRef(jStr); after ReleaseStringUTFChars() in GetStorageAbsolutePath() and GetActiveEnvironment() - the two jstring local references in VRBrowser.cpp that were never deleted.

Why

The file has exactly four local-reference sites. OnAppLink() (:445-447) and AppendAppNotesToCrashLog() (:461-463) delete their local reference immediately after use; these two getters (:356, :399) did not.

sEnv is the render thread's JNIEnv (InitializeJava(), :128-136) and the render thread stays attached for the app's lifetime, so JNI local references there are reclaimed only by an explicit DeleteLocalRef or 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 the surface reference returned by xrCreateSwapchainAndroidSurfaceKHR() with a NewGlobalRef of 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

  • Builds: ./gradlew assembleNoapiArm64GeckoGenericDebug
  • Existing unit tests pass: ./gradlew testNoapiArm64GeckoGenericDebugUnitTest

@NAME-ASHWANIYADAV

Copy link
Copy Markdown
Contributor Author

@svillar PTAL !!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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); in VRBrowser::GetStorageAbsolutePath() after releasing UTF chars.
  • Add sEnv->DeleteLocalRef(jStr); in VRBrowser::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 svillar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
NAME-ASHWANIYADAV force-pushed the fix/vrbrowser-jstring-local-refs branch from 5ce88d1 to cf296df Compare August 10, 2026 12:40
@NAME-ASHWANIYADAV

Copy link
Copy Markdown
Contributor Author

@svillar Thanks! Added the Fixes line to the commit

@svillar
svillar merged commit ae05713 into Igalia:main Aug 10, 2026
3 checks passed
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.

VRBrowser string getters leak JNI local references

3 participants