Skip to content

Commit d482b8e

Browse files
committed
Clean up DataFetchers even if DecodeJobs are cancelled prior to run().
Previously some of the logic in run() might null out the data fetcher instance variable, even if it had been set when run() was first called. As a result, the data fetcher would not be cleared. Now the initial data fetcher is held on to as a local variable so the instance variable can be freed without affecting the behavior of cleanup(). Progress towards #1996, #2352
1 parent a365dab commit d482b8e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

library/src/main/java/com/bumptech/glide/load/engine/DecodeJob.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.bumptech.glide.load.engine.cache.DiskCache;
1919
import com.bumptech.glide.load.resource.bitmap.Downsampler;
2020
import com.bumptech.glide.util.LogTime;
21+
import com.bumptech.glide.util.Preconditions;
2122
import com.bumptech.glide.util.Synthetic;
2223
import com.bumptech.glide.util.pool.FactoryPools.Poolable;
2324
import com.bumptech.glide.util.pool.StateVerifier;
@@ -218,6 +219,9 @@ public void run() {
218219
// swallows all otherwise fatal exceptions, this will at least make it obvious to developers
219220
// that something is failing.
220221
TraceCompat.beginSection("DecodeJob#run");
222+
// Methods in the try statement can invalidate currentFetcher, so set a local variable here to
223+
// ensure that the fetcher is cleaned up either way.
224+
DataFetcher<?> localFetcher = currentFetcher;
221225
try {
222226
if (isCancelled) {
223227
notifyFailed();
@@ -238,8 +242,11 @@ public void run() {
238242
throw e;
239243
}
240244
} finally {
241-
if (currentFetcher != null) {
242-
currentFetcher.cleanup();
245+
Preconditions.checkArgument(
246+
localFetcher == null || currentFetcher == null || localFetcher.equals(currentFetcher),
247+
"Fetchers don't match!, old: " + localFetcher + " new: " + currentFetcher);
248+
if (localFetcher != null) {
249+
localFetcher.cleanup();
243250
}
244251
TraceCompat.endSection();
245252
}

0 commit comments

Comments
 (0)