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

RegistrationIntentService leaks a closeable FileOutputStream #973

Closed
troy-lamerton opened this issue May 29, 2022 · 1 comment
Closed

RegistrationIntentService leaks a closeable FileOutputStream #973

troy-lamerton opened this issue May 29, 2022 · 1 comment

Comments

@troy-lamerton
Copy link

[REQUIRED] Please fill in the following fields:

  • Pre-built SDK from the website or open-source from this repo: prebuilt
  • Firebase C++ SDK version: 8.11.0
  • Problematic Firebase Component: Messaging
  • Other Firebase Components in use: none
  • Platform you are using the C++ SDK on: Mac
  • Platform you are targeting: Android

[REQUIRED] Please describe the issue here:

2022-05-26 10:43:36.813 9571-9584/? D/StrictMode: StrictMode policy violation: android.os.strictmode.LeakedClosableViolation: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
        at android.os.StrictMode$AndroidCloseGuardReporter.report(StrictMode.java:1877)
        at dalvik.system.CloseGuard.warnIfOpen(CloseGuard.java:286)
        at sun.nio.ch.FileChannelImpl.finalize(FileChannelImpl.java:175)
        at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:289)
        at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:276)
        at java.lang.Daemons$Daemon.run(Daemons.java:137)
        at java.lang.Thread.run(Thread.java:919)
     Caused by: java.lang.Throwable: Explicit termination method 'close' not called
        at dalvik.system.CloseGuard.open(CloseGuard.java:237)
        at sun.nio.ch.FileChannelImpl.<init>(FileChannelImpl.java:110)
        at sun.nio.ch.FileChannelImpl.open(FileChannelImpl.java:128)
        at java.io.FileOutputStream.getChannel(FileOutputStream.java:469)
        at com.google.firebase.messaging.cpp.RegistrationIntentService.writeTokenToInternalStorage(SourceFile:6)
        at com.google.firebase.messaging.cpp.RegistrationIntentService.onHandleIntent(SourceFile:3)
        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:78)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:237)
        at android.os.HandlerThread.run(HandlerThread.java:67)

Steps to reproduce:

  • Android project using Firebase Messaging
  • enable strict mode
StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder()
                    .detectActivityLeaks()
                    .detectLeakedClosableObjects()
                    .penaltyLog()
                    .build())
  • check logcat for D/StrictMode logs

100% reproduce.

Sample project that reproduces the bug:

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        StrictMode.setVmPolicy(
            StrictMode.VmPolicy.Builder()
                .detectLeakedClosableObjects()
                .penaltyLog()
                .build()
        )
    }
chkuang-g added a commit that referenced this issue Jun 17, 2022
Make sure all FileStream and FileLock are closed using AutoClose pattern.
chkuang-g added a commit that referenced this issue Jun 17, 2022
Make sure all FileStream and FileLock are closed using AutoClose pattern.
@chkuang-g
Copy link
Contributor

@troy-lamerton

This looks legit. Thank you for reporting. Let me see if I can put together a quick fix for this.

@chkuang-g chkuang-g added type: bug and removed new New issue. type: question labels Jun 17, 2022
chkuang-g added a commit that referenced this issue Jun 17, 2022
Make sure all FileStream and FileLock are closed using AutoClose pattern.
chkuang-g added a commit that referenced this issue Jun 17, 2022
Make sure all FileStream and FileLock are closed using AutoClose pattern.
@firebase firebase locked and limited conversation to collaborators Jul 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants