Skip to content

Commit

Permalink
Don't close reference to image in getSize
Browse files Browse the repository at this point in the history
Summary:
ImageLoader improperly closes both the image reference
(which is shared) and the DataSource (which is shared, and should only be
handled by BaseDataSubscriber when it is correct).

Reviewed By: plamenko

Differential Revision: D3441752

fbshipit-source-id: bfb3d0281cd9ae789cba4079978ef46d295ac8f5
  • Loading branch information
Ahmed El-Helw authored and grabbou committed Jun 20, 2016
1 parent a7a34a1 commit ccd0181
Showing 1 changed file with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

import android.net.Uri;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.WritableMap;
import com.facebook.common.executors.CallerThreadExecutor;
import com.facebook.common.references.CloseableReference;
import com.facebook.datasource.BaseDataSubscriber;
Expand All @@ -23,10 +20,12 @@
import com.facebook.imagepipeline.image.CloseableImage;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.WritableMap;

public class ImageLoaderModule extends ReactContextBaseJavaModule {

Expand Down Expand Up @@ -83,27 +82,20 @@ protected void onNewResultImpl(
sizes.putInt("width", image.getWidth());
sizes.putInt("height", image.getHeight());

image.close();
promise.resolve(sizes);
} catch (Exception e) {
promise.reject(ERROR_GET_SIZE_FAILURE, e);
} finally {
CloseableReference.closeSafely(ref);
dataSource.close();
}
} else {
dataSource.close();
promise.reject(ERROR_GET_SIZE_FAILURE);
}
}

@Override
protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
try {
promise.reject(ERROR_GET_SIZE_FAILURE, dataSource.getFailureCause());
} finally {
dataSource.close();
}
promise.reject(ERROR_GET_SIZE_FAILURE, dataSource.getFailureCause());
}
};
dataSource.subscribe(dataSubscriber, CallerThreadExecutor.getInstance());
Expand Down

0 comments on commit ccd0181

Please sign in to comment.