下面的代码位导致系统崩溃在我的C++应用程序:CFRelease导致崩溃
CFMutableDictionaryRef property_dictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
if (! property_dictionary)
break;
CFDictionarySetValue(property_dictionary, CFSTR("somekey"), CFSTR("someval"));
CFMutableDictionaryRef match_dictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
if (! match_dictionary)
break;
CFDictionarySetValue(match_dictionary, CFSTR(kIOPropertyMatchKey), property_dictionary);
io_iterator_t service = IOServiceGetMatchingService(kIOMasterPortDefault, match_dictionary);
if (property_dictionary != NULL)
CFRelease(property_dictionary);
// the following bit causes crash
if (match_dictionary != NULL)
CFRelease(match_dictionary);
不知IOServiceGetMatchingService有什么关系呢。
是否崩溃消失,如果你删除通话到'IOServiceGetMatchingService'? – 2015-03-31 02:42:37
是的,事实证明。 – Ash 2015-04-01 00:33:18