After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 676594 - [Patch] fix g_reload_user_special_dirs_cache
[Patch] fix g_reload_user_special_dirs_cache
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-05-22 20:07 UTC by Marc-Antoine Perennou
Modified: 2012-06-23 21:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix (1.12 KB, patch)
2012-05-22 20:07 UTC, Marc-Antoine Perennou
committed Details | Review
Fix previous test (965 bytes, patch)
2012-05-23 15:33 UTC, Marc-Antoine Perennou
rejected Details | Review
Rename previous test and add a new one (1.57 KB, patch)
2012-05-23 15:35 UTC, Marc-Antoine Perennou
needs-work Details | Review
Compare pointers instead of strings (807 bytes, patch)
2012-05-23 20:37 UTC, Marc-Antoine Perennou
none Details | Review
Add test_desktop_special_dit (1.76 KB, patch)
2012-05-23 20:38 UTC, Marc-Antoine Perennou
none Details | Review
Add test_desktop_special_dir (1.76 KB, patch)
2012-05-23 20:40 UTC, Marc-Antoine Perennou
none Details | Review

Description Marc-Antoine Perennou 2012-05-22 20:07:28 UTC
Created attachment 214698 [details] [review]
Fix

We handle a special case for G_USER_DIRECTORY_DESKTOP when we init the values but drop it when we reload them.
Fix this by preferring old values to NULL
Comment 1 Marc-Antoine Perennou 2012-05-22 20:13:24 UTC
Btw, there were a couple of tabs in this function, replaced them with spaces to be consistent and amended locally
Comment 2 Matthias Clasen 2012-05-23 10:23:16 UTC
Review of attachment 214698 [details] [review]:

Looks good, thanks. It would be nice to add a testcase for this special problem too.
Comment 3 Marc-Antoine Perennou 2012-05-23 15:33:54 UTC
Created attachment 214774 [details] [review]
Fix previous test

This value can be free'd in g_reload_user_special_dirs_cache
Comment 4 Marc-Antoine Perennou 2012-05-23 15:35:15 UTC
Created attachment 214775 [details] [review]
Rename previous test and add a new one

Previous test was a good test for this fix, but not for a general case, since it's basically the only value we handle in a different way when initializing.
Comment 5 Marc-Antoine Perennou 2012-05-23 15:46:09 UTC
Or maybe the new test should test for the result being !null instead ? Since it's always set at initilization ?
Comment 6 Matthias Clasen 2012-05-23 19:19:00 UTC
Review of attachment 214774 [details] [review]:

::: glib/tests/utils.c
@@ +430,2 @@
   g_assert_cmpstr (dir, ==, dir2);
+  g_free (dir);

We can't free the values returned by g_get_user_special_dir - it doesn't return a newly allocated string. We have to live with the fact that some strings leak if you call reload.
Comment 7 Matthias Clasen 2012-05-23 19:21:31 UTC
Review of attachment 214775 [details] [review]:

::: glib/tests/utils.c
@@ +441,3 @@
+  dir2 = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
+
+  g_assert_cmpstr (dir, ==, dir2);

I agree that it would be more useful to check that dir != NULL and dir2 != NULL.
Since that is what is currently broken.

@@ +442,3 @@
+
+  g_assert_cmpstr (dir, ==, dir2);
+  g_free (dir);

Same comment as before - can't free these strings.
Comment 8 Marc-Antoine Perennou 2012-05-23 20:23:11 UTC
Actually, it was possible to free these strings as there was a g_strdup before. It was to avoid using a pointer which points to an area of memory we do not manage anymore in case the value had changed and it was free'd, but it's pointless since we directly compare the pointers and not the strings (actually, I do not even get why the tests passed with this here...).
Comment 9 Marc-Antoine Perennou 2012-05-23 20:27:46 UTC
Oh, actually, after getting back in it, we're comparing the strings, so I think either the first patch _is_ needed in order not to dereference a pointer we shouldn't or we should just used g_assert instead of g_assert_cmpstr since when the strings are equals, the same pointer is used.

What do you think of this last solution ?
Comment 10 Marc-Antoine Perennou 2012-05-23 20:37:41 UTC
Created attachment 214815 [details] [review]
Compare pointers instead of strings
Comment 11 Marc-Antoine Perennou 2012-05-23 20:38:18 UTC
Created attachment 214816 [details] [review]
Add test_desktop_special_dit
Comment 12 Marc-Antoine Perennou 2012-05-23 20:40:30 UTC
Created attachment 214817 [details] [review]
Add test_desktop_special_dir

fix typo
Comment 13 Matthias Clasen 2012-06-23 21:51:14 UTC
Thanks, I've now added a testcase like this.