Commit 7cf93613 authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Fix Mojo handle leak when Shape Detection is not available

The native handle passed to the Shape Detection interface registrar can
be leaked if the barcode or text detection feature is not available.
This change ensures that it is always wrapped in a MessagePipeHandle and
closed on failure to bind to an implementation.

Bug: 1020746
Change-Id: Ic8a60135ed1ff43c27bb074bd577442dac40482f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2032175
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#737406}
parent b772c39a
......@@ -20,10 +20,16 @@ class InterfaceRegistrar {
@CalledByNative
static void bindBarcodeDetectionProvider(int nativeHandle) {
// Immediately wrap |nativeHandle| as it cannot be allowed to leak.
MessagePipeHandle handle = messagePipeHandleFromNative(nativeHandle);
BarcodeDetectionProvider impl = BarcodeDetectionProviderImpl.create();
if (impl != null) {
BarcodeDetectionProvider.MANAGER.bind(impl, messagePipeHandleFromNative(nativeHandle));
if (impl == null) {
handle.close();
return;
}
BarcodeDetectionProvider.MANAGER.bind(impl, handle);
}
@CalledByNative
......@@ -34,9 +40,15 @@ class InterfaceRegistrar {
@CalledByNative
static void bindTextDetection(int nativeHandle) {
// Immediately wrap |nativeHandle| as it cannot be allowed to leak.
MessagePipeHandle handle = messagePipeHandleFromNative(nativeHandle);
TextDetection impl = TextDetectionImpl.create();
if (impl != null) {
TextDetection.MANAGER.bind(impl, messagePipeHandleFromNative(nativeHandle));
if (impl == null) {
handle.close();
return;
}
TextDetection.MANAGER.bind(impl, handle);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment