首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何修复这个漏洞?

如何修复这个漏洞?
EN

Stack Overflow用户
提问于 2011-12-05 09:29:51
回答 1查看 142关注 0票数 0

我在分配NSOperationQueue对象的helper.offlineQueue行上遇到了一个漏洞。问题是,我不太确定在这个方法中在哪里发布它……

代码语言:javascript
运行
复制
+ (void)flushOfflineQueue
{
    // TODO - if an item fails, after all items are shared, it should present a summary view and allow them to see which items failed/succeeded

    // Check for a connection
    if (![self connected])
        return;

    // Open list
    NSMutableArray *queueList = [self getOfflineQueueList];

    // Run through each item in the quietly in the background
    // TODO - Is this the best behavior?  Instead, should the user confirm sending these again?  Maybe only if it has been X days since they were saved?
    //      - want to avoid a user being suprised by a post to Twitter if that happens long after they forgot they even shared it.
    if (queueList != nil)
    {
        SHK *helper = [self currentHelper];

        if (helper.offlineQueue == nil)
            helper.offlineQueue = [[NSOperationQueue alloc] init];      

        SHKItem *item;
        NSString *sharerId, *uid;

        for (NSDictionary *entry in queueList)
        {
            item = [SHKItem itemFromDictionary:[entry objectForKey:@"item"]];
            sharerId = [entry objectForKey:@"sharer"];
            uid = [entry objectForKey:@"uid"];

            if (item != nil && sharerId != nil)
                [helper.offlineQueue addOperation:[[[SHKOfflineSharer alloc] initWithItem:item forSharer:sharerId uid:uid] autorelease]];
        }

        // Remove offline queue - TODO: only do this if everything was successful?
        [[NSFileManager defaultManager] removeItemAtPath:[self offlineQueueListPath] error:nil];

    }
}

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-05 10:40:46

我希望你应该这样做:

代码语言:javascript
运行
复制
helper.offlineQueue = [[[NSOperationQueue alloc] init] autorelease];

SHK对象本身应该保留队列,并在完成时释放它。由于分配而持有的引用可以立即释放。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8380102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档