Fix CloseableReference leaks in Flipper plugin
Summary:
When debugging closeable reference leaks, I found that the Flipper plugin doesn't properly close one:
```
2020-01-17 10:45:29.346 27038-27053/com.facebook.wakizashi D/YOLO: LEAK!!:
java.lang.Throwable
at com.facebook.common.references.CloseableReference.<init>(CloseableReference.java:158)
at com.facebook.common.references.DefaultCloseableReference.<init>(DefaultCloseableReference.java:29)
at com.facebook.common.references.CloseableReference.of(CloseableReference.java:237)
at com.facebook.common.references.CloseableReference.of(CloseableReference.java:203)
at com.facebook.common.references.CloseableReference.of(CloseableReference.java:176)
at com.facebook.imagepipeline.cache.CountingMemoryCache.newClientReference(CountingMemoryCache.java:221)
at com.facebook.imagepipeline.cache.CountingMemoryCache.get(CountingMemoryCache.java:209)
at com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin$4.onReceive(FrescoFlipperPlugin.java:204)
at com.facebook.flipper.android.EventBase.loopForever(Native Method)
at com.facebook.flipper.android.FlipperThread.run(FlipperThread.java:31)
```
Second leak:
```
2020-01-17 11:04:16.503 28855-28869/com.facebook.wakizashi D/YOLO: LEAK!!:
java.lang.Throwable
at com.facebook.common.references.CloseableReference.<init>(CloseableReference.java:147)
at com.facebook.common.references.DefaultCloseableReference.<init>(DefaultCloseableReference.java:21)
at com.facebook.common.references.DefaultCloseableReference.clone(DefaultCloseableReference.java:35)
at com.facebook.common.references.CloseableReference.cloneOrNull(CloseableReference.java:258)
at com.facebook.common.references.CloseableReference.cloneOrNull(CloseableReference.java:326)
at com.facebook.imagepipeline.cache.CountingMemoryCacheInspector$DumpInfoEntry.<init>(CountingMemoryCacheInspector.java:32)
at com.facebook.imagepipeline.cache.CountingMemoryCacheInspector.dumpCacheContent(CountingMemoryCacheInspector.java:101)
at com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin$3.onReceive(FrescoFlipperPlugin.java:171)
at com.facebook.flipper.android.EventBase.loopForever(Native Method)
at com.facebook.flipper.android.FlipperThread.run(FlipperThread.java:31)
```
Reviewed By: passy
Differential Revision: D19445902
fbshipit-source-id: 12a513d9e34fcac0d546a4eac55932956e4e4d5b
This commit is contained in:
committed by
Facebook Github Bot
parent
1b7a30ae6c
commit
ad720b1f63
@@ -174,8 +174,13 @@ public class FrescoFlipperPlugin extends BufferingFlipperPlugin
|
|||||||
imagePipelineFactory.getEncodedCountingMemoryCache())
|
imagePipelineFactory.getEncodedCountingMemoryCache())
|
||||||
.dumpCacheContent();
|
.dumpCacheContent();
|
||||||
|
|
||||||
responder.success(getImageList(bitmapMemoryCache, encodedMemoryCache));
|
try {
|
||||||
mPerfLogger.endMarker("Sonar.Fresco.listImages");
|
responder.success(getImageList(bitmapMemoryCache, encodedMemoryCache));
|
||||||
|
mPerfLogger.endMarker("Sonar.Fresco.listImages");
|
||||||
|
} finally {
|
||||||
|
bitmapMemoryCache.release();
|
||||||
|
encodedMemoryCache.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -202,20 +207,27 @@ public class FrescoFlipperPlugin extends BufferingFlipperPlugin
|
|||||||
// load from bitmap cache
|
// load from bitmap cache
|
||||||
CloseableReference<CloseableImage> ref =
|
CloseableReference<CloseableImage> ref =
|
||||||
imagePipelineFactory.getBitmapCountingMemoryCache().get(cacheKey);
|
imagePipelineFactory.getBitmapCountingMemoryCache().get(cacheKey);
|
||||||
if (ref != null) {
|
try {
|
||||||
loadFromBitmapCache(ref, imageId, cacheKey, responder);
|
if (ref != null) {
|
||||||
} else {
|
loadFromBitmapCache(ref, imageId, cacheKey, responder);
|
||||||
// try to load from encoded cache
|
|
||||||
CloseableReference<PooledByteBuffer> encodedRef =
|
|
||||||
imagePipelineFactory.getEncodedCountingMemoryCache().get(cacheKey);
|
|
||||||
|
|
||||||
if (encodedRef != null) {
|
|
||||||
loadFromEncodedCache(encodedRef, imageId, cacheKey, responder);
|
|
||||||
} else {
|
} else {
|
||||||
respondError(responder, "no bitmap withId=" + imageId);
|
// try to load from encoded cache
|
||||||
mPerfLogger.cancelMarker("Sonar.Fresco.getImage");
|
CloseableReference<PooledByteBuffer> encodedRef =
|
||||||
return;
|
imagePipelineFactory.getEncodedCountingMemoryCache().get(cacheKey);
|
||||||
|
try {
|
||||||
|
if (encodedRef != null) {
|
||||||
|
loadFromEncodedCache(encodedRef, imageId, cacheKey, responder);
|
||||||
|
} else {
|
||||||
|
respondError(responder, "no bitmap withId=" + imageId);
|
||||||
|
mPerfLogger.cancelMarker("Sonar.Fresco.getImage");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
CloseableReference.closeSafely(encodedRef);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
CloseableReference.closeSafely(ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
mPerfLogger.endMarker("Sonar.Fresco.getImage");
|
mPerfLogger.endMarker("Sonar.Fresco.getImage");
|
||||||
|
|||||||
Reference in New Issue
Block a user