CF释放导致崩溃
CFRelease causes crash
以下代码导致我的C++应用程序崩溃:
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()
在内存管理方面是独特的。它使用一个对传入字典的引用。由于您的代码只有一个引用,因此在调用后它不再拥有match_dictionary
字典,并且不能对其调用CFRelease()
。
来自文档:
matching
包含匹配信息的CF字典,其中一个引用总是被该函数使用…
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 释放错误后堆使用
- 内联映射初始化的动态atexit析构函数崩溃
- 在函数内部错误定位后,从函数中释放返回的指针会导致芯片崩溃
- 释放字符的动态数组时崩溃
- 在崩溃时释放分配的指针的正确方法
- 复制赋值构造函数中的aligned_alloc内存块在释放时崩溃
- 当我释放由CFFI生成的DLL分配的char*时,为什么我的应用程序会崩溃
- 要释放动态数组初始化时程序崩溃
- 如何在程序崩溃后释放managedsharedmemory:在调试过程中使用哪些有效的技术
- C++,libxslt:在释放样式表之后释放样式表文档会导致崩溃
- CF释放导致崩溃
- 释放动态分配的内存时程序崩溃
- 未释放筛选器com对象导致崩溃
- 释放模式下的boost线程崩溃
- 当使用HoughLinesP时,Qt中的OpenCV在释放行向量时崩溃
- 试图释放对象指针的向量时崩溃
- c++程序在崩溃时是否自动释放内存?
- 智能指针如何知道何时释放程序崩溃时的资源
- 当使用C++目标的释放模式时,为什么这个Haxe try-catch块仍然崩溃