Skip to content

JNI init overwrites global refs without DeleteGlobalRef #58

Description

@QiuYucheng2003

Two JNI init functions store jniHelperClass and mainActivityObj with NewGlobalRef, then overwrite those same globals on the next call. The previous refs are never released. This file has no DeleteGlobalRef and no JNI_OnUnload.

Where

app/src/main/cpp/libUvc_Support/libuvc_support.c (d035099)

  • Lines 1041–1042: JniPrepairStreamOverSurfaceUVC creates both global refs
  • Lines 1053–1054: JniWebRtcJavaMethods creates both global refs again
  • Both write the same two globals declared at lines 158–159

What leaks

A second call, or a call to the other entry, replaces jniHelperClass and mainActivityObj without DeleteGlobalRef on the old values. Those refs stay in the global reference table. mainActivityObj is not read again in this file, so it only keeps the Java object alive.

Holding one global ref until process exit is a normal callback cache. The bug is the overwrite, and the lack of a matching DeleteGlobalRef when streaming stops or the library unloads.

Suggested fix

Before each assignment, delete the existing ref if it is non-NULL. Delete both refs when the capture stops, and in JNI_OnUnload.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions