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

Fix unclosed OutputStream in DiskLruCacheWrapper (reported by StrictMode... #61

Merged
merged 1 commit into from
Feb 16, 2014

Conversation

vickychijwani
Copy link
Contributor

Hi there,

I've been using Glide in my project, and it sure is great to have the best of Picasso and the best of Volley. Thank you for this.

Recently I've turned on StrictMode in my app, and I frequently get the following message in LogCat:

E/StrictModeA resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
    java.lang.Throwable: Explicit termination method 'close' not called
            at dalvik.system.CloseGuard.open(CloseGuard.java:184)
            at java.io.FileOutputStream.<init>(FileOutputStream.java:90)
            at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
            at com.jakewharton.disklrucache.DiskLruCache$Editor.newOutputStream(DiskLruCache.java:779)
            at com.bumptech.glide.resize.cache.DiskLruCacheWrapper.put(DiskLruCacheWrapper.java:80)
            at com.bumptech.glide.resize.ImageManager.putInDiskCache(ImageManager.java:525)
            at com.bumptech.glide.resize.ImageManager.access$2400(ImageManager.java:57)
            at com.bumptech.glide.resize.ImageManager$ImageManagerRunner.finishResize(ImageManager.java:665)
            at com.bumptech.glide.resize.ImageManager$ImageManagerRunner.access$2000(ImageManager.java:549)
            at com.bumptech.glide.resize.ImageManager$ImageManagerRunner$1$1$1.run(ImageManager.java:641)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:841)

This pull request corrects the issue by closing the OutputStream when it is no longer needed.

@sjudd sjudd merged commit 0ff76fe into bumptech:master Feb 16, 2014
@sjudd
Copy link
Collaborator

sjudd commented Feb 16, 2014

Added a try catch to be just a bit more paranoid. Nice catch and thanks for posting the fix!

@vickychijwani vickychijwani deleted the fix-unclosed-ostream branch February 16, 2014 00:08
@RobertoArtiles
Copy link

Getting a similar warning on the latest Glide 3.6.0 .(see square/okhttp#1053)

05-27 15:43:35.058    7180-7192/com.witdot.twinkie E/StrictMode﹕ A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
    java.lang.Throwable: Explicit termination method 'close' not called
            at dalvik.system.CloseGuard.open(CloseGuard.java:184)
            at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:287)
            at com.squareup.okhttp.Connection.upgradeToTls(Connection.java:242)
            at com.squareup.okhttp.Connection.connect(Connection.java:159)
            at com.squareup.okhttp.Connection.connectAndSetOwner(Connection.java:175)
            at com.squareup.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:120)
            at com.squareup.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:330)
            at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:319)
            at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:241)
            at com.squareup.okhttp.Call.getResponse(Call.java:271)
            at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:228)
            at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:199)
            at com.squareup.okhttp.Call.execute(Call.java:79)
            at com.bumptech.glide.integration.okhttp.OkHttpStreamFetcher.loadData(OkHttpStreamFetcher.java:48)
            at com.bumptech.glide.integration.okhttp.OkHttpStreamFetcher.loadData(OkHttpStreamFetcher.java:19)
            at com.bumptech.glide.load.model.ImageVideoModelLoader$ImageVideoFetcher.loadData(ImageVideoModelLoader.java:70)
            at com.bumptech.glide.load.model.ImageVideoModelLoader$ImageVideoFetcher.loadData(ImageVideoModelLoader.java:53)
            at com.bumptech.glide.load.engine.DecodeJob.decodeSource(DecodeJob.java:170)
            at com.bumptech.glide.load.engine.DecodeJob.decodeFromSource(DecodeJob.java:128)
            at com.bumptech.glide.load.engine.EngineRunnable.decodeFromSource(EngineRunnable.java:122)
            at com.bumptech.glide.load.engine.EngineRunnable.decode(EngineRunnable.java:101)
            at com.bumptech.glide.load.engine.EngineRunnable.run(EngineRunnable.java:58)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)
            at com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor$DefaultThreadFactory$1.run(FifoPriorityThreadPoolExecutor.java:118)
``

@sjudd
Copy link
Collaborator

sjudd commented May 27, 2015

@RobertoArtiles Do you mind filing a new issue? This is a super old pull request.

@RobertoArtiles
Copy link

Sure. #474

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.

3 participants