summaryrefslogtreecommitdiffstats
path: root/device/hid
diff options
context:
space:
mode:
authorreillyg <reillyg@chromium.org>2015-04-13 12:04:30 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-13 19:04:54 +0000
commit2411f2af4b2f92c725c0798400bc1253bae40e46 (patch)
treebfbb8d3b238921ef6d26cb15e13560abb844e0f9 /device/hid
parent2a6329e0c66a838a247ba709a77fe0f8be3c2dcb (diff)
downloadchromium_src-2411f2af4b2f92c725c0798400bc1253bae40e46.zip
chromium_src-2411f2af4b2f92c725c0798400bc1253bae40e46.tar.gz
chromium_src-2411f2af4b2f92c725c0798400bc1253bae40e46.tar.bz2
Pass reference to matching dictionary in device::HidServiceMac::Connect.
IORegistryGetMatchingService consumes a reference to the matching dictionary passed to it. Call release() on the ScopedCFTypeRef holding the dictionary so that the reference is passed to the callee so that it is not released later causing a crash. BUG=474820 Review URL: https://codereview.chromium.org/1070423002 Cr-Commit-Position: refs/heads/master@{#324893}
Diffstat (limited to 'device/hid')
-rw-r--r--device/hid/hid_service_mac.cc12
1 files changed, 10 insertions, 2 deletions
diff --git a/device/hid/hid_service_mac.cc b/device/hid/hid_service_mac.cc
index fb12d96..081e668 100644
--- a/device/hid/hid_service_mac.cc
+++ b/device/hid/hid_service_mac.cc
@@ -142,9 +142,17 @@ void HidServiceMac::Connect(const HidDeviceId& device_id,
base::ScopedCFTypeRef<CFDictionaryRef> matching_dict(
IORegistryEntryIDMatching(device_id));
+ if (!matching_dict.get()) {
+ HID_LOG(EVENT) << "Failed to create matching dictionary for ID: "
+ << device_id;
+ task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));
+ return;
+ }
- base::mac::ScopedIOObject<io_service_t> service(
- IOServiceGetMatchingService(kIOMasterPortDefault, matching_dict.get()));
+ // IOServiceGetMatchingService consumes a reference to the matching dictionary
+ // passed to it.
+ base::mac::ScopedIOObject<io_service_t> service(IOServiceGetMatchingService(
+ kIOMasterPortDefault, matching_dict.release()));
if (!service.get()) {
HID_LOG(EVENT) << "IOService not found for ID: " << device_id;
task_runner_->PostTask(FROM_HERE, base::Bind(callback, nullptr));