WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
127469
[GTK] Avoid unnecessary string duplications in FileSystemGtk
https://bugs.webkit.org/show_bug.cgi?id=127469
Summary
[GTK] Avoid unnecessary string duplications in FileSystemGtk
Carlos Garcia Campos
Reported
2014-01-23 00:58:56 PST
We are using fileSystemRepresentation() everywhere internally which returns a CString that always duplicates the string.
Attachments
Patch
(9.04 KB, patch)
2014-01-23 01:01 PST
,
Carlos Garcia Campos
no flags
Details
Formatted Diff
Diff
Patch
(9.05 KB, patch)
2014-01-23 02:23 PST
,
Carlos Garcia Campos
no flags
Details
Formatted Diff
Diff
Updated patch
(9.14 KB, patch)
2014-01-23 10:35 PST
,
Carlos Garcia Campos
mrobinson
: review+
Details
Formatted Diff
Diff
Show Obsolete
(2)
View All
Add attachment
proposed patch, testcase, etc.
Carlos Garcia Campos
Comment 1
2014-01-23 01:01:29 PST
Created
attachment 221956
[details]
Patch
Sergio Villar Senin
Comment 2
2014-01-23 01:28:37 PST
Comment on
attachment 221956
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=221956&action=review
Looks good to me but your changes unveil an already existing bug. See inline...
> Source/WebCore/platform/gtk/FileSystemGtk.cpp:84 > + GUniquePtr<gchar> display(g_filename_to_utf8(filename.get(), 0, nullptr, nullptr, nullptr));
This definitely sounds like a bug to me. We're passing 0 as the string length. We should either use -1 if null terminated or the actual string length if known.
Carlos Garcia Campos
Comment 3
2014-01-23 02:22:32 PST
(In reply to
comment #2
)
> (From update of
attachment 221956
[details]
) > View in context:
https://bugs.webkit.org/attachment.cgi?id=221956&action=review
> > Looks good to me but your changes unveil an already existing bug. See inline... > > > Source/WebCore/platform/gtk/FileSystemGtk.cpp:84 > > + GUniquePtr<gchar> display(g_filename_to_utf8(filename.get(), 0, nullptr, nullptr, nullptr)); > > This definitely sounds like a bug to me. We're passing 0 as the string length. We should either use -1 if null terminated or the actual string length if known.
You are right, that should be -1
Carlos Garcia Campos
Comment 4
2014-01-23 02:23:51 PST
Created
attachment 221964
[details]
Patch Good catch Sergio! Patch updated
Martin Robinson
Comment 5
2014-01-23 06:14:47 PST
Comment on
attachment 221956
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=221956&action=review
> Source/WebCore/ChangeLog:11 > + We are using fileSystemRepresentation() everywhere internally > + which returns a CString that always duplicates the string. > + Add unescapedFilename() internal helper function that returns a > + GUniquePtr and used it everywhere instead of fileSystemRepresentation().
I'm not sure this is true. CStrings contain a reference-counted internal buffer.
Carlos Garcia Campos
Comment 6
2014-01-23 06:28:27 PST
(In reply to
comment #5
)
> (From update of
attachment 221956
[details]
) > View in context:
https://bugs.webkit.org/attachment.cgi?id=221956&action=review
> > > Source/WebCore/ChangeLog:11 > > + We are using fileSystemRepresentation() everywhere internally > > + which returns a CString that always duplicates the string. > > + Add unescapedFilename() internal helper function that returns a > > + GUniquePtr and used it everywhere instead of fileSystemRepresentation(). > > I'm not sure this is true. CStrings contain a reference-counted internal buffer.
The constructor always allocates memory and copies the given string.
Carlos Garcia Campos
Comment 7
2014-01-23 06:32:08 PST
Check it yourself:
http://trac.webkit.org/browser/trunk/Source/WTF/wtf/text/CString.cpp#L63
Martin Robinson
Comment 8
2014-01-23 09:12:23 PST
Comment on
attachment 221964
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=221964&action=review
You're right. I neglected to notice that fileSystemRepresentation was converting from a c string into a CString.
> Source/WebCore/platform/gtk/FileSystemGtk.cpp:62 > + if (path.isEmpty()) > + return nullptr; > + return GUniquePtr<char>(g_uri_unescape_string(path.utf8().data(), nullptr)); > +}
This doesn't appear to be doing the right thing for Windows. In Windows we just need to return path.utf8() to maintain the current behavior.
Carlos Garcia Campos
Comment 9
2014-01-23 09:28:12 PST
Comment on
attachment 221964
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=221964&action=review
>> Source/WebCore/platform/gtk/FileSystemGtk.cpp:62 >> +} > > This doesn't appear to be doing the right thing for Windows. In Windows we just need to return path.utf8() to maintain the current behavior.
You are right, I forgot the windows ifdef. Will update the patch, thanks!
Carlos Garcia Campos
Comment 10
2014-01-23 10:35:04 PST
Created
attachment 221998
[details]
Updated patch Fixed the windows behaviour.
Carlos Garcia Campos
Comment 11
2014-01-28 00:11:13 PST
Committed
r162921
: <
http://trac.webkit.org/changeset/162921
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug