Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] GetStringUTFChars is used without ReleaseStringUTFChars, likely leaking memory #23658

Closed
andy31415 opened this issue Nov 17, 2022 · 1 comment
Labels

Comments

@andy31415
Copy link
Contributor

andy31415 commented Nov 17, 2022

Reproduction steps

> rg ReleaseStringUTFChars | cut -f1 -d: | uniq -c | sort -n
      1 examples/tv-app/android/java/AppPlatformShellCommands-JNI.cpp
      1 src/lib/support/JniTypeWrappers.h
      2 src/controller/java/AndroidDeviceControllerWrapper.cpp
      2 src/setup_payload/java/SetupPayloadParser-JNI.cpp
      7 examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp

> rg GetStringUTFChars | cut -f1 -d: | uniq -c | sort -n
      1 examples/tv-app/android/java/AppPlatformShellCommands-JNI.cpp
      1 examples/tv-app/android/java/ContentAppAttributeDelegate.cpp
      1 examples/tv-app/android/java/ContentAppCommandDelegate.cpp
      1 src/lib/support/JniTypeWrappers.h
      2 src/controller/java/AndroidDeviceControllerWrapper.cpp
      2 src/setup_payload/java/SetupPayloadParser-JNI.cpp
      5 examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp
      8 examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp

Platform

java

Anything else?

#23655 fixes one such instance. We likely want some form of RAII here to ensure we always release UTF char strings.

@andy31415
Copy link
Contributor Author

chip::JniUtfString exists in https://github.com/project-chip/connectedhomeip/blob/master/src/lib/support/JniTypeWrappers.h

We should probably use that and ban direct usage of GetStringUTFChars via linting rules in all other places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

4 participants