【问题标题】:input element of type range leaks in UIWebViewUIWebView 中类型范围泄漏的输入元素
【发布时间】:2014-07-20 15:12:50
【问题描述】:

当我发现 UIWebView 中类型 range 的输入元素添加到文档时泄漏 12 个字节时,我正准备提交我的应用程序以供审核。没有后续泄漏;即使使用滑块也不行。

如果您能就如何继续我的提交提供任何建议,我将不胜感激。我应该担心 12 个字节吗?我是否应该找到解决方法,比如说,根本不使用这个元素?或者,我是否应该向审阅者记录泄漏(在审阅说明标题下)?

可以使用最小的 UIWebView 应用程序复制泄漏:

#import "TjaViewController.h"

@interface TjaViewController ()
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@end

@implementation TjaViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.webView loadHTMLString:@"<input type='range'>" baseURL:nil];
}

@end

使用 Instruments 分析应用会产生具有以下属性的单个泄漏:

类别:Malloc 12 字节
保留数:1
负责库:JavaScriptCore
负责任的调用者:WTF::fastMalloc(unsigned long)

堆栈恍惚:

32 libsystem_pthread.dylib thread_start
31 libsystem_pthread.dylib _pthread_start
30 libsystem_pthread.dylib _pthread_body
29 WebCore RunWebThread(void*)
28 CoreFoundation CFRunLoopRunInMode
27 CoreFoundation CFRunLoopRunSpecific
26 CoreFoundation __CFRunLoopRun
25 CoreFoundation __CFRunLoopDoSources0
24 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
23 WebCore HandleRunSource
22 WebCore ___ZN7WebCoreL26applicationDidBecomeActiveEP22__CFNotificationCenterPvPK10__CFStringPKvPK14__CFDictionary_block_invoke
21 WebCore WebCore::ThreadTimers::sharedTimerFiredInternal()
20 WebCore WebCore::DocumentLoader::handleSubstituteDataLoadNow(WebCore::Timer<WebCore::DocumentLoader>*)
19 WebCore WebCore::DocumentLoader::responseReceived(WebCore::CachedResource*, WebCore::ResourceResponse const&)
18 WebCore WebCore::DocumentLoader::continueAfterContentPolicy(WebCore::PolicyAction)
17 WebCore WebCore::DocumentLoader::dataReceived(WebCore::CachedResource*, char const*, int)
16 WebCore WebCore::DocumentLoader::commitLoad(char const*, int)
15 WebKit WebFrameLoaderClient::committedLoad(WebCore::DocumentLoader*, char const*, int)
14 WebKit -[WebDataSource(WebInternal) _receivedData:]
13 WebKit -[WebHTMLRepresentation receivedData:withDataSource:]
12 WebCore WebCore::DocumentLoader::commitData(char const*, unsigned long)
11 WebCore WebCore::DecodedDataDocumentParser::appendBytes(WebCore::DocumentWriter*, char const*, unsigned long)
10 WebCore WebCore::HTMLDocumentParser::append(WTF::PassRefPtr<WTF::StringImpl>)
9 WebCore WebCore::HTMLDocumentParser::pumpTokenizer(WebCore::HTMLDocumentParser::SynchronousMode)
8 WebCore WebCore::HTMLDocumentParser::constructTreeFromHTMLToken(WebCore::HTMLToken&)
7 WebCore WebCore::HTMLConstructionSite::executeQueuedTasks()
6 WebCore WebCore::executeTask(WebCore::HTMLConstructionSiteTask&)
5 WebCore WebCore::insert(WebCore::HTMLConstructionSiteTask&, bool)
4 WebCore WebCore::HTMLInputElement::attach(WebCore::Node::AttachContext const&)
3 WebCore WebCore::FeatureObserver::didObserve(WebCore::FeatureObserver::Feature)
2 JavaScriptCore WTF::BitVector::resizeOutOfLine(unsigned long)
1 JavaScriptCore WTF::fastMalloc(unsigned long)
0 JavaScriptCore WTF::MallocHook::recordAllocation(void*, unsigned long)

【问题讨论】:

  • 我认为这是 webkit 核心中的一些错误
  • 我尝试使用 loadRequest 获取网页并得到相同的泄漏 WebCore::FeatureObserver::observe(WebCore::Document*, WebCore::FeatureObserver::Feature) WebCore::FeatureObserver:: didObserve(WebCore::FeatureObserver::Feature) WTF::BitVector::resizeOutOfLine(unsigned long) WTF::fastMalloc(unsigned long) WTF::MallocHook::recordAllocation(void*, unsigned long)
  • 感谢@buaacss 确认泄漏。

标签: memory-leaks uiwebview webkit app-store html-input


【解决方案1】:

我想我明白了

似乎是 libWTF 中的泄漏

这是来自https://github.com/leolannenmaki/JavaScriptCore-iOS的原始代码

void BitVector::resizeOutOfLine(size_t numBits)
{
    ASSERT(numBits > maxInlineBits());
    OutOfLineBits* newOutOfLineBits = OutOfLineBits::create(numBits);
    size_t newNumWords = newOutOfLineBits->numWords();
    if (isInline()) {
    // Make sure that all of the bits are zero in case we do a no-op resize.
        *newOutOfLineBits->bits() = m_bitsOrPointer & ~(static_cast<uintptr_t>(1) << maxInlineBits());
        memset(newOutOfLineBits->bits() + 1, 0, (newNumWords - 1) * sizeof(void*));
    } else {
        if (numBits > size()) {
            size_t oldNumWords = outOfLineBits()->numWords();
            memcpy(newOutOfLineBits->bits(), outOfLineBits()->bits(), oldNumWords * sizeof(void*));
            memset(newOutOfLineBits->bits() + oldNumWords, 0, (newNumWords - oldNumWords) * sizeof(void*));
        } else
            memcpy(newOutOfLineBits->bits(), outOfLineBits()->bits(), newOutOfLineBits->numWords() * sizeof(void*));
        OutOfLineBits::destroy(outOfLineBits());
    }
    m_bitsOrPointer = bitwise_cast<uintptr_t>(newOutOfLineBits) >> 1;
}

很明显 newOutOfLineBits 在代码执行 isInline() 时没有被破坏

我尝试替换系统JavascriptCore.framework

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/Frameworks/JavaScriptCore.framework

但是失败了,系统框架是从动态库编译出来的

据我所知,苹果禁止为 iOS 编译动态库...

所以我认为唯一的方法是向 Apple 报告此泄漏......

【讨论】:

  • 谢谢@buaacss!我提交了错误报告。
  • 我们认为我们也有一些泄漏,根据 Instruments 来自 WTF::FastMalloc。然而对我们来说,它来自加载图像。您能否指出您提交给 Apple 的错误?
  • 错误报告 17808677“UIWebView 中类型范围泄漏的 元素”
猜你喜欢
  • 2011-09-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-17
相关资源
最近更新 更多