Bug 179981

Summary: Fix dictionary leak in lookup, convert FindOptions to OptionSet, tweak code style nearby
Product: WebKit Reporter: Darin Adler <darin>
Component: WebCore Misc.Assignee: Darin Adler <darin>
Status: RESOLVED FIXED    
Severity: Normal CC: ews-watchlist, jlewis3, sam, thorton, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Archive of layout-test-results from ews126 for ios-simulator-wk2
none
Patch sam: review+

Description Darin Adler 2017-11-23 12:19:17 PST
Fix dictionary leak in lookup, convert FindOptions to OptionSet, tweak code style nearby
Comment 1 Darin Adler 2017-11-23 13:06:13 PST Comment hidden (obsolete)
Comment 2 EWS Watchlist 2017-11-23 13:08:34 PST Comment hidden (obsolete)
Comment 3 Darin Adler 2017-11-23 19:21:51 PST Comment hidden (obsolete)
Comment 4 EWS Watchlist 2017-11-23 19:24:59 PST Comment hidden (obsolete)
Comment 5 EWS Watchlist 2017-11-23 20:53:56 PST Comment hidden (obsolete)
Comment 6 EWS Watchlist 2017-11-23 20:53:57 PST Comment hidden (obsolete)
Comment 7 Darin Adler 2017-11-24 11:33:06 PST
Created attachment 327555 [details]
Patch
Comment 8 EWS Watchlist 2017-11-24 11:35:20 PST
Attachment 327555 [details] did not pass style-queue:


ERROR: Source/WTF/wtf/OptionSet.h:133:  Missing spaces around |  [whitespace/operators] [3]
ERROR: Source/WTF/wtf/OptionSet.h:138:  Missing spaces around |  [whitespace/operators] [3]
Total errors found: 2 in 34 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 Sam Weinig 2017-11-24 15:39:11 PST
Comment on attachment 327555 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=327555&action=review

> Source/WTF/wtf/OptionSet.h:151
> +    constexpr friend OptionSet operator|(OptionSet lhs, OptionSet rhs)
> +    {
> +        return fromRaw(lhs.m_storage | rhs.m_storage);
> +    }
> +
> +    constexpr friend OptionSet operator|(OptionSet lhs, T rhs)
> +    {
> +        return lhs | OptionSet { rhs };
> +    }
> +
>      constexpr friend OptionSet operator-(OptionSet lhs, OptionSet rhs)
>      {
> -        return OptionSet::fromRaw(lhs.m_storage & ~rhs.m_storage);
> +        return fromRaw(lhs.m_storage & ~rhs.m_storage);
> +    }
> +
> +    constexpr friend OptionSet operator-(OptionSet lhs, T rhs)
> +    {
> +        return lhs - OptionSet { rhs };
>      }

It would be good to add test cases for these to the existing OptionSet tests in TestWebKitAPI.

> Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h:111
> +    std::tuple<String, RetainPtr<PDFSelection>, RetainPtr<NSDictionary>> lookupTextAtLocation(const WebCore::FloatPoint&, WebHitTestResultData&) const;

I am surprised you don't have to #include <tuple>
Comment 10 Darin Adler 2017-11-24 17:08:06 PST
Comment on attachment 327555 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=327555&action=review

>> Source/WTF/wtf/OptionSet.h:151
>>      }
> 
> It would be good to add test cases for these to the existing OptionSet tests in TestWebKitAPI.

I will do that. In a separate patch.

>> Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h:111
>> +    std::tuple<String, RetainPtr<PDFSelection>, RetainPtr<NSDictionary>> lookupTextAtLocation(const WebCore::FloatPoint&, WebHitTestResultData&) const;
> 
> I am surprised you don't have to #include <tuple>

Someone includes it I guess.
Comment 11 Darin Adler 2017-11-24 17:10:04 PST
Committed r225142: <https://trac.webkit.org/changeset/225142>
Comment 12 Radar WebKit Bug Importer 2017-11-24 17:11:27 PST
<rdar://problem/35685066>
Comment 13 Matt Lewis 2017-11-27 10:59:28 PST
This change has caused an API timeout on Sierra for the test: 
WKWebViewCandidateTests.ClickingInTextFieldDoesNotThrashCandidateVisibility

https://build.webkit.org/builders/Apple%20Sierra%20Debug%20WK2%20(Tests)/builds/4175/steps/run-api-tests/logs/stdio
https://build.webkit.org/builders/Apple%20Sierra%20Debug%20WK2%20(Tests)/builds/4175
Comment 14 Tim Horton 2017-11-27 13:15:40 PST
Comment on attachment 327555 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=327555&action=review

> Source/WebCore/editing/mac/DictionaryLookup.mm:67
> +    NSDictionary *retainedOptions = nil;
> +    auto result = [classLULookupDefinitionModule tokenRangeForString:string range:range options:&retainedOptions];
> +    *options = adoptNS(retainedOptions);

What led you to this leak? What indication is there that options is not autoreleased?
Comment 15 Darin Adler 2017-11-30 09:43:13 PST
(In reply to Tim Horton from comment #14)
> What led you to this leak?

Reading the source code.

> What indication is there that options is not autoreleased?

I read the source code of the LULookupDefinitionModule. Maybe I misread it?
Comment 16 Darin Adler 2017-11-30 09:45:22 PST
(In reply to Darin Adler from comment #15)
> > What indication is there that options is not autoreleased?
> 
> I read the source code of the LULookupDefinitionModule. Maybe I misread it?

I did misread it! Oops, will fix right away.
Comment 17 Darin Adler 2017-11-30 09:46:16 PST
Reading the tokenRangeForString source code I saw a copy, but missed an autorelease later in the function.
Comment 18 Darin Adler 2017-11-30 09:48:54 PST
Comment on attachment 327555 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=327555&action=review

>> Source/WebCore/editing/mac/DictionaryLookup.mm:67
>> +    *options = adoptNS(retainedOptions);
> 
> What led you to this leak? What indication is there that options is not autoreleased?

My bad, I misread the source code to this function. I will fix this right now.
Comment 19 Darin Adler 2017-11-30 09:58:23 PST
Patch too big to just land without review, opening new bug 180202 with my patch.
Comment 20 Tim Horton 2017-11-30 09:58:56 PST
(In reply to Darin Adler from comment #19)
> Patch too big to just land without review, opening new bug 180202 with my
> patch.

I already fixed this in https://trac.webkit.org/changeset/225196/webkit
Comment 21 Tim Horton 2017-11-30 09:59:17 PST
(In reply to Tim Horton from comment #20)
> (In reply to Darin Adler from comment #19)
> > Patch too big to just land without review, opening new bug 180202 with my
> > patch.
> 
> I already fixed this in https://trac.webkit.org/changeset/225196/webkit

Just somehow managed to not mention it here :(
Comment 22 Darin Adler 2017-11-30 10:03:45 PST
Oops, OK.