Fabric: Fixed crash caused by incorrect bridge transfer annotation

Summary:
Don't ask.
Really, all those descriptions from official docs like below are useless:
 * `__bridge_transfer` Moves a Core Foundation pointer to Objective-C with transfer of the ownership to ARC.
 * `__bridge` Transfers a pointer between Objective-C and Core Foundation with no transfer of ownership

All that is totally confusing and useless. At the end of the day, we only have to think about which additional `CFRetain` and `CFRelease` ARC will add or will not add for our pointers.
So, following official docs recommendation, we would like to add `__bridge_transfer` because of course, we do want to ARC managing the variable after we introduced it to ARC here. But we also want to have shared ownership of this. That's the key. If we use `__bridge_transfer` ARC will assume that this variable already retained once (because it exists) and will call CFRelease at the end of the scope. Right before that when we pass this variable down to call stack ARC will retain and then manage the variable according to the rest of the code. But still, from this point, we will have zero-balanced reference counter; the owning by `shared_ptr` bump is already compensated with `CFRelease` at the end of the scope. As soon as the rest of the code release the object, it will be incorrectly deallocated.

So, instead of using `__bridge_transfer` we have to use `__bridge`. That will indicate that *in this block* ARC does not manage the reference counter of the variable (which is kinda true because having `shared_ptr` inside the block already retains that) and will not add `CFRelease` at the end of the block.

Reviewed By: mdvacca

Differential Revision: D10054241

fbshipit-source-id: 6e82c5270fe5d53f1ed68e167b94f70dc4367a9f
This commit is contained in:
Valentin Shergin 2018-09-26 14:30:53 -07:00 коммит произвёл Facebook Github Bot
Родитель 7e9c3f77cc
Коммит 8206e841d1
1 изменённых файлов: 1 добавлений и 1 удалений

Просмотреть файл

@ -74,7 +74,7 @@ using namespace facebook::react;
assert(_imageLocalData);
auto future = _imageLocalData->getImageRequest().getResponseFuture();
future.via(&MainQueueExecutor::instance()).then([self](ImageResponse &&imageResponse) {
self.image = (__bridge_transfer UIImage *)imageResponse.getImage().get();
self.image = (__bridge UIImage *)imageResponse.getImage().get();
});
}