ABMultiValueCopyValueAtIndex将消息发送到解除分配的实例

时间:2010-03-13 07:32:33

标签: iphone

HI,

I am getting a issue when trying to access the kABPersonInstantMessageProperty. The code is as follows :

    ABMultiValueRef IMS = ABRecordCopyValue(record, kABPersonInstantMessageProperty);
CFRetain(IMS);
if(IMS)
{
    int IMSCount = ABMultiValueGetCount(IMS);
    MWLOG(5, @"**** IMS COunt **** : %d", IMSCount);
    for(int iIM =0; iIM < IMSCount; ++iIM)
    {
        MWLOG(5, @"index *** : %d", iIM);
        CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(IMS, iIM);
        NSString* label = (NSString*)ABMultiValueCopyLabelAtIndex(IMS, iIM);

        NSString* service= (NSString*)CFDictionaryGetValue(dict, kABPersonInstantMessageServiceKey);
        NSString* username= (NSString*)CFDictionaryGetValue(dict, kABPersonInstantMessageUsernameKey);

        if(label) CFRelease(label);
        if(service) CFRelease(service);
        if(username) CFRelease(username);
        if(dict) CFRelease(dict);
    }

    CFRelease(IMS);
}

但是我在控制台中收到以下错误:

2010-03-13 12:39:16.731 mwp[1464:4f0b] *** -[CFString retain]: message sent to deallocated instance 0x1582820

2010-03-13 12:49:12.219 mwp[1464:4f0b] *** -[CFString _cfTypeID]: message sent to deallocated instance 0x15f0bf0

调试器中的堆栈跟踪如下:

**#0    0x3026e017 in ___forwarding___

**#1    0x3024a0a2 in __forwarding_prep_0___**

**#2    0x30201368 in CFRetain **

**#3    0x325bdb6d in ABCCopyDictionaryWithTypes**

**#4    0x325bdbe3 in ABCMultiDictionaryCreateCopy**
  • 问题出在api上吗?我在网上搜索但找不到任何解决方案。

我只是在阅读InstantMessageProperty时遇到此问题。

任何帮助都将非常感谢....

最诚挚的问候,

Mohammed Sadiq。

1 个答案:

答案 0 :(得分:1)

    NSString* service= (NSString*)CFDictionaryGetValue(...);
    NSString* username= (NSString*)CFDictionaryGetValue(...);
    ...
    if(service) CFRelease(service);
    if(username) CFRelease(username);

CFDictionaryGetValue是一个“获取”功能。 the Get Rule你不拥有它们,所以你不应该 CF发布它们。否则你将双重释放这些值。

只需删除这两条CFRelease行。