Bug 190865 - [WPE][GTK] Cleanups to the certificate encoder
Summary: [WPE][GTK] Cleanups to the certificate encoder
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Claudio Saavedra
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-10-24 01:01 PDT by Claudio Saavedra
Modified: 2018-10-24 07:09 PDT (History)
3 users (show)

See Also:


Attachments
Patch (2.21 KB, patch)
2018-10-24 01:01 PDT, Claudio Saavedra
no flags Details | Formatted Diff | Diff
Patch (2.32 KB, patch)
2018-10-24 01:51 PDT, Claudio Saavedra
zan: review+
mcatanzaro: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Claudio Saavedra 2018-10-24 01:01:29 PDT
[WPE][GTK] Remove redundant variable from certificate encoder
Comment 1 Claudio Saavedra 2018-10-24 01:01:46 PDT
Created attachment 353027 [details]
Patch
Comment 2 Zan Dobersek 2018-10-24 01:26:05 PDT
Comment on attachment 353027 [details]
Patch

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

> Source/WebKit/Shared/soup/WebCoreArgumentCodersSoup.cpp:61
>      GByteArray* certificateData = 0;
>      Vector<GByteArray*> certificatesDataList;

Move `certificateData` into the `do { }` scope, limiting its use to that part of the code.

`certificatesDataList` should IMO be a Vector<GRefPtr<GByteArray>>, immediately adopting the `certificateData` pointer and avoiding the out-of-the-blue adoptGRef() int the loop below.

> Source/WebKit/Shared/soup/WebCoreArgumentCodersSoup.cpp:80
> +    for (int i = certificatesDataList.size(); i > 0; i--) {

Use size_t for `i`. In the post-loop segment, use the prefixed decrement: `--i`.
Comment 3 Claudio Saavedra 2018-10-24 01:51:40 PDT
Created attachment 353028 [details]
Patch
Comment 4 Zan Dobersek 2018-10-24 01:56:15 PDT
Comment on attachment 353028 [details]
Patch

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

> Source/WebKit/Shared/soup/WebCoreArgumentCodersSoup.cpp:63
> +        GByteArray* certificateData = 0;
>          g_object_get(G_OBJECT(certificate), "certificate", &certificateData, NULL);

`nullptr` should be used in both lines.

> Source/WebKit/Shared/soup/WebCoreArgumentCodersSoup.cpp:80
> +        GRefPtr<GByteArray> certificate = certificatesDataList[i - 1];

This takes an extra reference to the GByteArray pointer stored in the Vector. Use auto& to bind a C++ reference to the existing GRefPtr instead:
    `auto& certificate = ...`
Comment 5 Claudio Saavedra 2018-10-24 02:10:42 PDT
Committed r237377: <https://trac.webkit.org/changeset/237377>
Comment 6 Radar WebKit Bug Importer 2018-10-24 02:11:27 PDT
<rdar://problem/45514258>
Comment 7 Michael Catanzaro 2018-10-24 07:06:08 PDT
Comment on attachment 353028 [details]
Patch

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

> Source/WebKit/Shared/soup/WebCoreArgumentCodersSoup.cpp:68
>          certificatesDataList.append(certificateData);

I think you need adoptGRef() here to avoid leaking it, right?

>> Source/WebKit/Shared/soup/WebCoreArgumentCodersSoup.cpp:80
>> +        GRefPtr<GByteArray> certificate = certificatesDataList[i - 1];
> 
> This takes an extra reference to the GByteArray pointer stored in the Vector. Use auto& to bind a C++ reference to the existing GRefPtr instead:
>     `auto& certificate = ...`

It's less confusing if you bypass the GRefPtr (because you don't need to hold a ref here) and just go straight to the GByteArray:

GByteArray* certificate = certificatesDataList[i - 1].get();
Comment 8 Michael Catanzaro 2018-10-24 07:09:56 PDT
Oh I missed that you already committed (cq? was still set, try not to forget about that). Anyway, my second comment isn't important, but please check the first one to make sure you're not leaking.